DEV Community

loading...

Bash script to create/delete Apache Virtual Host automatically

alfiosalanitri
I'm a web developer based in Catania (Sicily) that love coding and learning new program languages.
Updated on ・1 min read

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/bin
sudo chmod +x /usr/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)