Free PHP IDE with PDT for Eclipse

Eclipse is an¬†integrated development environment (IDE) with an extensible¬†plug-in system. Most people know it as a tool to develop Java applications, but if you install plug-ins you can use it to do PHP development. There are a lot of Eclipse based IDE’s (source: wikipedia). Three IDE’s that are based on Eclipse you might know are:

Now I hear you think: “I like to develop my PHP code in gedit“. Well that is a very good choice and so is “using vim for PHP“. And if you download and install Eclipse you might get disappointed by the (lack of) features it offers out of the box. I have to admit that you either need proper instructions and/or an (un)healthy dose of perseverance to get to satisfying results.

But once you have gone that extra mile and seen how stable and fast it is (when run under Linux) I doubt you ever want to go back. At least to me the step-by-step debugger (from PDT and Xdebug) and version control support from either subversive (SVN based on SVNKit) or Egit (for GIT) are indispensable.

Without further ado, here are the instructions for a perfect Eclipse installation on Linux (tested on Ubuntu 12.04):

$ sudo apt-get install lamp-server^
- Enter a new mysql root password (twice)
$ sudo apt-get install php-pear
$ sudo pecl install xdebug
$ nano /etc/php5/apache2/conf.d/xdebug.ini
  NB: Insert the following text:
  zend_extension=/usr/lib/php5/20090626/xdebug.so
  xdebug.remote_enable=1
  xdebug.remote_handler=dbgp
  xdebug.remote_mode=req
  xdebug.remote_host=127.0.0.1
  xdebug.remote_port=9000
$ sudo service apache2 restart
$ sudo apt-get install git
$ sudo chown -R `whoami`:`whoami` /var/www
  NB: whoami should be surrounded by backticks
$ cd /var/www
$ nano test.php
  NB: Enter the following text:
  <?php
  $test = 'test';
  echo $test;
$ nano .gitignore
  NB: Insert the following text:
  .buildpath
  .project
  .settings
$ git init .
$ git add .
$ sudo apt-get install eclipse
  NB: 245 MB will be downloaded and it uses 418 MB of diskspace
- Start Applications > Development > Eclipse
- When asked for workspace settings click "do not ask this again"
- Close the "Welcome" page
- Click Help > Install new Software
- Choose "Work with": --All Available Sites--
- Enter in "type filter text": PHP
- Wait..
- Select: PHP Development Tools (PDT)
- Click Next
- Click Next
- Click I Accept
- Click Finish
- Wait..
- Click "Restart Now"
- Close the "Welcome" page
- Click Help > Install new Software
- Choose "Work with": --All Available Sites--
- Enter in "type filter text": egit
- Wait..
- Select: Eclipse EGit
- Click Next
- Click Next
- Click I Accept
- Click Finish
- Wait..
- Click "Restart Now"
- Close the "Welcome" page
- Click File > New > Project
- Choose: PHP > PHP Project
- Click Next
- Enter "Project name": "test"
- Choose "Create project from existing sources"
- Enter Directory: "/var/www"
- Click "Finish"
- When asked to change perspective choose "Yes"
- Choose Window > Preferences
- Choose: General > Web Browser
- Select: "Use external web browser"
- Choose: PHP > Debug
- Choose "PHP Debugger": "XDebug"
- Unselect "Break at first line"
- Click Ok
- Open the PHP file "test.php" from your project
- Doubleclick linenumber 2 to put a breakpoint (blue dot)
- Choose Run > Debug
- Change "Launch URL" from "http://localhost/test/test.php" to "http://127.0.0.1/test.php"
  NB: 127.0.0.1 works, localhost does not work!
- When asked to change perspective choose "Yes"
  NB: Once you are in the debug perspective a browser opens,
      you can inspect variables and step-by-step execute.
- Choose Window > Open Perspective > PHP
- Right-click your project
- Choose Team > Share Project
- Select Git
- Click Next
- Select "Use or create repository in parent folder of project"
- Click Finish
- Right-click your test.php file
- Choose Team > Commit
- Enter your username and email address and click Ok
- Type a commit message
- Click Commit
  NB: You have commited to a local repository,
      how to push git commits remote is beyond this tutorial.
- Close Eclipse

If you feel Eclipse does not start quick enough, you might try these optimizations. I noticed some speed improvements after applying them, but note that your mileage may vary.

Share