DEV Community

alfiosalanitri
alfiosalanitri

Posted on • Edited on

Bash script to create/delete Apache Virtual Host automatically

[update 06/01/2022]

The new script is compatible with Debian 11 or Ubuntu 20.
Also you can choose custom file directory or custom server aliases or install automatically Wordpress or Laravel application.
See demo here


With this bash script you can add/delete an apache virtual host to/from your lamp stack. You can also to add a database and choose one of yours fast-cgi php module if installed.

If you choose development environment option, the script will add the ssl certificate with mkcert package if installed on your machine. If you choose production environment, the script will add the ssl certificate with certbot and let's encrypt. Note that this last step requires the dns for domain and aliases setted to your server ip address.

Prerequisites

  • A debian linux distribution like Ubuntu or Debian
  • Stack Lamp: Apache, Mysql (optional), Php
  • php-fpm module (optional)
  • mkcert or certbot for SSL certificate (optional)

Installation

sudo mv lamp_virtual_host /usr/local/bin
sudo chmod +x /usr/local/bin/lamp_virtual_host
Enter fullscreen mode Exit fullscreen mode

Usage

cd /path/to/directory/websites/
lamp_virtual_host www.example.local/ lamp_virtual_host /path/to/example.com/ -a www.example.com,shop.example.com
Enter fullscreen mode Exit fullscreen mode

and follow instructions.

Top comments (0)