viewBox="0 0 51 48">Five Pointed Star Five Pointed Star

Setting Up a Local Test Environment and IDE with Debugging Capabilities for PHP on Mac OS X Lion

Setting up a native AMP stack

AMP stands for Apache, MySQL, and PHP. Apache and PHP are built into OS X 10.7 and we will walk through the setup and instal­la­tion of MySQL.

You can ver­ify your native instal­la­tion of Apache and PHP and obtain the ver­sion infor­ma­tion with these com­mands from (/Applications/Utilities/Terminal):

php -v

And you’ll see some­thing like this:

PHP 5.3.8 with Suhosin-Patch (cli) (built: Nov 15 2011 15:33:15) Copyright (c) 1997-2011 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies with Zend Debugger v5.2, Copyright (c) 1999-2009, by Zend Technologies

httpd -v

Results in some­thing like this:

Server version: Apache/2.2.21 (Unix) Server built: Nov 15 2011 15:12:57

Running Apache

You can start and stop Apache from Sys­tem Pref­er­ences » Shar­ing. Just check the box labeled “Web Sharing.”

Sharing Preferences

Or from Ter­mi­nal you can con­trol the Apache dae­mon startup, shut­down, and restart, respectively:

 sudo apachectl start sudo apachectl stop sudo apachectl graceful

Activate PHP

PHP is installed but not enabled. To enable it we run some more com­mands from Ter­mi­nal. The sudo com­mand will cause a prompt for your pass­word. You can use what­ever text edi­tor you would like, but nano is quick and easy

cd /etc/apache2/

sudo nano httpd.conf

Around line 115 you will find the php5 mod­ule and the line is com­mented out with a hash “#” symbol. Remove the hash to uncom­ment the line.

httpd.conf file

Press Ctrl-x and then y to save and exit from nano. Then restart Apache.

sudo apachectl graceful

Install MySQL

Point your browser at and choose Mac OS X ver. 10.6 (x86, 64-bit), DMG Archive

MySQL .dmg contents

Upon down­load­ing the .dmg file and open­ing the disk image, you will see three main instal­lable items. It is very impor­tant the order in which you install these items! First install the mysql pack­age file (.pkg), then the MySQLStartupItem.pkg, and finally the MySQL.prefPane. You will find the MySQL pref­er­ences now under Sys­tem Pref­er­ences » Other (toward the bottom).

MySQL System Preference Pane

Now we need to add MySQL to the bash shell path.

 cd ~ nano .bash_profile

Add this line and press Ctrl-x and y to exit and save:

 export PATH="/usr/local/mysql/bin:$PATH" source ~/.bash_profile

To test whether or not this worked try this com­mand again:

mysql -v

mysqladmin -u root password '[yourpassword]'

Point your browser to http://localhost/~[your user name] and you should see “It works!”

Install php­MyAd­min

Down­load from here: php­MyAd­min. Uncom­press and rename the folder to php­MyAd­min, then move it to /Users/[your username]/Sites/

There are some bash (Ter­mi­nal) com­mands to run (set up a sym­bolic link to the Mac OS X 10.7.x loca­tion of mysql.sock and set some permissions):

 sudo mkdir /var/mysql sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock mkdir ~/Sites/phpMyAdmin/config chmod o+w ~/Sites/phpMyAdmin/config

Nav­i­gate to http://localhost/~[your username]/phpmyadmin/setup/. Click on New server, Fill in the authen­ti­ca­tion tab with your user­name and pass­word. Click save, and again on the intial screen when it reloads. When upgrad­ing php­MyAd­min in the future, be sure to keep the file from your old instal­la­tion with your local­host server settings.

Set­ting up a PHPIDE with debug­ging capabilities

Down­load Eclipse for PHP Devel­op­ers here: Eclipse Helios. You can sim­ply uncom­press it and move the folder to /Applications or ~/Applications.

Now to setup debug­ging, first down­load and uncom­press the Zend Debug­ger plug-in for Eclipse. It will uncom­press to a folder called Eclipse. Inside are two fold­ers, fea­tures and plu­g­ins. Copy the con­tents of these fold­ers to your main Eclipse folder in the cor­re­spond­ing fold­ers there. Now, we need the Zend debug­ger exe­cutable, avail­able here: Zend Stu­dio Web Debug­ger. You’ll want the 64 bit ver­sion of “Stu­dio Web Debug­ger.” Uncom­press the gzipped tar­ball and you should see this folder:

Zend Debugger Folder Contents

We want the file inside the 53x_comp folder. From Finder, with this folder win­dow open, press Shift-⌘-G and enter /usr/lib/php/extensions/ into the dia­log box. Move the file inside /usr/lib/php/extensions/ (Authen­ti­cate if nec­es­sary). Edit the /etc/php.ini file by adding these lines to the bottom:

 [Zend Modules] zend_extension=/usr/lib/php/extensions/       zend_debugger.allow_hosts=,192.168.*.*,10.*.*.* zend_debugger.connector_port=10000 zend_debugger.expose_remotely=always

Restart Apache & Ver­ify installation:

sudo apachectl graceful php -m

You should see the fol­low­ing at the bottom:

[Zend Modules] Zend Debugger

Eclipse Setup

The next step is to setup Eclipse to use the debug­ger. Go to Pref­er­ences » PHP. We need to add Mac OS x’s PHP 5.3.8 exe­cutable and make it the default.

Eclipse PHP Preference Settings

Click Add

Eclipse PHP Executable Settings

Next, setup the debugger…

Eclipse PHP Preference Settings

As a last, but purely optional step, I installed the Aptana Stu­dio 2 (not 3) plu­gin for now, until Aptana Stu­dio 3’s PHP debug­ger is fin­ished(PHP Debug­ger). From the Eclipse Help menu select Install New Soft­ware, paste this url — — into the Work With field and press return. Fol­low the prompts to install the Aptana Stu­dio 2 Eclipse plu­gin for addi­tional PHP cod­ing features.

One last thing, if you want to change the browser from the default sys­tem web browser (like Fire­fox so you can use Fire­bug), here is what you do — under Pref­er­ences » Gen­eral » Web Browser, add the fol­low­ing. Then be sure to high­light it and set as default when you are done.

Eclipse Web Browser Preference Settings

Now to debug a php script locally, all you have to do is right click and select Debug As » PHP Web Page. You now have a pow­er­ful local test envi­ron­ment and IDE in which to develop PHP projects. Congratulations!

L. Ball
L. Ball

Father. Developer. Coffee Connoisseur. Amateur Guitarist.