- Details
- Category: Mac OSX
- Hits: 611
Assuming:
- You wish to use the Apache2 web server that comes with OSX 10.8
- AND you have already started it up on your own Mac (if not, see the article Enabling Apache on OSX 10.8)
- You don't want to clutter your mac with XAMP type environments (which I believe duplicate some of what you already have on the Mac)
- You know how to take precautions to back up critical system files you will be editing and recover from your own oops-isms
- You wouldn't be on this page if you didn't really want to debug php (thus you are a programmer of sorts)
Then this page:
- Will help you get to the point of being able to debug php
- Will show how to get the Safari browser and MacGDBp App working together
- And will do so without installing all the XAMP stuff (since OSX Moutain Lion comes with everything you need to run as a web host in the first place).
Note: XAMP, and others like it, are great tools and offer lots of features and advantages, but its not something I've really pursued. This set of instructions follows the minimalist approach and only needs to add one application (that can easily be replaced if need be by something better some day in the future) and one browser extension (that can easily be turned off). So for some XAMP is great, for me its not my cup of tea. So, I'm not criticising it.
Outline:
- The Apache php.ini file setup - part 1
- Installing the MacGDBp application
- The Apache php.ini file setup - part 2
- The Safari Xdebug Helper extension setup
The Apache php.ini file setup - part 1
Apache2 (the implementation of Apache that comes with OSX) will read its php.ini file from the /etc directory of the boot drive then run it in /private/etc
If you've never made any adjustments to the php.ini file, then it probably doesn't exist and Apache2 is running default settings (from /etc/php.ini.default). Don't mess with this one - you may need it if you have an oops-ism moment. Instead, copy it to /etc/php.ini. Here's an example of how to do so using the Terminal application (assumed for the rest of the article unless otherwise noted). Note: the background color of text on this page is slightly different for each distinct editor/mode. Note: The command sudo to "do something as super user" and may ask you for the administrator password in order for it to continue.
sudo cp /etc/php.ini.default /etc/php.ini
If instead /etc/php.ini already exists, make a backup copy of it
sudo cp /etc/php.ini php.ini.bu_yyyymmdd
{Name the backup copy anything you want - in this example yyyy is the year, mm the month, and dd the day of the month}
Now edit the php.ini file to turn on Xdebug etc.
sudo vi /etc/php.ini
If prompted for a password, enter the administrator password for your Mac (typically your own login password by default if you are the owner/administrator - otherwise, if you are using someone else's Mac, you will need to get them to assist)
Now using vi as the editor, execute the following commands.
First, find the zend extension setting by using vi (the slash in the next command does just that):
/zend_ext
which should land your cursor on this line...
;zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"
If the semi-colon (;) is still there, make sure the cursor is over it and type
x
to delete it.
If the vi editor complains that you are editing a readonly file, ignore it, will take care of that later
Next, search for the Xdebug setting by typing
/xdebug.rem
which should land your cursor on this line...
xdebug.remote_enable=1
If the (;) is till there, make sure the cursor is over it and type
x
to delete it.
Next, force save the file.
:write!
Then, quit the vi editor
:q
Restart Apache
sudo apachectl stop sudo apachectl start
Assuming you have:
- setup your Apache2 similar to the article Enabling Apache OSX 10.8, and
- used the article Setting up a home page on your localhost to create a custom home page that will show phpinfo() automatically. Or, create a subfolder with code in it to do so (see Making a phpinfo() page on your localhost),
then entering the url localhost in your browser will produce a whole lot of phpinfo output which contains the following near the bottom:

Installing MacGDBp
Download Blue Static MacGDBp (assuming version 1.5 or greater)
Install MacGDBp and then run it. If your system complains because you have your security settings set such that you aren't allowing yourself to run "non app-store" apps, then you will have to change the settings in your System Prefereneces - Security pane to get it to run the first time. After you run MacGDBp, you can set your security settings back to be more restrictive once again.
The Apache php.ini file setup - part 2
Now that Xdebug has been shown to be enabled, lets now get it ready to run under MacGDBp
First, you need to know the exact url of your localhost. It can be your IP address (which may change from time to time if you are using DHCP on your network to assign you an IP dynamically). It's best if you open your System Preference application, open the "Sharing" pane

and denote your Mac's local network network name from beneath the Computer's name - is should be something.local. You will need it in just a moment

Open the php.ini file again
sudo vi /etc/php.ini
Search for the debug stuff again by typing in vi
/xdebug.rem
With your cursor on this line, enter additional lines by typing in vi
o
which opens up a new line and will put you in "insert" mode - so what you type now will be added verbatim (except for the value "localhost") until you type ESC. The value localhost in this next line needs to be replaced with your actual local hosts name (the something.local you just fetched from the Systems Preferences - Sharing pane)
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_autostart=1
Type the ESC key to exit the vi editor
Use your cursor keys (or search mode in vi using the / as in above commands) to find the line
;xdebug.idekey="macgdbp"
Remove the ; from the beginning of the line by typeing the x over it like before.
Next, force save the file
:write!
Then quit the vi editor
:q
Restart Apache again
sudo apachectl stop sudo apachectl start
The Safari Xdebug Helper extension setup
In Safari, install the extension Xdebug Helper by using the Safari menu "Safari : Safari Extensions...", or by going to http://extensions.apple.com, click on the "Developer" category to narrow down the search, and find Xdebug Helper

Click the Install button to its right.
Once the installation completes a new icon will appear to the left of the URL box in Safari
![]()
Now setup the Xdebug Helper extension in the Safari Preferences window under its Extensions tab. Change the IDE key: field to read XDEBUG_macgdbp

Close the Extensions window.
You will need to navigate to a site for which Safari has full access to the php - such as your localhost (ISP provided web sites run the php for you so you don't have access to its php scripting and only see the results of such in your browser).
Navigate to your localhost home page in Safari.
Now, to see it in action, popdown the menu from the Xdebug Helper icon at the top of the Safari window, and select "Trace"

It should now show a banner number over the icon to show how many sessions are active

Refresh your localhost home page in Safari
MacGDBp should now be showing you a trace event!

Keep in mind you have now interrupted the refresh of the page! You must go to the main window of MacGDBp and operate its buttons - Step, Continue, whatever. To stop debugging, go back to the XDebug Helper icon on Safari and set it to Disable.
Some history:
Prior versions of OSX made it difficult to use Xdebug with the Apache web server that was included with the system. That seems to have changed with Mountain Lion (OSX 10.8)
Other useful links and credits:
- Here's another example for "Configuring XDebug on OSX Mountain Lion" but which uses PhpStorm as the example IDE
- For the brave at heart who want to "upgrade Xdebug" on their own see the Xdebug home site
Feedback is always welcome from non-spammers: feedback

