Apr 16 2008

Developing PHP on a Mac


I am sure that many PHP developers that a new to the World of Mac development are relieved when they realize (or already know) that PHP is already installed on their Mac by default. But the time and setup to get Apache2, PHP and MySQL to interact together, in an easy manage fashion might be a little harder in the beginning. If you are the type of user that is just doing some local web development and then moving it to a live server or maybe a staging server it is worthwhile to just go and download MAMP. MAMP as you probably have guessed stands for Macintosh-Apache-MySQL-PHP. This is an all in one package that allows you to install all of these great products by seriously just draggins MAMP over to your applications folder. It is configured to use it’s own PHP, MySQL and Apache2 installation (even if you already have some of these running on your machine), which is very handy if you don’t want to disturb your already existing configurations. MAMP is configured to have Apache listen on port 8888 and MySQL listen on port 8889, which unless you have changed your existing installs defaults should not cause a conflict. At this point if you have dragged MAMP to your applications you are absolutely ready to go (easy right?).Starting MAMP At this point you can start MAMP. Once it is started it should bring up a browser window (in whatever browser is your default, Safari, Firefox, etc.) This will serve a few purposes, A) that MAMP is running properly and B) allow you to work with MySQL via a built in PHPMyAdmin installation. From here you should be good to go to start developing on your own. I have a few additional modules that I would like to discuss.

XDebug
XDebug is a great module for helping you analyze PHP error messages. While there is no binary that was designated for for Mac, if you Google the subject you will discover some workarounds. Trust me this is totally worth it. If you download the PHP Remote Debug tools for Komodo it will work . I have only posted the x86 version for Mac, but their are ones if you are still running a PowerPC machine. At this point we need to copy the file over when you extract the zip file you will be presented with a series of folders, the one we are concerned with is the 5.2folder. Inside of it will be a single file which is the extension we need.

Copy it over to:
/Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20050922/.

Then we need to open up the php.ini file which is located in:
/Applications/MAMP/conf/php5/

Add the following lines to the end of the file:

Once you have completed this all you need to do is verify that x-debug has been loaded which you can do in two ways, phpinfo() showing XDebug loaded A) run a page with phpinfo() on it and you should see XDebug on there OR B) write some bad code (how hard can that be) and verify that you now have fancy looking errors.

At this point you are ready to develop. If you don’t have a preferred IDE for PHP check out Eclipse with PDT or Zend Studio for Eclipse. Try loading up your favorite Framework and get coding. If you don’t have a favorite framework come to OrlandoPHP on April 22nd for a discussion on PHP Frameworks.


4 Responses to Developing PHP on a Mac

  1. Ryan Price August 7, 2008 at 10:14 am

    MacPorts FTW

    (formerly DarwinPorts)

  2. ian merkel September 3, 2008 at 9:54 am

    nice! thnx bro! very timely too ( you know why )

  3. Snowden November 16, 2008 at 9:59 pm

    Cool, thanks man. I’m doing the mac switch and after using a VAMP setup (which took some time to enable) I’m happy to hear it’s a whole lot easier to setup a local testing environment on a mac. Touch wood it’s as easy as it sounds.

  4. PuReWebDev September 23, 2010 at 9:57 am

    Just an fyi, the latest version of MAMP, actually comes with xdebug, the module, and the entry in the php.ini (which happens to be commented out), just remove the ; , restart MAMP and it’s rocking. Thanks for the tutorial just the same.

Leave a Reply

Your email address will not be published.