A script that helps to manage virtual hosts on Mac OS X (it may also run on other unix based systems with some or no changes).
The Idea is to keep the changes on the existing config as little as possible.
- Install:
brew tap alxndrhi/miscbrew && brew install vhm
- Tell apache where to find the configuration:
sudo echo "Include /usr/local/etc/vhm/httpd-vhosts.conf" >> /etc/apache2/extra/httpd-vhosts.conf
- Check the vhm Configuration in:
/usr/local/etc/vhm/vhm.cfg
- create sites-available folder:
mkdir -p /usr/local/etc/vhm/sites-available
- create sites-enabled folder:
mkdir -p /usr/local/etc/vhm/sites-enabled
- create templates folder:
mkdir -p /usr/local/etc/vhm/templates
- Download Release from releases page untar / unzip it
- symlink vhm:
ln -s WHEREVER-YOU-PUT-THE-FILES/vhm /usr/local/bin/vhm
- copy config:
cp WHEREVER-YOU-PUT-THE-FILES/vhm.cfg /usr/local/etc/vhm/vhm.cfg
(don't forget to edit the config) - copy template
cp WHEREVER-YOU-PUT-THE-FILES/VirtualHost.conf /usr/local/etc/vhm/templates/
- copy apache config file
cp WHEREVER-YOU-PUT-THE-FILES/httpd-vhosts.conf /usr/local/etc/vhm/
- Tell apache where to find the configuration:
sudo echo "Include /usr/local/etc/vhm/httpd-vhosts.conf >> /etc/apache2/extra/httpd-vhosts.conf
To create a host, you have to go into the root folder of the new host and run vhm -d domain-name cr
.
Ok, lets say we want to create the development domain testing.dev with the "DocumentRoot" in ~/Sites/testing.dev/, and as we are already here, we also want to enable it and restart apache.
mkdir -p ~/Sites/testing.dev
cd ~/Sites/testing.dev
vhm -d testing.dev cr en --apache-restart
You can use your custom template file or an alternative template file by using the --template parameter.
mkdir -p ~/Sites/testing.dev
cd ~/Sites/testing.dev
vhm -d testing.dev cr en --template MyTemplateFileName.conf --apache-restart
To delete, disable or enable an existing VirtualHost you dont have to cd
into the "DocumentRoot". Just use the --domain parameter:
vhm -d testing.dev --enable
vhm -d testing.dev --disable
vhm -d testing.dev --delete
See a list of Domains including Status:
vhm -l
For a full list of parameters see vhm --help
You can create your own template files. Just put them in /usr/local/etc/vhm/templates
.
Info
- After creating a new VirtualHost you have to enable it.
- Remember to restart apache after every change to the configuration.
- If apache don't start just run
apachectl
without any parameter to see the error message. - Delete will remove the VirtualHost config file and the symlink from
/etc/apache2/sites-enabled
and/etc/apache2/sites-available
. This will not remove any of your project files.