Running PHP on your OS X machine is the simplest option, as almost everything you need is already present: Mac OS X comes with a full Apache server installation that includes PHP. The only downside is that this native installation does not include MySQL. Because of that limitation, this article will provide two options: the first using the native Apache installation, and the second using a downloaded server package that includes MySQL. Note that you will need an Administrator account on your machine to complete both options. Generally speaking I suggest using the second option (MAMP) , as it is easier.

Mac Option 1: Use the native OS X Apache server

Web SharingAs I mentioned, every installation of Mac OS X comes with Apache and PHP: it’s just not turned on. Under System Preferences, go into Sharing and turn on Web Sharing. (Note that you will likely need to unlock the Sharing preference panel in the bottom left corner.)

Sharing Preference PanelThat’s it! You can use the panel’s suggestions as to what the URL of your new, locally hosted server is, or the following:


The question is, where is the page served from?

Go to your home location, and find the Sites folder. Inside this folder you’ll see an index.html page and an images folder: the index.html page is what is being served when you type in http://localhost/

Modified Sites folderObviously we need to improve on this. Create a new folder with the name new-site in the same location as the default index.html page. You will create a new folder in the same location for every site you wish to test. The name of the folder(s) don’t particularly matter, but they should follow web naming conventions.

Now create a new index.html page inside the new-site folder, with some content in the of the page. The URL for the new page is now:


You’re all done! Now you can create a complete site inside the new-site folder, including PHP code, and test it locally. Remember, no-one from the outside world should be able to see this content; it’s just for you.

Mac Option 2: Install MAMP

MAMP InstallationIf you want to use MySQL with Apache, you could try to download components and modify the default Apache installation manually, but I find it much easier to download and install an entire separate server suite. While there are many options out there, I recommend MAMP.

Extract MAMP, double-click on the .dmg image, and drag the MAMP folder icon to the Applications folder. Once it is complete, look inside Applications for the MAMP folder that will have been created for you.

Start the MAMP application. This will start up your default browser to show you that the new server is working, at the following URL:


Default MAMP pageI strongly recommend that you change the MAMP application preferences. Set the Apache Document root to the same location I provided in option 1 above. (When you set the Document Root to a new location, the Apache server will stop and restart, which will take several seconds). Assuming you have the same new-site folder in the Sites folder as in Option 1, the URL to visit the locally hosted site served by MAMP will be: