Command line tool to create virtual host config files.
Switch branches/tags
Nothing to show
Clone or download
Latest commit d8886b0 Apr 26, 2014
Failed to load latest commit information. add badge Apr 26, 2014 Initial Commit Apr 22, 2014

Stories in Ready


Command line tool to create virtual host config files.


This is still in very early stages and extremely rough around the edges. Use at own risk.


Download the file with curl:

curl -O

Move the file to your bin directory:

sudo mv /usr/bin/mkvhost

Ensure that the file is executable:

sudo chmod +x /usr/bin/mkvhost

You will also have to set your Apache config so that it loads all the generated virtual host files. This can be achieved by adding the following line to httpd.conf or your /etc/apache2/extra/httpd-vhosts.conf file (on mac):

Include /private/etc/apache2/virtualhosts/*.conf

This directory can be changed as explained below.


mkvhost <options>


--help, -h

Shows the help screen.

--directory, -d (Default: "/Library/WebServer/Documents")

Sets a custom parent directory for the document root.

mkvhost -d /var/www

You can also change VHOST_DOCUMENT_ROOT in the script file to set a default.

--parent-directory (Default: "/private/etc/apache2/virtualhosts")

Sets the directory that will hold the virtual host config file.

mkvhost --parent-directory /etc/apache2/virtualhosts

The script will check if this directory is available and prompt to create it if it does not exist.

You can also change the default by editing VHOST_PARENT_DIRECTORY in the script file.

--port, -p (Default: "80")

Sets the port that the virtual host will listen on.

mkvhost -p 8080

Again, you can change the default by editing VHOST_PORT in the script file.

--web-dir, -w (Default: "")

Sets the public directory.

mkvhost -w public

What a surprise... You can change the default of this as well. Just edit VHOST_PUBLIC_DIR in the script file.

--directory-index, -i (Default: "index.php index.html")

Changes the directory index for the virtual host.

mkvhost -i

To change the default edit the VHOST_DIRECTORY_INDEX in the script file.

--document-root, -r (Default: The domain name entered)

This one is a bit confusing, but I do require it in some situations so I added it. If the folder containing the project files does not match the domain name (e.g. you can change it with this option.

mkvhost -r example

--skip-apache, -s

Add this option to skip the automatic apache restart that occurs after the script completes.

mkvhost -s

Vhost Example

<VirtualHost *:80>
    DocumentRoot "/var/www/"

    <Directory "/var/www/">
        Options All
        AllowOverride All
        Order allow,deny
        Allow from all
        DirectoryIndex index.php index.html

Symfony Example

This part can be ignored, but to help understand all the options, below is a command I use when setting up a local environment for Symfony 2:

mkvhost -d /var/www -w web -i app_dev.php -r project

In this example my project files are located in /var/www/project. The public directory for Symfony 2 is web and as it is my development environment I change the directory index to app_dev.php.

The .htaccess file will still kick in so you might still get the default app.php file. To fix this change the AllowOverride option in the vhost file to AllowOverride none.