4

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:

  1. MAMP 2.2
  2. PHP 5.3.3
  3. Eclipse Kepler
  4. Eclipse PDT
  5. Xdebug
  6. 2 virtual hosts with roots at /Applications/MAMP/htdocs
  7. Apache Port: 80
  8. MySql Server Port: 3306

My virtual hosts setup within MAMP is working fine. Below are screenshots concerning the Xdebug setup:

Eclipse XDebug Configuration

Eclipse PHP Server Configuration

Eclipse PHP Executable Configuration

php.ini Xdebug contents

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!

faridghar
  • 1,445
  • 2
  • 13
  • 25
  • Can you tell from the web server logs whether it ever receives the request? On the client, does the connection to port 9000 ever get made (does `netstat -na | grep :9000` say CONNECTED, or just LISTENING)? – Andrew Schulman Dec 21 '13 at 13:24
  • I've checked the apache_error.log and php_error.log and nothing get's logged in these files. netstat -na | grep :9000 doesn't show anything either (no lines match the grep). – faridghar Dec 21 '13 at 14:01
  • Apologies, turns out there was this line in the php error log: [21-Dec-2013 15:36:45 Europe/Berlin] PHP Warning: The remote debug handler '”dbgp”' is not supported. in Unknown on line 0 – faridghar Dec 21 '13 at 14:39
  • I can't understand that error, because your 1st screenshot shows that you have dbgp disabled. – Andrew Schulman Dec 21 '13 at 15:41
  • In my first screenshot, the dbgp **proxy** is disabled. As far as I know (and I could be wrong), the proxy is only required when you want multiple users to be running debug sessions concurrently. Is that not true? – faridghar Dec 21 '13 at 16:15
  • 2
    Just as an update, I removed the virtual host configuration (removed entries from hosts file, removed entries from MAMP httpd-vhosts.conf file and put all website files under htdocs. Then I added the following option to the php.ini file: "xdebug.remote_log=/tmp/xdebug.log" in order to generate an xdebug file. This showed me the same error: "E: The remote debug handler 'DBGp' is not supported. :-(" in the generated log. So I changed the option in the php.ini file from "xdebug.remote_handler=DBGp" to "xdebug.remote_handler=dbgp" et voila! IT WORKED! – faridghar Dec 21 '13 at 18:47
  • I'm going to revert back to the virtual host configuration and see if debugging is still working. If it is, I'll post a full solution to the steps required for future reference. – faridghar Dec 21 '13 at 18:48
  • Great news! Remote debugging is a pain to get set up, but so worth it when it finally works. Please do post a solution, to give yourself credit and help others. – Andrew Schulman Dec 21 '13 at 19:00

1 Answers1

1

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->

Eclipse Debugger Configuration

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

Eclipse PHP Executable Configuration

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

Eclipse PHP Server Configuration

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.

Eclipse Debug Configuration

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.

Eclipse Debug Configuration: Debugger Tab

That is all you should need to do. Happy debugging! :)

faridghar
  • 1,445
  • 2
  • 13
  • 25