Generally whenever doing any sort of development I like to work within an IDE with an integrated debugger, sure you can get away with a text editor but I like to make things easier for myself (as you may have noticed by now).

My favourite IDE for Java development is eclipse which supports development in many different languages either out of the box or via plugins (and it’s free 🙂 ), we’re going to have a shot at using eclipse for PHP development as well which should be fun.

We’ll also be doing all of our Java development in Eclipse, coming in a later post…


Step 1: Install eclipse

In a bold move I’ll be eschewing my beloved package manager here as the packages in the Ubuntu repositories tend to be a few releases behind the current release.

Eclipse runs entirely from it’s own directory so you can just download the zipped file from and extract to the location of your choice (the same applies for the Windows version). I downloaded the “Eclipse IDE for Java Developers”, the EE edition should also be fine. I extracted the tar to a directory under my home directory called devTools but it doesn’t matter where you put it.

Step 2: Install the PHP Development Tools (PDT) plugin

From Eclipse go to Help->Install New Software

Select the appropriate URL for your Eclipse release in the ‘Work With’ text box (for me it is

In the package select tree select Programming Languages->PHP Development Tools (PDT).

We can now create php projects and files but in order to be able to debug our code we need to install a debugger

Step 3: Install a debugger for PHP

We’re going to be using XDebug as our debugger, another option would be to use Zend

This may seem slightly involved if you’re not familiar with building packages from source in Linux but if you follow the steps on the following web pages it’s really not too difficult, stick with it.

Two packages you’ll need to install using the package manager:

php5-cli Command line interpreter, Eclipse uses this to run/debug CLI applications.

php5-dev Provides phpize, required to build the debugger.

Start off with this wiki:

Download and compile XDebug

Use the wizard on this page to get tailored installation instructions (it’s rather clever).

A quick way to test the installation is to run the wizard again.

You’re already running the latest Xdebug version

Make sure to add the lines:

zend_extension = /usr/lib/php5/20121212/
xdebug.remote_enable = 1

to your ini file.
in my case, /etc/php5/cli/php.ini
Note: this is the ini file for the cli executable I’ll be using in Eclipse, apache uses a different initialisation script /etc/php5/apache2/php.ini on my machine, so in order to debug a php in a running apache instance this file will need to be edited in the same way (note: phpinfo() will tell you which php.ini file that particular instance in using).

Now in Eclipse we can go to Window->Preferences->PHP->PHP Executables and setup our PHP environment.

In my case the executable path is /usr/bin/php

The ini file is /etc/php5/cli/php.ini

And set the debugger to XDebug

Once this is installed we’ll test the installation by running a simple PHP script from Eclipse.

Create PHP Project in Eclipse:

File->New->Other->PHP->PHP Project

Add a new PHP file, we’ll use exactly the same code as we used before to test our PHP installation.


Save then right click on this file in the package explorer, select; Debug As->PHP CLI Application.

By default this will switch Eclipse to the debug perspective (I don’t like switching perspectives every time I start a debug session, I find the context switch jarring so I set it not to do this), start debugging and break at the first line, press F8 to continue and a load of PHP info should be printed to the console.

We have our PHP development environment running!

Next time we’ll put together what we have so far to create a MySQL database and write some PHP to write and retrieve information to/from our database.

Next page: Database design and querying from PHP

Back to: Setting up the dev/test environment – Part one


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: