The other night I was fiddling about with my macbook, trying to setup a “MySQL-Apache-PHP” server on my system. Digging a bit about the system and googling a bit, it seems that the system comes with a built in apache server and php installation.
I thought to myself, why not use the built in server instead of installing a MAMP package?
Anyways, seconds went by and I found the option in the system preferences, turned on “web sharing” and excitedly headed on to localhost. It worked perfectly, now I just needed to set it up as it was on my linux desktop.
The apache’s httpd.conf file is located in the folder: /private/etc/apache2/httpd.conf
(I used textmate to edit the file.)
What I wanted to do was, since I’m the only user on this laptop, I wanted my Sites folder to have a www “folder”, which was a symlink to a folder in my Documents folder. The symlink would then point to the webapp I was currently coding.
This worked on my linux desktop, so it should also work here.
The first thing I did was to fix the DocumentRoot so it now points directly to my /Users/username/Sites/www folder (or actually the symlink, which we’ll create now).
The I added PHP support by removing the comments from line 116, containing:
LoadModule php5_module libexec/apache2/libphp5.so
Then I went into my Sites folder and created a symlink to a folder in the Documents folder called “current_project” (yes yes, secret stuff here). This is done using the following command:
ln -s ~/Documents/current_project ~/Sites/www
After that, just reboot you apache server (you can use the Web Sharing option in the System Preferences. Just uncheck the web sharing checkbox and recheck it again).
An here my problems began. I got a lot of warnings in my apache error log (/private/var/log/apache2/error_log) saying:
Symbolic link not allowed or link target not accessible: /Users/username/Sites/www
After googling for a while with no answers, I thought : “why not disable the userdir module? I’m not going to use the localhost/~username anyways”
This turned out to do the trick.
The solution was simply to disable the userdir module in apache.
Comment out line 112 (LoadModule userdir_module libexec/apache2/mod_userdir.so) and line 465 (Include /private/etc/apache2/extra/httpd-userdir.conf)
Restart the apache server (web sharing thingy in the System preferences interface) and you server can now access the symlink.
I hope this will help you on your way, when coding using a Mac.
Small update: (2010-06-02 at 13:15)
Remember to right click the Documents folder and choose “Get Info”. Unfold “Sharing & Permissions” and set “Everyone” to “Read only”, else you will get a permission denied