Among developers and system administrators, there are still those who prefer to use native LAMP stack, as their primary development environment and platform, instead of a variety of popular services or solutions available out there.
Starting each new project often requires many repetitive tasks to be performed and, when it comes to LAMP stack, adding a Virtual Host to Apache Http Server is one of them.
Using this simple shell script, provided below, can reduce the time needed to perform adding or removing Virtual Host tasks to seconds.
- This guide may lead to data loss, if not followed correctly.
- Do not use this script in a production environment without enforcing the desired security settings for Virtual Hosts.
When you use the script to add a new Virtual Host on your system, it will:
- Create a folder (inside user’s profile directory) that will serve as a root directory for the VHost
- Add a desired VHost’s FQDN to the hosts file
- Create a necessary apache configuration file for the VHost
- Enable the VHost
The script can also be used to remove previously added Virtual Hosts.
To prevent possible conflicts in regards with Virtual Host’s root directory being in a user’s profile folder, consider enabling mpm-itk module on Apache HTTP server.
[Download] Add/remove Virtual Host script for Apache HTTP Server
Execute the script from Terminal using shell:
The script has been tested in Ubuntu 18.10 cosmic.