A quick guide to installing a local PHP MySQL development server on Mac OS X
Friday, December 21st, 2007Mac users are sensitive little souls. Artistic types. We love our beautifully designed computers and software, but poking around in the guts of our operating system doesn’t come quite as naturally to us as to our PC using friends.
Sometimes though that can be a very worthwhile exercise, such as installing a dev server. Perhaps you have a laptop, and need to be able to work or present when you don’t have internet access (eg: while travelling). Here’s how…
Good news, everyone!
The Apache web server and PHP are already installed as part of Mac OS X and only need to be turned on. The MySQL database server will have to be downloaded and installed, but we’ll cross that bridge when we come to it…
This is an easier job than it used to be and doesn’t have to involve typing code into the Terminal. Marc Liyanage does a fantastic job of creating PHP installer packages if you want to keep your installation bang up to date, but for most purposes the instructions below should be sufficient.
Note: I have used Mac OS X 10.5 Leopard and MySQL 5.0.45 (the latest at the time of writing) on a MacBook Pro. I used TextMate to edit text.
Part 1 – Apache and PHP
-
Start by editing the Apache config file to enable PHP. This file is hidden by default, but you can access it from the Finder’s “Go” menu. Enter /etc/apache2 and confirm to make the folder appear.
-
Open httpd.conf in a text editor. Find the line that says:
#LoadModule php5_module libexec/apache2/libphp5.so
Uncomment it by removing the hash. Save the file (you will be asked to enter your admin password).
-
Open System Preferences and go into “Sharing” (under “Internet & Network”).
Turn on ”Web Sharing”. You now have an active Apache server with PHP. Test this by typing localhost into your browser. You should see the default Apache page.
-
If you feel curious, create a PHP file with the phpinfo() function call in it to see the details of your installation.
Place your own files in /Library/WebServer/Documents
Part 2 – MySQL
First things first: Head on over to MySQL.com and download MySQL Community Server and the GUI Tools.
As their names indicate, the former is the database software itself while the latter is a collection of graphical tools to make the task of administering MySQL easy for those of us that find the Terminal a bit too scary.
-
I use an Intel Mac, so I got the Mac OS X 10.4 (x86) builds. Take care to download the most appropriate build for your computer and OS version.
I recommend that you always use the latest GUI tools for the latest features and stability improvements.
-
Mount the MySQL disk image and run the main package first, then install the startup item, finally the prefpane. I needed to restart before MySQL would turn on.
-
Open System Preferences and go into “MySQL” (under “Other”). Tick the box to automatically start MySQL on startup.
You can install the GUI Tools by dragging them from their disk image to your Applications folder. Nearly there now!
-
It is crucial that you now set a password for the MySQL “root” account. Open MySQL Administrator and log into localhost with root (no password). Under “Accounts” you can assign a password to root, as well as create other database users.
Avoid using the root account in your applications – use it only for administration.
That’s it! You can start creating databases and coding the PHP applications that will run on them.
Recommended Reading
If PHP and MySQL are new to you, I recommend PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide by Larry Ullman. In common with other books in the series, this book gives you a solid grounding in the subject, with plain English examples.
If you are already familiar with HTML and maybe a scripting language or two, you should hit the ground running!
If this guide was useful to you or you would like me to elaborate further, please feel free to comment. I’m thinking about writing a series of how-tos in this manner and your feedback would be appreciated.



