Home/HostingApacheLinux/Automated Script To Create Virtual Host on Linux

Automated Script To Create Virtual Host on Linux

It is always complicated to create virtual hosts every time you setup a new website especially for developers and webs designers who do it regularly. This script will automate this process of creating virtual hosts with a single command:

sudo virtualhost create mysite.dev

Download From Github

Credits: Thanks to https://github.com/RoverWire for this useful script

virtual host




  1. Download the script
  2. Apply permission to execute:
$ chmod +x /path/to/virtualhost.sh
  1. Optional: if you want to use the script globally, then you need to copy the file to your /usr/local/bin directory, is better if you copy it without the .sh extension:
$ sudo cp /path/to/virtualhost.sh /usr/local/bin/virtualhost

For Global Shortcut

$ 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-nginx


Basic command line syntax:

$ sudo sh /path/to/virtualhost.sh [create | delete] [domain] [optional host_dir]

With script installed on /usr/local/bin

$ sudo virtualhost [create | delete] [domain] [optional host_dir]


to create a new virtual host:

$ sudo virtualhost create mysite.dev

to create a new virtual host with custom directory name:

$ sudo virtualhost create anothersite.dev my_dir

to delete a virtual host

$ sudo virtualhost delete mysite.dev

to delete a virtual host with custom directory name:

$ sudo virtualhost delete anothersite.dev my_dir


For Apache:

$ sudo cp /path/to/locale/<language>/virtualhost.mo /usr/share/locale/<language>/LC_MESSAGES/


$ sudo cp /path/to/locale/<language>/virtualhost-nginx.mo /usr/share/locale/<language>/LC_MESSAGES/


Leave a Reply

Enim tempor eget pharetra facilisis sed maecenas adipiscing. Eu leo molestie vel, ornare non id blandit netus.

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • 2.May.2023 | codedrill | Artificial Intelligence

    OpenAI API

    The OpenAI API can be applied to virtually any task that involves understanding or generating natural

  • 2.May.2023 | codedrill | Artificial Intelligence

    What is Chat GPT

    ChatGPT is an artificial intelligence (AI) chatbot developed by OpenAI and released in November 2022. It is