A newbie’s guide to setting up Apache, php and Mysql on your MAC

I’ve found myself setting up a local Apache/php/MySQL server on various Macs several times for various reasons, and each time I do I always end up looking (digging) for the same resources on the internet. So, to make life a bit easier I figured I’d set this post up as a basic reference guide.

I don’t go into to much detail here simply because the resources I have listed do that and do a much better job than I will ever likely be able to. My goal is to point (myself) you in the right direction when you are going through this process yourself. Hopefully this helps…

The goal here is to get Apache up and running with php enabled and a MySQL database server up and running so that we can do some local development without the reliance of a web connection.

My tool set includes pretty much everything that comes standard on any mac plus one software item that I find indispensable and key to any serious web developer: BBEdit. Just get it…

Let’s get started:

1. Enable Apache: Make sure Apache is enabled and running on your machine; Open your favorite browser and type: http://localhost – if you see the standard Apache test page then you’re good to go. If not, then chances are you have web sharing turned off. If that is the case all you need to do is go into yout system references and enable it. Simply select the apple menu, then select System Preferences:Sharing and enable Web Sharing.

2. Enable php: The next thing you want to do is enable php. Php is included with your OS distribution, but it is, by default turned off. You’ll find a great tutorial how to do this at Foundation PHP. In essence all you are doing is un-commenting a line (LoadModule php5_module libexec/apache2/libphp5.so) in your httpd.conf. Since httpd.conf is owned by root you will not be able to “browse” to it via the default OS X GUI. Instead you’ll have to either open it via terminal or, if you have BBEdit, you can select the “Open Hidden” command from the file menu.

Either way httpd.conf resides in /private/etc/apache2.

I’d walk you through the process but there is not reason to repeat what David Powers has so eloquently posted in Foundation PHP.

Once you do enable php you’ll have to restart the Apache server. The easiest way to do this is to simply go back to the system preferences and disable web sharing and then enabling it again.

Once you do that create a simple filed called info.php with the containing the following code: <?php phpinfo(); ?> and save it in your web site’s root folder – /Library/WebServer/Documents, then browse to it:  http://localhost/info.php – If you see the php configuration screen you’re good to go.

3. Install/Enable MySQL: With Apache and php enabled now it’s time to set up MySQL. The first thing you need to do is get MySQL. I’m under the assumption that you are NOT running OS X server. If you are, MySQL already comes with your distribution, if that is the case then move on over here. Otherwise, carry on and get the latest MySQL distribution from MySQL’s downoad page.

I personally downloaded the Mac OS X (package format) distribution of MySQL. I did so because all you have to is mount a disk image and then double click an installation package file – it doesn’t get any easier than that. The disk image also includes a pretty comprehensive “ReadMe.txt” file with all of the instructions you’ll need to set up your initial MySQL server. Your distribution of MySQL will be installed in the following path: “/usr/local/mysql“.

Once things are set up it is very important to follow the instructions in the MySQL post installation Setup ad instructions note to secure your installation. Even though this will be a local set-up it is a good exercise to accomplish these steps.

With all of that done you should now be able to set up and install your MySQL database admin tool. Although you can manage MySQL directly through terminal there is a tool that will make your life tremendously easier – phpMyAdmin. PhpMyAdmin puts all of the power of php and MySQL in an easy to use GUI interface. Chances are that if you are doing any web development at all you have already been exposed to this tool more than once.

Your next step is to simply download and configure phpMyAdmin so that you can create, manage and update databases in your local environment. My next post will cover just this since I myself have not gotten to this step just yet. Stay tuned…

Resources:

BBEdit
Foundation PHP
Apple: MySQL on Mac OS X
MySQL’s downoad page
Installing MySQL on Mac OS X
MySQL post installation Setup ad instructions
phpMyAdmin

Leave a Reply