Very excited to present my own Setup Guide to get Xdebug, PhpStorm and MAMP to play nice together. Our goal here is to get remote debugging setup to be able to debug any line within a much bigger web app. In our case I am interested to debug WordPress Themes and Plugins without having to declare what file to start from.
YouTube Video Xdebug, PhpStorm and MAMP – OSX – Setup Guide
Two different types of Xdebug modes
- Direct (via command line)
- Remote (via browser)
I am no expert on this topic, so apologize my language. If anybody knows the proper terminology, please leave them in the comments and I am more than happy to change this. Essentially you can find two types of debugging. Direct one and remote. The first one essentially is essentially like running php from your command line using Xdebug. So you need to know exactly where to start and all files you want to debug need to be somehow connected (told you I am no expert on this…). The second method is the remote debugging where anywhere in you code you set a break point and essentially trigger the debugging remotely, in our case a browser. This is what we want
Here is how those two options look like in PhpStorm:
There are plenty of steps to do in order to get this to work. Here is the step by step list.
Note I will be doing most work from the terminal. You should be able to copy paste all commands.
Here is my setup for this Setup Guide
- MAMP 2.2
- PhpStorm 8.0.1
- OSX 10.7
Xdebug Phpstrom Mamp Install Guide
1. Find Your PHP version in MAMP
2. Set your PHP version globally (optional)
Either create or open your .bash_profile file in ~/.bash_profile
open ~/.bash_profile or if your .bash_proile doesn’t exist
touch ~/.bash_profile; open ~/.bash_profile
enter the following at the bottom of your .bash_profile:
# MAMP PHP export MAMP_PHP=/Applications/MAMP/bin/php/php5.5.3/bin export PATH="$MAMP_PHP:$PATH"
Restart your terminal.
Check your php version with:
3. Find your PHP ini file
Your php ini file will be in:
If you setup you MAMP PHP globally you can also do:
php -r 'phpinfo();' | grep 'php.ini'
and find your php.ini path. Couldn’t help myself but geek out. Sorry…
4. Add the remote session parameters to php.ini
Open your php.ini file.
Find the section Xdebug and uncomment (aka remove the semicolon) the zend_extension and add the following two options until your section looks like this:
[xdebug] zend_extension="/Applications/MAMP/bin/php/php5.5.3/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so" xdebug.default_enable=1 xdebug.remote_enable=1
Your Xdebug section should be at bottom of your php.ini file.
Make sure you restart your MAMP server after editing your php.ini file, otherwise your settings wont apply.
5. Install browser extension
The title says it all:
6. Set PhpStorm IDE key
In your Xdebug Helper browser extension go to Options via chrome://extensions/. The Xdebug Helper should be at the bottom. Set the IDE key to PhpStorm.
7. Start PhpStorm and setup project with localhost
Setup the project with PhpStorm. Make sure you set the correct project root and setup the localhost with the correct port.
In our case we will open project wp-test.
8. Turn on Listening for Debug Connections
Turn on via: Go to Run -> Start Listening For PHP Debug Connections
9. Start debugging in browser
Switch the little to Debug.
10. Set breaking points
Finally… In PhpStorm just click into the line on the left.
11. Refresh browser
12. Accept remote connection in PhpStrom
PhpStorm should recognize at this point the remote connection and ask you what you want to debug. Set your choice on your project root folder.
13. Fix mapping
Check the debugger for the mapping error and untick the mapping. You can now run the debugger and it will stop at your breaking point.
Phew we are all set. If all is working for you, you should now be ready to use Xdebug, PhpStorm and MAMP. If you have any questions I will do my best to help. Please consider though that I have very little experience in this.