Setting up PHP & MySQL on OS X 10.6 Snow Leopard
With OS X 10.6, Apple ships PHP 5.3 with PEAR, GD and PDO_MYSQL out of the box. Also, everything is now 64bit. This means that the entire effort required to get a working PHP dev environment for my work is now much easier.
/usr/local
Ensure that the following directories exist:
sudo mkdir /usr/local/include sudo mkdir /usr/local/bin sudo mkdir /usr/local/lib sudo mkdir -p /usr/local/man/man1
MySQL
- Download the 64bit version of MySQL 5.0.x for OS X 10.5 from mysql.com and install the pkg, the startup item and the pref pane.
- Add /usr/local/mysql/bin to the path: vim ~/.bash_profile and add:
export PATH=~/bin:/usr/local/bin:/usr/local/mysql/bin:$PATH export EDITOR=vim
at top of file. (Note that we set EDITOR whilst we are here so that svn is happy!)
- Set up MySQL root password:
mysqladmin -u root password {new-password} mysqladmin -u root -p{new-password} -h localhost password {new-password} mysqladmin -u root -p reloadQuit Terminal to flush the history to file. Restart Terminal and remove the history file: rm .bash_history so that {new-password} isn't in plain text on the disk.
Apache
- cd /etc/apache2
- sudo vim httpd.conf
- Find #LoadModule php5_module libexec/apache2/libphp5.so and remove the leading #
- Find AllowOverride None within the <Directory "/Library/WebServer/Documents">section and change toAllowOverride All so that .htaccess files will work.
- Restart Apache: sudo apachectl restart
- Open Finder and navigate to /Library/WebServer/Documents/
- Create a new folder called "orig" and place all files currently in the Documents folder into it.
- Create a new file called info.php with <?php phpinfo(); inside it.
- Use Safari to navigate to http://localhost/info.php and check that the PHP version is displayed (5.3.0 at the time of writing).
php.ini
- cd /etc
- sudo cp php.ini.default php.ini
- sudo chmod ug+w php.ini
- sudo chgrp admin php.ini
- vim php.ini (assuming your user is a member of the admin group) and change settings appropriately. Change:
error_reporting = E_ALL | E_STRICT display_errors = On html_errors = On extension_dir = "/usr/lib/php/extensions/no-debug-non-zts-20090626"
(I like to see my xdebug errors in bright orange!)
Also, change all instances of /var/mysql/mysql.sock to /tmp/mysql.sock
Xdebug
Can't have a PHP development environment without xdebug!
- sudo pecl install xdebug
- Edit /etc/php.ini and add
zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"
after the other extension lines.
- Restart apache: sudo apachectl restart and check in the phpinfo that xdebug is now loaded.
It all works on this machine, anyway :)

October 5th, 2009 at 22:53 #
Thanks for the tips.
I am newbie in Mac Platform and your post was very useful.
I just uninstalled the Zend Server to use these packages shipped in Snow Leopard.
Cheers,
October 6th, 2009 at 02:07 #
If any of your readers are interested in compiling Apache/MySQL/PHP on Snow Leopard from the ground up, check this out:
http://docs.google.com/View?id=ddbc374w_393r64mhgf
October 6th, 2009 at 07:52 #
Sweet !
And how do I uninstall the zend Server installation from your other blog post?
October 6th, 2009 at 08:52 #
Hvdklauw,
No idea :) I did a clean install.
I would expect Zend provide instructions. Zend Server is definitely the best solution for 10.5 Leopard though.
Rob...
October 6th, 2009 at 16:30 #
Thanks for the tips! I especially appreciate the easy and simple xdebug instructions
you can flush your shell history with:
history -c
also see:
http://www.macosxhints.com/article.php?story=20090831101932728
October 7th, 2009 at 08:49 #
Hey Rob,
A couple of juicy additions: 64 bit MySQL preference pane:
http://www.swoon.net/site/software.html
Nice tool I picked up just the other day, WebMon:
"Configures OS X's built-in web server to support WebDAV, PHP, and SSL." and "WebMon for Snow Leopard can now set up multiple virtual domains in addition to the main domain."
http://www.cutedgesystems.com/software/WebMonSnow/
It allows custom Apache directives so is quite flexible. I also use their DNS Enabler.
October 11th, 2009 at 15:38 #
Sweet Jesus, yes!
I'd been hoping for two things with Snow Leopard: 1. MySQL PDO and 2. some nice person to write an all-inclusive tutorial on setting up. Winner!
Btw, I enjoyed your talk at PHPNW09; Really natural, informed and insightful. Nice to see someone not reading from their slides, too.
Cheers,
Ross
October 11th, 2009 at 18:01 #
Nice.
Is there an easy way to install APC and Imagick (that's Imagick, not ImageMagick) extensions?
October 12th, 2009 at 14:34 #
Goran,
Have you tried pecl install apc and pecl install imagick?
Regards,
Rob...
October 12th, 2009 at 14:55 #
rossmcf,
Thank you. Have you commented on joind.in at http://joind.in/616?
Rob...
October 26th, 2009 at 10:18 #
Hi, I'm a fresh newbie on Mac... your post was very helpful.
One off-topic question: how do you easily insert the tilda "~" character on regular US keyboard (e.g. for you path environment setup)? It's driving me crazy... Thank you in advance.
October 26th, 2009 at 10:23 #
UJ,
No idea :) On a UK keyboard, it's "shift"+"key to the left of the Z key"
Regards,
Rob...
October 27th, 2009 at 10:00 #
Thanks Rob, it worked! I must have missed it. I was looking at the "Show keyboard viewer" at least million times...
November 4th, 2009 at 00:11 #
I think there might be a few things that need cleaning up in this tutorial to make it a little easier to understand.
On step 2 it says 'Add /usr/local/mysql/bin to the path: vim ~/.bash_profile and add: ' I couldn't figure out what that was supposed to mean but I just ran 'vim ~/.bash_profile' and added those two lines to the top. There was another line to include PEAR, so I got rid of that line and added the path to the first line (export PATH).
Next, I tried to start step three, but got an error saying "unknown command mysqladmin". So I skipped ahead, quit terminal, opened terminal and ran 'rm .bash_history'. I quit terminal. Opened it again, tried 'mysqladmin -u root password {new-password in clear text}' and it worked fine. So next I try 'mysqladmin -u root -p{new-password in clear text, but I put a space after the -p} -h localhost password {new-password in clear text}' and get 'Unknown command (my password)'. So I left out the first password leaving 'mysqladmin -u root -p -h localhost password {new-password in clear text}' it prompts me for my password, then finishes without complaint.
In the Apache section, I try to go to localhost and I get a 403 forbidden and message 'You don't have permission to access / on this server.'
I don't think Apache is working right. I don't know if there's anything left over from having MAMP installed that is messing things up or not.
So that's as far as I got. Any suggestions?