The Net, the Web and other Geeky stuff
Author: MikeW Date: 2016-08-28 11:49 Tweet
This is a tip on how to configure Apache 2 to support multiple sites on one server for Mac OS X El Capitan, Mavericks, and Yosemite. This is a much improved process thanks to this write up on Apache and vhosts. A vhosts approach is used to configure the server. The makes the setup simpler and quicker.
Note: This tip assumes you have some knowledge of Mac OSX system administration. You need to use
sudo to edit and create files and directories. Make sure you can use either
vi before attempting to edit any configuration files.
/etc/hostsfor Multiple Sites
To be able to use multiple sites on one server, you must first update the
/etc/hosts file. Add an entry for each of your sites to the localhost address. For example:
sudo nano /etc/hosts
127.0.0.1 localhost site1 site2
Before the Apache configuration file is edited, a little setup. is required.
Here are some sample files that demonstrate how you could setup each test site on the Apache server.
Imporant Note: The Apache server needs to be able to read the directory your files are in. If you are like me and your files are stored in a subdirectory under your home directory, the default permissions (700) may cause access issues. Make sure any web directories under your home directory have their permissions to 755. That should fix any access issues. If you need to write to a web directory, you may need to create a new web directory with
root and set the directory group to
This is a default vhost. Any unamed url, (e.g., localhost) will serve up the page using this setting.
<VirtualHost *:80> DocumentRoot "/Users/myhome/www/site1" <Directory "/Users/myhome/www/site1"> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost>
Here is the configuration for site1 in the
<VirtualHost *:80> ServerAdmin firstname.lastname@example.org DocumentRoot "/Users/myhome/www/site1" ServerName site1 ServerAlias site1.local ErrorLog "/private/var/log/apache2/site1-error_log" CustomLog "/private/var/log/apache2/site1-access_log" common <Directory "/Users/myhome/www/site1"> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost>
Here is the configuration for site2 in the
<VirtualHost *:80> ServerAdmin email@example.com DocumentRoot "/Users/myhome/www/site2" ServerName site2 ServerAlias site2.local ErrorLog "/private/var/log/apache2/site2-error_log" CustomLog "/private/var/log/apache2/site2-access_log" common <Directory "/Users/myhome/www/site2"> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost>
httpd.conf file. Uncomment these two lines to enable
LoadModule rewrite_module libexec/apache2/mod_rewrite.so LoadModule php5_module libexec/apache2/libphp5.so
Then scroll down to this comment:
# Virtual hosts
And add this line.
So now, any
.conf file placed into the
vhosts directory will automatically load when Apache starts.
To restart apache:
That is it. Now to add a new web site to Apache, just put a new site file in the
vhosts directory, update your
/etc/hosts file, and restart Apache. Voila!