DEV Community

alfiosalanitri
alfiosalanitri

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.

Prerequisites

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

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/
Enter fullscreen mode Exit fullscreen mode

and follow instructions.

Discussion (0)