I ran into a snag today while trying to get the websites on my local machine running with Leopard. The first thing was that the config file in the new version of Apache is in a different location (/etc/apache2/httpd.conf instead of /etc/httpd/httpd.conf). Once I changed the settings I kept getting 403 Forbidden messages every time I loaded a page (the default in the new httpd.conf is ‘Deny from all’ for all directories). I finally figured things out and here’s what I did:
- Open the httpd.conf file for editing (sudo vi /etc/apache2/httpd.conf).
- Uncomment the line
LoadModule php5_module libexec/apache2/libphp5.so
by removing the ‘#’ from the front of the line. This will enable PHP 5. The php5.conf file is loaded automatically from /private/etc/apache2/other/.
- Create a file called _sites.conf in your Sites folder. I like to keep my site configuration in the Sites folder to make it more easily accessible as I’m doing development.
- Add the following line to the very bottom of the httpd.conf file:
Include /Users/yourusername/Sites/_sites.conf
That will make Apache load all the configuration settings from your _sites.conf file.
- Add the following information to your _sites.conf file.
# Enable named virtual hosts
NameVirtualHost *:80
# Override the default httpd.conf directives. Make sure to
# use 'Allow from all' to prevent 403 Forbidden message.
<Directory />
Options ExecCGI FollowSymLinks
AllowOverride all
Allow from all
</Directory>
# A basic virtual host config
<VirtualHost *:80>
# Add yoursite to your /etc/hosts file so you can
# type it directly in your browser
ServerName yoursite
DocumentRoot /Users/yourusername/Sites/yoursite
</VirtualHost>
Now you just need to start/restart Apache and the sites should load. PHP should be working and no more 403 Forbidden message.