Get started with PHP in Eclipse

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. We will not discuss XDebug because, at the time of writing, attempts to get XDebug up-and-running ended in nothing but frustration.

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:

  1. Start or restart the Eclipse IDE.
  2. Create a new PHP Project in Eclipse.
    Note: Eclipse may default the project contents to the local Zend server. This can be changed if desired so that projects are consolidated in a single workspace.
  3. Open project Properties dialog and enable project specific settings from the PHP Debug panel.
  4. If not already selected, choose Zend Debugger as the PHP Debugger and set the Base Path to “/”, the local root.
    Note: Zend CE restricts users from hosting multiple PHP projects simultaneously.
  5. 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. The Launch URL should be something like http://localhost/index.php. If the Launch 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 Eclipse 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 is now available.

Push Upstream with EGit and Eclipse Indigo

While working through the EGit User Guide I ran into difficulty pushing files upstream using Eclipse Indigo SR1 (build 20110916-0149). The difficulties manifested themselves at first with an “auth failed” error, which was quickly resolved with a visit to Stack Overflow. But after fixing that problem I began seeing the following error while trying to push to a remote repo:

Cannot get remote repository refs.
Reason:
ssh://git@github.com:22: Passphrase for C:\Users\...\.ssh\id_rsa

Initial research indicated that Eclipse/EGit SSH authentication has problems. So I just kept messing around until I was able to get things working. After a little Googling and even more fiddling I found two solutions:

Simple fix that skips the passphrase and uses only Eclipse

  1. Use ssh-keygen from Git Bash, or Eclipse, to generate an RSA key, but do so without setting a passphrase.
  2. Open and copy the public key from ~/.ssh/id_rsa.pub and add it to GitHub via the SSH Public Keys section in Account Settings.
  3. Restart Eclipse. (Note: Not doing this was tripping me up for a while.)
  4. Try the Push Upstream steps again from the EGit User Guide.

The obvious pitfall here is that a passphrase cannot be associated with the RSA key. If skipping the passphrase is out of the question the following solution a little more up your alley.

Use PuTTY for file transfers over SSH from within Eclipse

  1. Download the following PuTTY binaries: Plink, Pageant and PuTTYgen.
  2. Use PuTTYgen to generate a new public/private key pair with a passphrase. Open and copy the public key from ~/.ssh/id_rsa.pub and add it to GitHub via the SSH Public Keys section in Account Settings. Save the private key file in your ~/.ssh directory for later.
  3. Run Pageant and add the key created during the last step, entering the passhprase when prompted. Leave this utility running.
  4. Cache the server’s host key in the registry by:
    1. From a bash prompt like Git Bash execute the following command (assumes Plink binary is accessible from the current path): plink git@github.com
    2. Verify the RSA key fingerprint matches GitHub’s and, if they match, choose to store the key in the registry.
  5. Add a new environment variable called GIT_SSH and point it to the downloaded Plink binary (e.g. “C:\Windows\system32\plink.exe”). EGit will attempt to use this binary for SSH, if configured.
  6. Restart Eclipse, ensuring Pageant is still running with the private key available.
  7. Try the Push Upstream steps again from the EGit User Guide.

If done correctly, Eclipse should allow pushes to the remote repo without any further configuration, though Pageant must be running with the private key configured for it to work correctly. If problems continue see the SSH issues in the GitHub help documentation for additional information. Good luck!

Get sideways with HTML5 in Eclipse

Featured

There are few front-end web developers I know who actually use the Eclipse editor for development. Whether it’s the complexity of the IDE or simply resistance to change I cannot say. Working with Eclipse on enterprise apps has some serious advantages when it comes to working in multidisciplinary teams. And wrenching on a UI is no exception.

Continue reading