A development tools such as Microsoft Visual Studio has debugging feature built-in where you can step through the code line by line and watch the variables. There are times when you may want to do the same thing with PHP script running in a remote (or it could be local as well) web server. It is possible thanks to Xdebug.
This article will focus on configuring Xdebug on your MAMP development platform. We’ll focus on utilizing Eclipse IDE platform as debugger client. So let’s get started.
Installing Xdebug on your MAMP
Regardless which way your MAMP is configured, the easiest and quickest way, perhaps, is to download Xdebug binary that I compiled myself. Note that it was compiled on Intel Mac on 10.5.6 Leopard and was tested only on my Intel MacBook Pro.
- MacOS X Xdebug binary 2.0.0
- MacOS X Xdebug binary 2.0.1
- MacOS X Xdebug binary 2.0.2
- MacOS X Xdebug binary 2.0.3
- MacOS X Xdebug binary 2.0.4
So which version to use? Well, Xdebug documentation recommends version 2.0.2, but then again, I’m not sure how outdated the documentation is. So I decided to provide all and let you decide yourself.
If you’re using MAMP Application package
Once you decide which version to download, copy the newly downloaded xdebug-2.0.x.so to /Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20050922/. Your extension location may vary depending on which MAMP version you have installed. Check phpinfo() page for your exact location.
Xdebug is not compatible with Zend Optimizer. So you need to make sure that Zend Optimizer is disabled in your MAMP. Click on preferences button then on PHP section, make sure Zend Optimizer is unchecked. Also make sure that you’re not using cache. Below is how your PHP MAMP preference should be.
Then edit your php.ini using your favorite text editor. For my MAMP installation (version 1.7.2), php.ini is /Applications/MAMP/conf/php5/php.ini. Then add the following line somewhere in your php.ini. I like to add it at the end of the file.
Make sure you specify the absolute path to xdebug binary otherwise you may have some issues. Save your modified php.ini file and restart servers on MAMP app. Then go to phpinfo() page again and make sure that Xdebug is listed.
If you’re using the built-in PHP
The concept is basically very similar to the MAMP app. The only difference is the location of php.ini file, extension_dir and how to restart Apache. On the built-in MAMP stack, restart Apache from System Preferences -> Sharing then check & uncheck Web Sharing service.
Next, we’ll discuss on using Xdebug for remote debugging using Eclipse IDE through example.