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!
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!
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.
Alex's Ramblings
This is my blog where I discuss web design, development, my projects, the mac and anything else that springs to mind!
Fetching RSS feed... please stand by
