DEV Community


Posted on • Updated on

Bash script to create/delete Apache Virtual Host automatically

How to create the virtual host

A simple bash script for Linux (debian-based distro) to create or delete a virtual host from command line interface.
Supports: SSL certificate self-signed (mkcert), PHP-fpm (optional), Mysql database (optional).

Note: This script is only for local development. For production server, Apache requires some security improvements.


  • A debian-based distro like Ubuntu
  • Stack Lamp: Apache, PHP, Mysql (optional), PHP-fpm (optional)
  • mkcert


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


cd /path/to/directory/websites/
lamp_virtual_host www.example.local/
Enter fullscreen mode Exit fullscreen mode

and follow instructions.

Discussion (0)