Developing with PHP and Eclipse (Helios)
Written by Ian Elliot   
Thursday, 24 June 2010
Article Index
Developing with PHP and Eclipse (Helios)
Importing the site
Running and debugging

A first run

To try things out load index.php, or any PHP file that creates a complete web page, into the editor - simply double click on the file in the Project tree.

Next select Run,As PHP Web page and you will see a potential problem. The launch dialog indicates that it is going to use the local web server "localhost". This is fine if you set the development site up this way, but if you installed the web server on the remote machine it isn't going to work.

You could now install the same web server on the local machine and reconfigure everything, but it's easier to change the default server. Select Windows,Preferences and navigate to PHP Servers. Select the Default PHP Web Server and click on Edit. Change the URL to the remote machine.

(Notice that there is also a Project,Properties dialog which sets a range of seemingly similar features and often seems to be confused with Preferences.)

 

Banner

 

When you try to run the index.php file you should discover that the correct launch URL, i.e. the one you would type into a browser to access the page, is shown in the dialog box. If it isn't simply type the changes needed into the box and continue. You should see the web page appear in a tabbed window within the Workbench. You can now click links and use it as normal viewing the pages in the Workbench browser.

A run configuration has now been created for the page index.php and the initial URL will be correct when ever you run the page in the future. You can view and edit the configuration using Run,Configurations. Don't try anything more complicated until you have got the web site running well enough to see a page displayed in the browser.

 

run

A first run

Debugging

You already have a system that makes editing the website much easier but the real payoff comes when you also have a debugger running. To achieve this you need the Zend debugger which is often included with PHP installations. If it isn't then you can download a standalone copy from:

http://downloads.zend.com/pdt/

The files that you require are in the server-debugger directory and are called something like

ZendDebugger-version-type

Next you need to extract the appropriate dll (Windows) or SO (Linux) and the correct version depending on the version of PHP you are running (the compressed file contains a range of versions). 

A readme file is included and a test file called dummy.php. All you have to do is copy the dll or SO to a directory within the PHP installation (again it can be anywhere but this is convenient).

The included readme file says:

Zend Debugger installation instructions

  1. Extract the Zend Debugger package.
  2. Locate the ZendDebugger.so (Unix) or ZendDebugger.dll (Windows) file in the directory which corresponds to your version of PHP (4.3.x, 4.4.x, 5.0.x, 5.1.x, 5.2.x).
  3. Add the following line to your php.ini file:
    Linux and Mac OS X:     zend_extension=<full_path_to_ZendDebugger.so>
    Windows:       zend_extension_ts=<full_path_to_ZendDebugger.dll>
    Windows non-thread safe: zend_extension=<full_path_to_ZendDebugger.dll>
    (*) The Windows non-thread safe binary is only used with Zend Core 2.0.
  4. Add the following lines to your php.ini file: zend_debugger.allow_hosts=<host_ip_addresses> zend_debugger.expose_remotely=always
    (*) hopst_ip_addresses are the IPs of the hosts which will be allowed to initiate debug sessions
  5. Copy the dummy.php file to your document root directory.
  6. Restart your Web server.

 

So for example tell PHP where the debugger for the remote Linux server used for this example you have to edit the php.ini file to read:

zend_extension=/etc/php5/ZendDebugger.so
zend_debugger.allow_hosts=192.168.253.59
zend_debugger.expose_remotely=always
zend_debugger.connector_port = 10013

You need to modify the lines to reflect where the dll or SO is stored and to give the IP address of the machine running Eclipse. You can modify the connector port to be anything you choose but also make sure you have opened it in the Eclipse machine's firewall - if you don't you will see the "can't connect to server" message. If you are installing a local debug system you don't need the final three lines.

Finally you need to copy dummy.php to the root of the website, usually the same directory as index.php, and restart the web server.

Of course if you are using a remote web server as a development system you need to do all of this on the server. It's also a good idea to restart Eclipse. If everything is ok you should be able to load the index.php file, open the Debug configuration dialog box and click Test Debugger.

You should see an OK message - if not then either you haven't copied the dummy.php into the server's root, you haven't copied the dll or SO into the correct directory or you have made a mistake in the php.ini file. For a remote debug you also might not have opened the port in the firewall.

These are the only possibilities.

If you do see OK then click Debug and you should find that a debug perspective opens and you can single-step through the PHP code. If you complete the PHP code then you will see both the output of the PHP in the Debug window on the far right and the results in the browser, either in a new tab or in the browser window at the far right.

You are now ready to experiment with debugging Joomla.

Some common questions that are worth answering before they are asked are:

1) You can set breakpoints both in the code that makes the page you start with and in any pages that are reached by following links from it.

2) You can see the output from the PHP in the Debug window.

3) The browser used as the "internal browser" is an instance of the default browser on the machine that Eclipse is installed on.

Any more questions? Email me:Ian.Elliot@i-programmer.info

<ASIN:1847192823>

<ASIN:0470133945>

<ASIN:0596523203>

Banner


PHP Inner Functions And Closure

PHP inner functions and anonymous functions are a little strange to say the least. However, just because something is strange doesn't mean that it isn't useful. We take a close look at the way PHP fun [ ... ]



Ten Minutes to PHP

Want to get started with PHP but never found the time? Now you can write your first program in around ten minutes and understand where to go next.


Other Articles



Last Updated ( Monday, 30 January 2012 )