DBG and PHPEclipse


This guide will focus on using the DBG Debugger with PHPEclipse. It will cover the dbg config file for the server (apache), setting up a DBG profile in PHPEclipse and starting your debug session. The installation of DBG on the server is outside of the scope of this document. Please refer to the DBG website for guidance on installing DBG on your server. This guide was written using CentOs 5 as it's example server. Your system may be different. If so please open a ticket and mention the change. This guide will be updated to reflect changes for different platforms.

Special Note:
Before you begin insure that you have only the DBG plugin from the PHPEclipse update site installed. You can go to Help->Software Updates -> Manage Configuration to check for XDebug plugin. If it is installed, just disable it. The two debugging tools not working well together is a known issue in the 1.2.0 release of PHPEclipse.

Special Note 2:
As of PHPEclipse 1.2.x trying to debug an RSE project will not work. The src needs to be on local disk, or a mapped nfs mount/ smb directory.

Project Paths

Getting the paths to work is a big issue with Eclipse and Debugging. I am going to try to make this as clear as possible. First we have our apache website path. Our apache config may look something like this

<VirtualHost *:80>
    ServerAdmin ed_mann@dont_spam_me.ok
    DocumentRoot /home/ed_mann/dev30
    ErrorLog logs/dev30-error.log
    CustomLog logs/dev30-access.log common

From above we can find that our Remote Src path is the DocumentRoot which is set to /home/ed_mann/dev30.
Remote Path = /home/ed_mann/dev30 You will need to replace that Remote Path with the path you get from your Apache conf file, or your virtual host configuration.

Now on our local machine where we are running Eclipse our workspace is in
and the project is called dev30
So our total local path would be
local path = /home/ed_mann/workspace/dev30

Please change this to your workspace and project name path. We will be using this information later. So keep it in mind or write it down.
Notice how our apache path does not have workspace, but our local path does. That is ok. The server that is hosting the files stores it in the ed_mann directory, but you can use a nfs/smb/fuse export to mount the files into /home/ed_mann/workspace. So if the paths are not the same it's ok. Eclipse only needs to know where on each end is the source files.

DBG config

Your server may have a /etc/php.d directory with extra configuration options in it for php. If not you will need to add the following code to your php.ini file. If you have a php.d directory create a new file in that directory named dbg.ini and add the following code:
debugger.enabled = true
debugger.profiler_enabled = true
debugger.JIT_host = clienthost
debugger.JIT_port = 10001

Once the code is added restart Apache. Create a php file in your document root for the website you can call it whatever you want we will use info.php in this document. Add the following code to the info.php file.

 print (phpinfo());

When you have done this, now with your browser type in the url address to get to this page. Example http://localhost/info.php
Look for the section that resembles the image below
dbg php info
If you do not see DBG in the section like above check your settings, make any needed changes and restart apache.

debugger.JIT_host = clienthost

Note that the DBG debugger currently relies on the PHP variable HTTP_SERVER_VARS to determine the IP address of your debug session. By default CentOS 5 disables this variable, so you will find remote debugging does not work. You need to add the directive

register_long_arrays On

to php.ini for remote debugging to work.

Test Project

Once you have DBG installed into php on the server you can now configure DBG in Eclipse. Start Eclipse and activate the PHPEclipse perspective if it is not already. You will need to import a project to use from your webserver or create a new project on the web server. Configuring the web server for projects is out of the scope for this document that exercise is left up to the reader. Once you have your project established create a new file called dbg.php.
Starting of simple we will just add the following to the dbg.php file.

 print("DBG Test");

Now with your browser connect to the page with your browser Example: http://localhost/My_Project/dbg.php.
Once you have done this and verified that the text appears you are ready to configure a DBG Profile and our debug script.

Debugging Script

You should have verified your environment is setup to debug using the steps above. Now we need to write some code that will allow us to test debugging our php script. In our dbg.php file we are going to remove the print("DBG Test"); statement with a little loop that will allow us to step into the code.

for ($i =1; $i <= 10; $i++){
  print (" we are at ". $i. "<br />");

On the line that starts our for loop toggle a breakpoint. You can do this by right-clicking in the gutter and selecting Toggle Breakpoint
dbg debug toggle breakpoint

You should see a blue dot appear to signify where the breakpoint is. Now change to the Debug Perspective. Window->Open Perspective -> Debug
Now we can configure our DBG Debug Profile. We will only need to do this once per project.

DBG Debug Profile

In Eclipse click on the debug icon in the top navigation bar. Select Open Debug Dialog
open debug dialog

You should get the Debug Dialog Window. We will create a new PHP DBG Script by double clicking on the PHP DBG Script list entry.

dbg debug dialog

The file page that it defaults to when you create a new configuration should not need any changes. Just edit the configuration name to something more meaningful to you. Click on the Environment tab with the PHP icon and we will make our needed changes.

  1. Select Remote Debug
  2. Select the browser that you want to use. If you are going to use the internal PHPEclipse browser just select Open with DBGSession URL in internal Browser. If you want to use external browser select Open with DEBSession URL in internal Browser and then also select Use external Web browser as well. There is a ticket open to have the way these options work changed.
  3. Set your remote Sourcepath to the remote path that you determined was correct for your environment when you read the section earlier on Project Paths.
  4. Click Add in the Mapped Path section to add map path for our local and remote paths.
    1. Local path is the path that is to your workspace + project See Project paths from above.
    2. Remote Path is the remote path that you get from apache configuration or VirtualHost config.

dbg debug evo config

dbg debug map path

Once you have these items configured you just need to apply them and you are ready to debug. Click the Debug button, You should have already set breakpoints and activated the Debug Perspective.
Your browser should then get the URL set and the debugger should connect to the Eclipse Debug session. The script should start executing but stop at our breakpoint. You should be able to step into the for loop.

Last modified 8 years ago Last modified on Oct 23, 2008 5:43:16 PM

Attachments (6)

Download all attachments as: .zip