Alex Hardy


Hello there!

A quick guide to installing a local PHP MySQL development server on Mac OS X

Mac 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

  1. Go to Apache folder

    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.

  2. Edit Apache config file

    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).

  3. System Preferences – Sharing

    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.

  4. Turn on Web Sharing

    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

  1. MySQL Community Server

    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.

  2. MySQL GUI Tools

    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.

  3. 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.

  4. MySQL prefpane

    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!

  5. 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

PHP and MySQL for Dynamic Web Sites

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.

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Facebook
  • StumbleUpon
  • del.icio.us
  • Reddit
  • Ma.gnolia
  • Technorati

2 comments for “A quick guide to installing a local PHP MySQL development server on Mac OS X”

  1. Neil Woodman

    Nicely put together. I don’t understand it however but thats down to me not you.

    Is it possible to allow internet users to connect to a folder on my mac via FTP and only allow them to access this folder and nothing else? I know you can turn on Sharing in system preferences and enable FTP but futher than that I’m not sure.

  2. Alex

    It’s possible, but unless you have a static IP address (so users have a reliable address for your FTP folder) and your computer is always online it’s probably too much hassle for all concerned.

    Have a look at Box.net - they are an online storage service that you can access with a web browser or mount as a volume in the Finder. I use it myself for backup.

Comments are welcome. Keep it friendly and on-topic please.

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>