How to Set xdebug in Mac OS X with phpStorm and MAMP in 23 Easy Steps
Warning
This blog post is included for archival purposes and may contain outdated information. While it provides historical insights, we strongly recommend that you double-check the details before relying on any of the information outlined here.
It’s amazing how spoiled we tend to get with products such as Xcode and Visual Studio. I’ve gotten accustomed to debugging a web application by hitting F5 and off you go. After the last hour or so of configuring phpStorm has taught me, setting up remote debugging can be a bit of a pain.
I’m going to document all I did because I’m bound to forget it all. Here is my current setup:
I am assuming you have MAMP running and phpStorm installed. I am also assuming you will be using Chrome.
In you want to debug PHP using MAMP, you have to use PHP 5.2.17:
Open the PHP ini file for version 5.2.17, usually found under: /Applications/MAMP/bin/php/php5.2.17/conf/php.ini
Look for the portion of the code that reads:[xdebug]
;zend_extension=”/Applications/MAMP/bin/php/php5.2.17/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so”
Remove the ‘;’ before the zend_extension bit
Append the following below that line:xdebug.remote_enable=true
xdebug.remote_port=9000
xdebug.profiler_enable=1
xdebug.profiler_output_dir=”/Applications/MAMP/bin/php/php5.2.17/tmp>”
Stop your MAMP server and restart it again
To make sure xdebug is properly installed, from the MAMP App, select “Open start page”
When the page loads, click the phpInfo link in the toolbar:
Scroll all the way to the bottom and find the section called Xdebug, the following should be listed:
At this point, xdebug is installed. Now we must configure phpStorm to work with it. Launch phpStorm, create/open the project you want to debug and from the File menu select Preferences.
From the Project Settings section, click the PHP node:
Notice the right pane now allows you to select the PHP interpreter to use. MAMP ships with various versions of PHP, but we need to set this one to use 5.2.17 if we want to to debug. Click the Ellipsis button, create a new configuration by clicking the ‘+’ and selecting “Specify Other”
Name the configuration PHP 5.2.17 and specify as the PHP home the following path:/Applications/MAMP/bin/php/php5.2.17/bin
phpStorm will now recognize the interpreter and display the version:
From phpStorm, select from the Run menu Edit Configurations
Click the ‘+’ sign and select PHP Web Application
Fill out the values to your corresponding development environment, here is mine as a guide (make sure to select Chrome as your browser)
Almost there! To make life easier when hooking up the debugging session with Chrome, we need to install an extension that will make life easier, the Xdebug helper extension.
Once installed, open the web page you would like to debug in Chrome
Now it’s time to test debugging! Set up a breakpoint somewhere in your code that will be hit when the web app runs.
From the Run menu, select Debug [Name of your Project]
Chrome will open the web application, you will notice that your URL has a debugging portion added to the URL:
Back in phpStorm, your breakpoint will be hit and now you can debug!
If you have questions or comments, please post below, I’ll leave this thread open for a while.
Christian is a seasoned computer engineer with a rich career spanning collaborations with industry leaders such as Artinsoft (now Mobilize.net), Microsoft, HP, and Intel. As a technical evangelist and trainer, Christian honed his expertise in Costa Rica and Seattle, delivering impactful solutions and sharing his knowledge.
Now based in Sydney, Australia, Christian channels his passion into web development, leading a talented team to tackle diverse projects with innovation and precision. His commitment to crafting exceptional digital experiences reflects his deep-rooted enthusiasm for technology and problem-solving.
Comments
Comments are closed
ScorpioTek, based in Sydney, Australia, is a seasoned web development firm with a proven track record of delivering cutting-edge, user-friendly websites for a diverse range of clients.
Thank you for your interest. Please fill out this form to provide us with your contact information. We'll get back to you as soon as possible.