Bash Script to allow create or delete apache/nginx virtual hosts on Ubuntu on a easy way.
- Download the script
- Apply permission to execute:
$ chmod +x /path/to/virtualhost.sh
- Optional: To use the script globally, copy it to the /usr/local/bin directory. It is recommended to remove the .sh extension.
$ sudo cp /path/to/virtualhost.sh /usr/local/bin/virtualhost$ cd /usr/local/bin
$ wget -O virtualhost https://raw.githubusercontent.com/RoverWire/virtualhost/master/virtualhost.sh
$ chmod +x virtualhost
$ wget -O virtualhost-nginx https://raw.githubusercontent.com/RoverWire/virtualhost/master/virtualhost-nginx.sh
$ chmod +x virtualhost-nginxBasic command line syntax:
$ sudo sh /path/to/virtualhost.sh [create | delete] [domain] [optional root_dir] [optional is_subdomain] [optional canonical]With script installed on /usr/local/bin
$ sudo virtualhost [create | delete] [domain] [optional root_dir] [optional is_subdomain] [optional canonical]Parameters:
domainis the domain name for the virtualhost (myhomepage.com, test.local, etc)root_diris the path where your want to serv as domain root for your host files. If not specified it will create a new one under /var/www folder.is_subdomainis a boolean true/false to flag when a host is subdomain.canonicalcan have two possible values: www or empty, this is to add another entry in the hosts files preppending the www.
to create a new virtual host:
$ sudo virtualhost create mysite.devto create a new virtual host with custom directory name:
$ sudo virtualhost create anothersite.dev my_dirto delete a virtual host
$ sudo virtualhost delete mysite.devto delete a virtual host with custom directory name:
$ sudo virtualhost delete anothersite.dev my_dir
WARNING: Localizations are outdated, any help to contribute to fix this is welcome.
For Apache:
$ sudo cp /path/to/locale/<language>/virtualhost.mo /usr/share/locale/<language>/LC_MESSAGES/For NGINX:
$ sudo cp /path/to/locale/<language>/virtualhost-nginx.mo /usr/share/locale/<language>/LC_MESSAGES/Contributions are welcome. You can also report any issues.
Thank you to everyone who has contributed over the years.