I am posting this because I recently had a lot of trouble setting up a Virtual Host with a MAMP stack, due to Apple's throttling of the useable PHP version on Mac OS 10.8's default Apache2 installation.
This is a very quick guide on what to do and I owe the solution to this question on Stack Overflow:
You can think of this as a compilation of what worked for me, as the accepted answers had no effect, but rather those with a significantly lower score.
Similarly, every guide I have seen fails to mention some points which users answered with on the sourced question.
Step 1: Install and configure Apache.
Make sure you specify what port you want to listen on, for me I specified 8080
. This will be the case for this series of instructions.
Listen 8080
- Default is 80
Step 2: Edit your /etc/hosts
file to spoof your loopback address, 127.0.0.1
127.0.0.1 localhost
127.0.0.1 some.example # domain-name.domain-TLD
127.0.0.1 www.some.example # The same as the above line, but with www. prefixed
You should really add a handle for subdomains on your web server, Apache or Nginx (or whatever else you use. Something that routes www to non-www.
Step 3: Enable the Virtual Hosts import on Apache.
- Open your
httpd.conf
file located within Apache2's subdirectories. Usually within /conf
- Uncomment the line that resembles this:
Include conf/extra/httpd-vhosts.conf
- Also uncomment this module import:
LoadModule log_config_module modules/mod_log_config.so
Step 4: Configure your Virtual Hosts file
- Find your Virtual Hosts config,
httpd-vhosts.conf
, you can comment out the two example Virtual Hosts in the file. Usually within /conf/extra
- Copy your own Virtual Host into the file from this template:
<VirtualHost *:80> # Change the 80 to the number Apache2 "Listen"s on. In my case, 8080
ServerName SERVER-ADDRESS # E.g. mywebsite.local
ServerAlias WWW.SERVER-ADDRESS # E.g. www.mywebsite.local
DocumentRoot " SERVER-FILE-ROOT " # E.g. "Users/user-name/Sites"
<Directory /> # This should be a full path, though
Require all granted # Required for permission errors
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride none
</Directory>
</VirtualHost>
You're Done!
Once your Virtual Host has been edited to your liking you are done, just restart Apache and enjoy.
This guide already includes the fixes implemented, but in-case you still get permission errors:
- You MUST make sure that your
DocumentRoot
is not inside any documents your user explicitly owns. If it needs to be, give "Read Only"
access to "Everyone" on Mac for that particular folder, E.g. "Documents" or "Movies" etc....
Although the above answer is much explanatory, the following 2 things are most important when you are migrating virtual hosts to apache 2.4
Go to wamp/bin/apache/apache2.4.x/conf/httpd.conf
find #Include conf/extra/httpd-vhosts.conf
and uncomment to Include conf/extra/httpd-vhosts.conf
Add the virtual hosts in wamp/bin/apache/apache2.4.x/conf/extra/httpd-vhosts.conf
as
<VirtualHost *:80>
ServerAdmin admin@localhost.com
DocumentRoot "H:/Wamp/www/mysite"
ServerName mysite
ServerAlias mysite
<Directory />
Require all granted
</Directory>
</VirtualHost>
Note: <Directory **/**>
the / is important