Skip to navigation | Skip to content

Share your knowledge. Make a difference.

Installing a PHP MySQL development server on Mac OS X

1 - I can do better 2 - Jury's out 3 - Pretty darn good 4 - Splendiferous 5 - Awesometastic (by 0 people)   Your rating: 1 - I can do better 2 - Jury's out 3 - Pretty darn good 4 - Splendiferous 5 - Awesometastic

Ranked #6563 in Tech & Geek, #144098 overall

Rated G. (Control what you see)

A quick guide to getting a local server up and running on your mac

Mac users are sensitive 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. You can find this information under "About this Mac" in the Apple menu.

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.

Reader Feedback 

Like this lens? Want to share your feedback, or just give a thumbs up? Be the first to submit a blurb!

Useful websites 

PHP: Hypertext Preprocessor
The homepage for PHP.
MySQL AB
The world's most popular open source database.
phpMyAdmin
Browser-based MySQL database administration tool.

Recommended Reading 

If PHP, MySQL or web development in general are new to you, I recommend these books.

PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide

Amazon Price: $26.39 (as of 01/09/2009) Buy Now

PHP and MySQL Web Development (3rd Edition) (Developer's Library)

Amazon Price: (as of 01/09/2009) Buy Now

Alex's Ramblings 

This is my blog where I discuss web design, development, my projects, the mac and anything else that springs to mind!

Loading Fetching RSS feed... please stand by
X
alex-hardy

About alex-hardy

I'm a web developer from Manchester, UK.

alex-hardy's Pages

See all of alex-hardy's pages

X

Happy holidays!

The red bow is special. Whenever you see a red bow on a Squidoo page, it means the page is raising money for charity.

Buy something from the page, and we'll automatically make a donation to charity, thanks to you.