Eclipse and PHP

After installing LAMP, lets configure Eclipse for PHP development.

1. Install Eclipse

Download Eclipse latest version, from here. You just need the Eclipse Standard version (if you only want to develop PHP Web Applications). At the time of writing this post the latest Eclipse version is Luna. Once downloaded, start it up. If you try to create a new project, you will see that only Java projects are available. Now, lets enable PHP projects.

2. Enable PHP in Eclipse

In Eclipse, go to the “Help” menu, then “Install New Software…“. On the “Work with:” input field, type this URL: This will display a list of different tools to install. Under the “Programming Languages” category, you will find “PHP Development Tools (PDT)“, check it and click “Next” to follow the wizard to install it.

Restart Eclipse and once is up you will note that in the “Open Perspective” now you have PHP as an option. In addition, in the menu “Windows > Preferences”, you will see a set of PHP options too.

3. Enable User’s Home Directory

As PHP runs using Apache, you will need to create the project in a directory that Apache can see. There are many ways of doing this, but one I like is to use the {user.dir}/public_html that Apache supports pretty well and is accessible from a browser using http://localhost/~{user.dir}.

To enable this do the following:

  1. Go to the mods-enable directory in the Apache home directory, usually under /etc/apache2/mods-enable.
  2. Run the following commands:
    • sudo ln -s ../mods-available/userdir.load
    • sudo ln -s ../mods-available/userdir.conf
  3. Lastly, to enable the PHP interpreter under the {user.dir} directory, edit the /etc/apache2/mods-enabled/php5.conf file and comment out, using #, the lines below:
    • <IfModule mod_userdir.c>
      <Directory /home/*/public_html>
      php_admin_flag engine Off
  4. restart apache: sudo service apache2 restart

4. Set up a PHP Project
On Eclipse go to File->New->PHP Project. A “New PHP Project” window will open. On the Contents section, choose the radio button that says: “Create Project at Existing Location (from existing source)”. In the Directory input choose your {home_directory}/public_html/{project_name}, and press finish. An you are done. To test it, just create a PHP file, called test.php, like this:

<?php echo "<b>Hello World!</b>";?>

save it, and in the browser go to the following URL: http://localhost/~{user_name}/{project_name}/test.php. If you see “Hello World!” in bold, then you are done!.

Posted in Dev&Ops Tagged with: ,