Sunday, October 28, 2007

Getting Breakpoints to work in Eclipse PDT using Zend Debugger

November 18th, 2007 UPDATE: Please see the section at the bottom of this post for an update!

I've recently been fooling around with PHP.

At work we have a Drupal-based web site, and I figured it was time to get a better mental-grasp around PHP. After looking through a whitepaper from IBM titled Using open source software to design, develop, and deploy a collaborative Web site I decided I needed to get myself a development environment setup in which I could work with Drupal 'under-the-hood'.

IBM's whitepaper was written in various pieces over the course of about a years time. One of the sections discusses setting up Eclipse with different plugins that facilitate PHP development. In a later section they mention the PHP Development Tools (PDT) - a more comprehensive set of PHP development and debugging tools for Eclipse. Lucky for me, they now have a PDT all-in-one Eclipse package that makes setup even easier. (Get the package from here.) After downloading and installing it, and getting a feel for the whole thing (wow, Eclipse is complicated at first,) I got down to the brass-tacks and tried debugging.

Before I go on, here's a little more information about my development environment:
  • OS: Window XP SP2
  • Development Environment:
    • Eclipse : PDT
    • PHP 5.2.4
    • MySQL 5.Something
  • Web server: Apache
PHP, MySQL and Apache are all from the Apache Friend's XAMPP package.

I followed the instructions on the PDT Wiki for instructions on how to Install the Zend Debugger for Eclipse.



Just for reference, in the screenshot above, you'll notice my "Dummy Debugger Test Server" configuration. Here's a screenshot of the specific details of that config:


After getting everything setup, I could get the debugger to debug any PHP-based web page -- so long as I had the "Break at First Line" debugging option set. I could start the debugger and at the first line of PHP code, the debugger would 'catch', and allow me to step through my code. Everything worked as expected - variables and their values were visible in the Variables dialog, I could step into and out of various functions. Unfortunately, if I set breakpoints anywhere, they would never 'hit', the debugger wouldn't halt the PHP execution on the specified breakpoints. It would zip right past them as though they never existed.

Naturally I hit-up my good friend Google for answers. I found a number of people having the same problem as myself. I found instances of people having this problem all the way back in January of 2007. I also found instances of people having this problem as recently as October of 2007! Every single time I found someone saying they had the problem, nobody ever had an answer for them!

Finally, finally, I was able to find this somewhat cryptic post on how someone fixed the problem:


Not sure if this helps, but I ran into the same problem myself. I found out that it was that the plugin expects the project root to be the http root.

My project structure had the http root as a subfolder of the project root.

If the http root isn't the same point as the project root, then the plugin can't correctly inform the debugger which file the breakpoint is in.

I ended up hacking the source to make the plugin work at a subfolder level.


Problem was, he stated that he hacked the source of the plugin to 'make the fix'. Not exactly what I was hoping to do. I figured I was approaching yet another dead end, but something about him stating that the plugin was simply confused about expecting your Eclipse project's root to be the web server's root gave me an idea: Move my content to the virtual host's root directory.

I tried moving my project's files all into the root folder of the web server (just dummy.php in this case.) I modified my "Dummy Debugger Test Server" configuration as shown in this screenshot:


I made sure that "Break at First Line" was unchecked/disabled, and fire up the debugger. It worked. It finally worked. After all that trouble it freakin' worked.




Has anyone else had this much trouble? Has anyone been able to get debugging to work when your debugged PHP doesn't reside in the root of your web server?

November 18th, 2007 Update:
I think I may have a better example. I've also been 'playing' around with the Symfony PHP Framework. I again ran into this breakpoints-not-working problem when trying to debug a Symfony-based project.

I'm going through the "Askeet" tutorial and have imported a project into Eclipse and had my Apache instance serving up the "/web" subfolder served up as the server's document root.

Of course, this confuses the debugger plugin, because, again, the debugger is assuming that the Eclipse project-root corresponds directly to the web server's root directory, which it's not. This is the situation:



The arrow titled "Assumed" is what the debugger is wrongly assuming. To fix the problem, you have to configure your web server to match that assumption.

So, I modified the virtual host's DocumentRoot to point to the Askeet project's root folder, even though there is no index.html or index.php to be served from there. I had to also modify the "/sf" alias to handle "/web/sf". (If you're using Symfony, you should know what I'm talking about.) So, now instead of going to http://localhost, I have to go to http://localhost/web/. But since this is strictly for development purposes, it's not a big deal. Oh, and I had to make a slight modification to the debugging profile in Eclipse to match the new /web/index.php URL. Again, not a big deal.

I hope this update cleared any confusion...

31 comments:

Anonymous said...

I've just reproduced the PDT debugger bug and also the solution. Setting apache docroot to point to the project root worked very well. Thanks a lot!.

Jason Poll said...

Glad to hear it helped.

I hope this gets fixed in a future update as I prefer to have the flexibility of having my various projects under different sub-directories of my web server. Having to move them into the root each time I want to work is an inconvenience.

Unknown said...

I've tried using your solution as I have the same problem with Eclipse, PDT, and the Zend debugger, but it's not working for me. The breakpoints are still ignored.

My PHP project in Eclipse points to the same file directory as the document root for Apache.

Does it make a difference if my Apache Web Server is on manual start?

Anonymous said...

When the PDT debugger does not stop on your breakpoints then it is because it is confused in what file the breakpoint is set.
Consider that you have a test project with a test.php file in your workspace. You set a breakpoint in test\test.php and launch the web debugger.
The debug server config is set up to point to your web project root, lets say localhost/webtest and you also specify the directory where to find this on your webserver system. This might be d:\webroot\webtestdir.
The PDT debug environment opens test.php but does not stop on the breakpoint. By hovering over the filename tab you will notice this is test\test.php which is in your workspace.
Now goto the file menu and open d:\webroot\webtestdir\test.php and set a breakpoint in this file. Try again and you will find the breakpoint does work.
It is highly confusing to have two tabs with the same name open. You will end up making changes to the wrong instance. Let's hope we get this improved in PDT soon.

Anonymous said...

This problem is solvable by insuring that your apache server settings within eclipse point to the actual document root, both url-wise and filesystem-wise. DO NOT point them to the subdirectory where you want your project to live.

Then, you must create a debug profile for the web page or script you wish to debug, set it to publish to the server, and then add the subdirectory where you do want you project to live on the server to the Publish To text box.

I admit that it is confusing and it took me some trial and error before I figured it out. I had the same problem mentioned and now it is working for me.

Jason Poll said...

Great comments, thanks - I wish I could have found these answers earlier. :)

Jerome: I hope the other anonymous comments have helped rectify your situation. I'm so 'green' with Eclipse that I'd just be repeating what they've already stated. :)

Unknown said...

Ok wow! Problem solved!

Thank you guys very very much. I think you probably saved me a day of pulling my hair out =).

Great article Jason. It's the first resource that I found to help me with this problem.

Jason Poll said...

Thanks Jerome.

I've said it before, and I guess I'll say it again: when a problem has given me such a hard time, and finding an answer proved to be equally difficult, (even with Google's help,) I post about it.

Not surprisingly, these are the posts that get the most hits. :)

Anonymous said...

HI Jason,
I have a similar situation:
my symfony url is : http://localhost/frontend_dev.php/mymodule/index

If I say, breat at first line, it is actually stopping at at the first line of 'frontend_dev.php'. But all other breakpoints (say in the module/action php) are ignored.

If I don't set the option, then I don't hit any break points.

Can you post your full config for debugging Symfony? Yours is the most informative post on this topic!

- Virtual Host settings
- Eclipse debugger settings

Thanks

Ranjan said...

Thanks Jason.

Now i have configured a single PHP server pointing at the root. Then use a project specific Debug options to work on with sub-directories of my web server. It works superb.

Thanks again.

Jason Poll said...

In response to the anonymous "symonfy user" - I've ran into the same problem now. :(

I suspect it has to do with the fact that, by definition, you symfony project is including the symfony 'core' files, which do not reside in your project 'root'.

Unfortunately, I haven't had time to delve into this further. If I figure anything out, I'll be sure to post it here.

Egr said...

Thanks for the post!
It save me a lot of time!

Anonymous said...

Exactly what I needed to know!!! Thank you very much. This saved me hours of work and heartburn!!

Worked like a charm.

Parul Seth said...

Hi
I am a newbie in developing eclipse plugin's..:)!
Can you please tell me how can we add breakpoints through the outline view programmatically?
I have an XML editor whose outline is shown on the outline view and I want to add breakpoints through its content outline.
I am able to add a popup menu on the outline i.e Toggle Breakpoint. but it is not working.
Please Help!!!

Regards
Parul Seth

Jason Poll said...

Parul: Sorry, I've no idea how to develop eclipse plugins.

Anonymous said...

I checked "Publish on the server" and it destroyed my files! Files became directories of the same name if memory serves me right.

Anonymous said...

Perhaps this is useful to people that do not want to screw up their main webserver configuration by pointing the HTTP root to the project root:

I have created a new apache2 VirtualHost that listens to port 8080, of which the root points to the project root. The VirtualHost listening on port 80 still points to default /var/www on my system.

In Eclipse/PDT I changed the debug server configuration by setting Run->Debug Configurations...->PHP Server->Configure...->URL to http://localhost:8080 instead of http://localhost

It works fine for me. Many thanks for the information! Kind regards, Jeroen

VincentG said...

Not sure if this helps anybody, but in the recent version of Eclipse with PDT i run on my mac, there is an option in the debug conf to link a server path to a local path.
It did not seem to work though.

Why not just apache's vhost?
In MAMP (or LAMP/WAMP) you can use http.conf or http-vhost.

put something there like :
< VirtualHost *>
ServerName phptest
DocumentRoot /Users/vincent/Documents/workspace/PHPtestproject
< /VirtualHost>

and create a new config in eclipse with name phptest instead of localhost.
Add phptest in /etc/hosts pointing to 127.0.0.1 and it should work.

You can create a seperate host and apache entry for every site, so you are able to develop on more site.

(remove space before < , needed to add it to be able to post)
hope this helps :)

more info:
http://stringfoo.com/2007/11/07/mamp-setup-leopard/

Anonymous said...

Oh Man! You turned out to be the real hero in the end. I've been trying to get Symfony dance with both debuggers (zend/xdebugger) since yesterday 8:00 pm ...atlast after 11:00 am i found one last stop for all my needs! Thanks buddy

Anonymous said...

Hi, I do quite a bit of PHP development (See www.megabuy.com.au) and decided I needed a decent PHP IDE with debugging capabilities. Very glad i found your website. After playing around a bit I found that as long as you setup the Path Mappings correctly (it's a tab when you edit your PHP Server) it all seems to work pretty nicely and i didn't get any issues at all!

Anonymous said...

I had been trying to resolve an issue with Zend Debugger on Vista x64 of Eclipse not stopping at the breakpoints. All the other issues about project root and document root were all fine. In fact the exact same project/directory structure were working fine on a prior Win XP machine.
Finally figured it out - when I ran php -v, it gave me a parse error in the php.ini file. It turns out that Vista is a bit more strict on the directory separator. viz. zend_extension_ts="c:\Program Files (x86)\php\ext\ZendDebugger.dll" will work on Vista but zend_extension_ts="c:/Program Files (x86)/php/ext/ZendDebugger.dll" does not. But this will work with Win XP. Wasted a few days on this.

Anonymous said...

man i am still having problems with this issue. i have tried everything said here like:

pointed apache to wamp/www/workspace/project

and had my test.php file in project/test.php location

set the debug configuration appropriately etc and still its skipping breakpoints i have spend like a day but no luck so far. anybody please help.

Anonymous said...

I think I managed it to do it in yet another way. I run a local Apache server under C:/. I don't want my project files in the same folder as my web files so I created a project folder under My Documents. In the project I added external folders (the apache folder with the web files). These folders are now accessible for in the configuration of the custum debug profile you need to set up.

MH IT SOLUTIONS said...

Thanks for the information

Jean Kitchen said...

Thank you so much for documenting this and saving me some headscratching Very useful, including all the comments It sounds like I have this problem. I do not want to hack source, but I certainly don't serve my files from the doc root. I've been fidgeting with PDT and this damn debugger all day. When I finally got it to set break points it breezed right over all of them. I'm just having a hard time remembering which menus these configgy thingies live under and whether it's the server or the client (since both are the same.) Life was so much simpler with the CLI and text config files.

Abbas Gadhia said...

ok. i had somewhat of a similar problem, only in my case, i was unable to SET the debug point at all. As a nb to eclipse, i ate my head over what could have been wrong. In the end it turned out that i'm used to debugging on Intellij Idea and in there you have to SINGLE click to SET a debug point, and here you have to DOUBLE CLICK!!!!
DAMNNNNN.........how gullible can one get.....

Anonymous said...

Thank you! Really think that the guys at symfony should document this better than they do now.

However I have another problem regarding the debugging of symfony.

I get the following:

The route "start_debug=1&debug_host=127.0.0.1&send_sess_end=1&debug_session_id=1012&original_url=http%3A%2F%2Ftest.local%2Fweb%2Ffrontend_dev.php&debug_start_session=1&debug_no_cache=1293796940180&debug_port=10000" does not exist.

Seems to be some problem when the debugger adds info to the querystring..

Anyone had this problem?

Thanks
Christopher

Jay said...

Hi Yooper,

I have spent many hours on this, but still no luck. Please help:

My server location is :
DocumentRoot "C:/Users/jay/Documents/My Dropbox/MVCtest/"

Project root is same aswell.

Under PDT debug configuration i have:

PathMapping:
Path on server: http://localhost:78
Local path: C:/Users/jay/Documents/My Dropbox/MVCtest/



File: "/MVCtest/init.php"

URL is: "http://localhost:78/init.php"

Break at first like is selected.

Still no luck.

Please help:(

Jay

Jay said...

Ok I got it working with "run as script" but not as "run as web page"

Any suggestions would help.

Thanks.

jay

Nabha said...

Same problem, same cause, slightly different fix (I think).

Like others here, the problem was a file path issue. In the Debug Configurations -> PHP Server -> Configure... area, I had the path mapping set up wrong.

Path on server should be "/", not "http://localhost/" or whatever.

Good luck with your fix!

UV said...

mmh now reading this it seems the world turned around.... ;)
looks like someone tried to fix it and create the opposite bug.

I have eclipse Indigo with PDT 3.0.2
and there seem to be a funny bug with mapping to project root now!

The debugger is working in general, but the URLs generated for the internal webbrowser to send the request include the project NAME into the URL so they dont work.
I have to manually remove the project NAME and then everything works fine.

I tried mapping / on server to local path in filesystem or workspace with the same effects.
Entering a functional URL into the file field of the Server tab in the Debug Configurations is not permitted and thus not saved.