Search This Blog


Saturday, February 28, 2009

How to Debug a PHP file as WebPage using Zend Studio for Eclipse

Recently I dubbed into PHP development, and have chosen Zend Studio for Eclipse as my development platform.  Eclipse is so different than Visual Studio in terms of usability that I have to spend some time in familiarizing myself with the tool. I had some difficulties in even setting up a simple Eclipse project . So to help other people, I wrote a post on how to do just that.

Now, this is a post on how to debug a PHP file. It doesn't take a genius to figure out what's the latest problem I had run into.

Here are the steps on how to debug a PHP file as a webpage using Zend Studio for Eclipse
  1. Download and install Zend Studio for Eclipse , of course. 
  2. Download Zend Core . Install it on your web server. So if you are using your own machine as the server, then install it on your machine. If you want to do remote debugging, you have to install it on the real server. 
  3. Create a new project, name it as WebPageGo, choose the default workspace for Eclipse.
  4. Put in a dummy.php in your  htdocs folder ("C:\Program Files\Apache Software Foundation\Apache2.2\htdocs"). 
  5. In the Conf\Extra folder ("C:\Program Files\Apache Software Foundation\Apache2.2\conf\extra"), Create a new configure file StupidWorkPlace.conf. Type in the following content:

    NameVirtualHost *:80
        DocumentRoot "C:\Documents and Settings\%YourUsername%\Zend\workspaces\DefaultWorkspace"
        DirectoryIndex index.html index.php
           AddDefaultCharset UTF-8
           AllowOverRide none
           Options FollowSymlinks
           Order allow,deny
           Allow from all
  6. In your httpd.conf file, type in

    Include conf/extra/StupidWorkPlace.conf;
  7. Create a a PHP script call DoesItMatter.php ( don't ask me what's the reason behind this name). Put it under the WebPageGo workspace.
  8. Type In the following scripts:

    Hello word
    echo "I want to debug";
  9. Choose Debug As->PHP Web Page, but before that set a breakpoint at the echo statement.

  10. And voila! You can now step into the web page for debugging!
Note that you must install Zend Core on your webserver, or else you can't debug, even if your webserver is located on your development machine. If you don't have Zend Core, you can still debug as PHP script, but you can't debug as PHP webpage, as the breakpoint won't be hit.


knyto2 said...

this worked for me. thanks a bunch!

nil_von_9wo said...

This didn't work for me. Maybe its because my environment is configured slightly different and I'm compensating incorrectly?

I have Zend Server listening to port 59090.

My workspace is "D:\Brian Stuff\Education\PHP"

This is the StupidWorkPace.conf file that I created:

NameVirtualHost *:59090
>virtualhost *:59090=""<
DocumentRoot "D:\Brian Stuff\Education\PHP"
DirectoryIndex index.html index.php
>directory d:\brian="" stuff\education\php="" <
AddDefaultCharset UTF-8
AllowOverRide none
Options FollowSymlinks
Order allow,deny
Allow from all

I added Include conf/extra/StupidWorkPlace.conf; to line 424 of httpd.conf (after all the commented out includes).

However, my result now is no different than before I tried to fix this.

Any idea(s) what I am doing wrong?

nil_von_9wo said...

oops... I mixed up the greater and less than signs in my last comment... they are correct in my code, so don't worry about correcting that.



nil_von_9wo said...

After rebooting the computer, without removing the include, I can't get Apache to start.

I ran httpd.exe -t from the cmdline and this was the result:

[Sun Sep 13 13:44:53 2009] [error] (OS 11001)No such host is known. : Could not resolve host name *:59090="" -- ignoring!
Syntax error on line 5 of C:/devtool/Zend/Apache2/conf/extra/stupidworkplace.conf:
&lr;Directory "d:\\brian="""&gr; path is invalid.

Just to see what would happen, I copied your exact text into my conf file, and instead I got this result:

[Sun Sep 13 13:50:45 2009] [error] (OS 11001)No such host is known. : Could not resolve host name *:80="" -- ignoring!
Warning: DocumentRoot [C:/Documents and Settings/%YourUsername%/Zend/workspaces/DefaultWorkspace] does not exist
Syntax error on line 18 of C:/devtool/Zend/Apache2/conf/extra/stupidworkplace.conf:
&lr;Directory "c:\\documents="""&gr; path is invalid.

... any idea why this is insisting my paths are invalid? Or why http.exe is describing these paths with extra quotes and slashes that are not in the conf file? The paths are most certainly there and the conf file, has no more slashes nor quotes than yours.

Anonymous said...

Helpful article...