Sunday, September 13, 2009

PHP and Eclipse

This post is because I'm starting to program using PHP and I found no easy documentation explaining how to integrate PHP and Eclipse. I tried PDT (hated it) and Aptana and none of them actually solved my problem that was: an IDE with text highlight and a debugger. Aptana is rather confusing (I couldn't figure it out how to start a server and connect my php to it) and PDT is kind of messy.

The best I could find was a reference at Drupal documentation: The link is This was an almost complete documentation and helped me to get the job done.

First of all, the PHPEclipse editor is the best. It actually highlights PHP files, even though they do not possess a ".php" extension. (The other editors just cann't tackle this fairly easy task.) And it is really easy to debug your code (there is a catch nonetheless) and start playing around. For this documentation I will not repeat things that are already documented, so you will need to have the documentation below opened:

1. Get Eclipse Galileo (the version that I have and in which this documentation is based on) at:

2. Install Subclipse plugin (for SVN):

Eclipse update site:

3. Install PHPEclipse plugin:

Eclipse update site:

3.1. It is VERY important that you disable the DBG plugin. See the "Special Note:" at

4. Install XDebug (not in Eclipse):

4.1. Get some additional packages:

yum -y install \

4.2. Get XDebug source, configure, compile and install it:

cd /tmp
tar -vxzf xdebug-2.0.5.tgz
cd xdebug-2.0.5
./configure --enable-xdebug
mkdir -p /opt/xdebug-2.0.5
cp /tmp/xdebug-2.0.5/modules/ /opt/xdebug-2.0.5/

Note: It will be installed at /opt/xdebug-2.0.5/

4.2. Configure the XDebug for the PHP:

cat >> /etc/php.d/xdebug.ini << __END__
; Configuration taken from:
; for non threaded php (debug and inside eclipse)
; for threaded php (apache)
; zend_extension_ts="/opt/xdebug-2.0.5/"
; change it if you want to debug from another server/workstation

4.3. Configure your Apache to have an Alias to your workspace, but remember: you HAVE to give permission to the apache user to reach you workspace:

chmod o+r ${HOME}
chmod -R o+r ${HOME}/<your workspace>
echo "Alias /dev \"${HOME}/<your workspace>/<your php project name>\"" > /etc/httpd/conf.d/php-dev.conf
service httpd restart

5. Configure Eclipse to use XDebug:

Follow from "Test Project" section to the end.

Note: The URL for your project will be: http://localhost/dev/<your PHP file in your workspace>

Note2: When you launch a debug (in Eclipse) you have to switch to the Debug Perspective manually (that is the catch that I mentioned).

Note3: At the "pathmap" configuration (for the PHP XDebug Remote Script) you will use: /home/<your username>/<your workspace>/<your php project name> in both fields (this is due to the fact that you are running the http server locally and using an Alias).