Eclipse is a powerful IDE supporting many different languages, including PHP. Unfortunately, many Eclipse installations do not provide PHP language support right out of the box—some assembly required. This article will focus on getting Eclipse set-up for PHP development and local debugging.
To get started, first download and install the PDT plug-in for Eclipse. PDT installation instructions are available on Eclipsepedia. Once installed, a PHP perspective will become available, providing PHP syntax highlighting and code completion, as well as the ability to create PHP project types. The basics are now in place for developing PHP applications, save for local debugging.
Debugging PHP apps locally requires users to install a separate debugging tool. Two currently available PHP debugging solutions include XDebug and Zend. We will focus on getting set-up using Zend as it is relatively easy to install and use.
To use Zend for PHP debugging first download and install PHP, if not already available, which is required for Zend to work properly. With PHP installed, download and install Zend Server CE, the free community edition. When the server is running return to Eclipse to configure it to use Zend:
- Start or restart the Eclipse.
Create a new PHP Project from within the IDE.Tip: Eclipse can default projects to the local Zend server. This setting may be adjusted to consolidate projects into a single workspace.
Open project Properties dialog and enable project specific settings from the PHP Debug panel.
If not already selected, choose Zend Debugger as the PHP Debugger and set the Base Path to
/, the local root.Tip: Zend CE restricts users from hosting multiple PHP projects simultaneously.
Choose OK to save settings and close the Properties dialog.
With Zend installed and Eclipse configured it should now possible to debug PHP on the localhost. To do so create a simple PHP file of the hello world variety, select it in the PHP Explorer (visible from the PHP Perspective), press F11 or choose Debug As… and select PHP Web Page from the Debug As dialog.
http://localhost/index.php. If the URL includes the project name, Zend debugging may not function as expected.
Once debugging is started the browser will open as well as the Debug perspective in Eclipse. The Debug perspective will be stopped on the first PHP instruction encountered and ready for debugging.
Press F8 to resume processing and then switch back to the PHP Perspective. Local PHP debugging should now be available within Eclipse IDE.