My problem:
When launching a debug configuration from Eclipse for one of my php pages, the page opens successfully in Chrome but the Eclipse debugger freezes at 57% (in the bottom right hand corner of Eclipse) and never progresses further. The set breakpoints are never reached.
My setup:
- MAMP 2.2
- PHP 5.3.3
- Eclipse Kepler
- Eclipse PDT
- Xdebug
- 2 virtual hosts with roots at /Applications/MAMP/htdocs
- Apache Port: 80
- MySql Server Port: 3306
My virtual hosts setup within MAMP is working fine. Below are screenshots concerning the Xdebug setup:
I suspect the problem is being caused by my virtual hosts. The two virtual hosts are under "/Applications/MAMP/htdocs/ledworld" and "/Applications/MAMP/htdocs/sandbox". Im currently trying to debug the sandbox project.
If you could provide detailed instructions on what changes I should make to the attached screenshots or step by step instructions on how to set this up that would be great!
Here is the full solution for anyone else stuck on this:
The bottom of your /Applications/MAMP/bin/php/<your_php_version>/conf/php.ini
should look like this:
[xdebug]
zend_extension="/Applications/MAMP/bin/php/<your_php_version>/lib/php/extensions/no-debug-non-zts-<timestamp>/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_host=sandbox
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.idekey=ECLIPSE_DBGP
xdebug.remote_log=/tmp/xdebug.log
Note that then xdebug.remote_host
option is set to the name you gave your virtual host. So in my case, my httpd-vhosts.conf file would containt an entry like this
<VirtualHost *:80>
ServerName sandbox
DocumentRoot /Applications/MAMP/htdocs/sandbox/
<Directory /Applications/MAMP/htdocs/sandbox/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
and my /private/etc/hosts
file would have an entry like this
127.0.0.1 sandbox
From the Eclipse side of things, here is what you should do.
Configure the XDebug debugger of Eclipse. Make sure that the selected port matches the port specified in the php.ini file above
Make sure that "Accept remote session (JIT)" is set to "localhost" if you want external programs to trigger debug sessions (e.g. Chrome Xdebug helper extension).
Eclipse Preferences->PHP->Debug->Installed Debuggers->XDebug->Configure->
Add a new or edit an existing PHP executable in Eclipse:
Make sure that the "Executable Path" and "php.ini File" fields point to the same version of PHP that MAMP is using (MAMP->Preferences...->PHP->PHP Version. You probably don't need to also fill in the "php.ini File" field, but I do it anyway.
Eclipse Preferences->PHP->PHP Executables->Add/Edit
Setup a server in Eclipse:
I use HTTP port 80 for Apache under MAMP (MAMP->Preferences...->Ports->Apache Port). If you use a difference port, make sure to include it at the end of the "Base URL" in this screen.
Eclipse Preferences->PHP->PHP Servers->New/Edit
Create a new Eclipse debug configuration that looks like this:
The "PHP Server" should be set to the server you created above. The "File" should be set to the php file you want to debug within your project. If the "URL" field does not show what you would expect to type into your browser to load your PHP file (namely http://<virtual_host>/path/to/file/being/debugged.php
, then uncheck the "Auto Generate" box and manually modify the second part of the "URL" field so that the complete URL is what you expect. Don't forget to add any query parameters that your PHP script expects to find in the $_GET variable.
The "Debugger" tab of the debug configuration should look like this:
Make sure "Server Debugger" is set to XDebug. I like to uncheck the "Break at First Line" option because I find it annoying to always break at the first line of code. Use breakpoints instead to control where the debugger stops.
That is all you should need to do. Happy debugging! :)