
I’ve upgraded both my Macs to Snow Leopard, and a few things have changed with the built in Apache webserver.
As a web developer it’s important for me to have a fully functional development environment so the first thing I had to do with the new install is get Apache set up and running as I need it.
This post shows how to set up PHP, mySql, Virtual Hosts & .htaccess
PHP
By default PHP is disabled so let’s turn that on.
In the finder navigate to the /etc folder, this houses all the files we need to configure. This is a hidden system level folder so to access it press “apple shift G” and type /etc.

Find the folder Apache 2 and open httpd.conf
This is the main config file for Apache, I use textMate to edit these files but you can use any text editor.
Go to line #115 and uncomment (remove the starting #) “LoadModule php5_module”
Save the file, you will be asked to enter your password.
After every change you make to the Apache or PHP config files you will need to restart the webserver. This can be done in the Terminal with “sudo apachectl graceful” or go to System Preferences and untick then tick Web Sharing in the Sharing Pane.
Now PHP is running.
Error Messages when using date() function
PHP has been upgraded to V5.3 and the Snow Leopard version doesn’t have a timezone set, this will give you errors when you use the date() function. To fix this go back to the “/etc” folder and open “PHP.ini.default”
Go to Line #997 and enter your timezone, here in the UK it’s Europe/London find your timezone.
Remove the semicolon and the line should read “date.timezone = yourtimezone”
Save this file as PHP.ini in the etc folder, restart the webserver and PHP is now all good to go.
mySQL
mySQL doesn’t come as standard on OS X so we need to install it luckily this is nice and easy because we can get a dmg file. I choose the 64bit version, head over and grab it scroll down to “Mac OS X (TAR packages) downloads” and choose “Mac OS X 10.5 (x86_64)”.
Open the dmg and run the installer. I also installed the prefPane, double click the “MySQL.prefPane” It’s a good idea to use this as you can use System Preferences to start/stop mySQL.
Setting the password
The mySQL install doesn’t set a password so we need to set it.
For this task we need to use the Terminal. Open Terminal located in the “Applications/Utilities” folder and type “/usr/local/mysql/bin/mysqladmin -u root password yourpassword” (where yourpassword is the password you want.) hit enter and the password is set.

Fixing the PHP socket
Before we can use mySQL we need to point PHP to the correct place. Open the PHP.ini file as before and change line #1213 to mysql.default_socket = /tmp/mysql.sock
Save this file and restart the server.
phpMyAdmin
I use phpMyAdmin to manage mySQL. So here’s how to do that.
Head over to the phpMyAdmin Site and download the latest version.
Unzip the downloaded file and place in either your Sites folder or the servers root (Library/WebServer/Documents) I use the root as I class this as a management tool and like to keep my Sites folder for projects.
This needs configuring too. It does come with a documentation file so you could go through that and set it up as you like. I keep mine nice and simple and have it so I don’t need to log in each time.
Open “config.sample.inc.php” and add after “$i++” the lines:
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'yourpassword';
$cfg['Servers'][$i]['auth_type'] = 'config';
Remove the line “$cfg['Servers'][$i]['auth_type'] = ‘cookie’;”
Save this file as config.inc.php.
In a browser go to “http://localhost/phpMyAdmin/” if you moved the folder to the root as I did or if you placed into your Sites folder go to “http://localhost/~yourusername/phpMyAdmin”.
Virtual Hosts
Open the “httpd.conf” and uncomment line #461 which reads “Include /private/etc/apache2/extra/httpd-vhosts.conf”, then save.
Now open “/etc/apache2/extra/httpd-vhost.conf”
I commented out each VirtualHost block and made my own underneath, You really do need this one:
<VirtualHost *:80>
DocumentRoot /Library/WebServer/Documents
ServerName localhost
</VirtualHost>
After this block you can add your own
<VirtualHost *:80>
DocumentRoot /Users/youruser/Sites/yoursitefolder
ServerName yoursitesname
</VirtualHost>
You will need to add a new VirtualHost block for each VirtualHost you wish to set up.
Save this file and we’re almost done. Open “/etc/hosts” and add “127.0.0.1 yoursitename” you will need to add a new line for each Virtual Host you have set up where “yoursitename” matches the name chosen name in the VitrualHost block in the previous step.
Save this file and restart the webserver. Now in a browser type the VirtualHost name and you will see the corresponding site. A link to “/” within this site will take you to the root of that site as if it was on a remote server.
.htaccess
Open the “httpd.conf” file and change line #210 to read “AllowOverride All”.
Open “/etc/Apache2/Users/youruser.conf”
Change AllowOverride to All
Add a new Directory Block
<Directory "/Users/youruser/Sites/*/">
Options Indexes MultiViews FollowSymLinks
</Directory>
Save and restart the server. Everything should now be all set up and you can use .htaccess and mod_rewrite.

[...] Chapman has a good documentation about how Setting up Apache on Snow Leopard. It’s worth a read and has all you may need to sucessfully setup apache on Mac OS X 10.6.x [...]
New to mac. Very new. Just installed XAMPP (coz it’s what I always do with windows). It was a one-click install for php, mysql and apache. So why go this route?
PLEEEAAASSEE. HELP! I used the administrator account and tried using textwrangler and it wouldnt let save the php.ini.default as php.ini it said:
This operation could not be completed, because an error occured.
You do not have sufficient privileges to perform this operation (MacOS Error code: -5000)
Mac OS X 10.6.6
In terminal type:
su vi /etc/apache2/httpd.conf
You’ll be asked to enter your admin pass and can save the file after the required changes have been made.
Hello,
I’m trying to block the access to certain files with a .htaccess file and a .htpasswd file. I changed all the setting in the httpd.conf file (allowoverride set to all), and username.conf file but i get an Internal Server error.
Anyone knows how to fix this ?
Hi, for some reason when i try to enter the mysqladmin, in the bin folder, it cant be found
“-bash: mysqladmin: command not found”
did i miss anything??
I tried to get clean urls so many ineffective ways and finally got it thanks to your last box:
Options Indexes MultiViews FollowSymLinks
Thank you thank you thank you
I followed all given hints, but as soon as i activated virtual host in httpd.conf (line 461), I can’t access http://localhost/ no more, nor phpmyadmin. I get the message 403 forbidden: You don’t have permission to access…
I’m a little desperate
and grateful for help!
Hi Tanner. Try checking your config for errors. Terminal: apachectl configtest. Also make sure that you still have: 127.0.0.1 localhost in your hosts file (it should be the first line after the #comments).
Hi Kev. Quite simply, you are a legend. I’ve just wiped clean and re-installed my entire system, which has been made a whole lot easier by following your step-by-step guide. Nice one
I don’t think localhost and 127.0.0.1 will make any differences. The problem of connection is mainly the location of mysql.sock if mysql shell is working and port number has not been changed.
Once I corrected the mysql.sock path in php.ini, restart apache should make apache+php+mysql working
Hi Kev,
Your info has been really helpful. HOWEVER, I am having issues! I set everything up as you described for my Sites folder. In my sites folder I have /sites-name/ and then inside that a WordPress site. The homepage works great, but all other pages and posts give me a 500 Internal Server Error. I’ve noticed when I turn AllowOverride back to “None” I then get a 404 error instead.
I also have another site in progress in another folder under Sites – haven’t found this problem so far.
Any ideas what is causing this?! Is it WordPress? There is no .htaccess file in my WordPress folders, not sure whether that makes a difference.
Thanks
Thank you very much for putting this together. I’ve been working on getting rid of MAMP and moving everything over to the native OSX. It was confusing because with MAMP I had two PHP’s and two MySQL’s installed. It was tricky to get everything straight. Your article was the most helpful, accurate and clearly-written of anything I’ve seen on the web in the last couple of days.
Hi, thanks for an informative article. I wanted to ask what may seem an obvious question – can I run the native OSX and MAMP on the same machine? I would like to do this as my MAMP servers is set up exclusively for Drupal multisite and I would like to do some plain php (without the drupal) stuff on the native OSX server. I don’t want to mess around with anything until I’m sure this can be done.
Thanks
K
change the permission to the appache2 folder as read and write access.. then u can save it dude
Thanks for the detailed instructions! Was following another tutorial on someone else’s website and I couldn’t get past 403 error. But thank goodness I found your article and it solved my problem immediately!