Eclipse as Symfony2 IDE

In this post I will explain how to turn Eclipse in a full-featured IDE for Symfony2. The other popular MVC framework (Zend) has Zend Studio as an full-featured IDE. Zend Studio is based on Eclipse and we will show in this post how you can turn a standard Eclipse into a full-featured IDE for Symfony2. First you need to install Eclipse. It can be installed from the standard repositories in Ubuntu 12.04. A simple “sudo apt-get install eclipse” will do. Although everybody says you need Oracle Java to run Eclipse with PDT, I have no problems running it under OpenJDK. If you download the latest Eclipse from the download page, choose the “Classic” distribution.

After installing and starting Eclipse, you should install the MarketPlace. Newer distributions of Eclipse come with MarketPlace installed. You can find “Eclipse MarketPlace” under the “Help” menu. This is a software manager for Eclipse that is fast and easy to use. If you do not have it, install it by going to: “Help” > “Install new software” > “All available sites” > type “marketplace” > “Select All” > “Next” > “Finish”.

Now that MarketPlace is installed we can “shop” for some nice additions to Eclipse to make it a full featured Symfony2 IDE. The following packages should be acquired:

  • “EGit” and/or “Subversive” for Git and SVN support
  • “AnyEdit Tools” for proper whitespace handling and tab conversions
  • “PTI – PHP Tool Integration” for support of
    • CodeSniffer
    • PHP Copy Paste Detector
    • PHP Depend
    • PHPUnit
  • “Symfony Plugin” for supports of the Symfony 2.1 composer and twig templates
  • “DBViewer” plugin for database setup and queries from within Eclipse

Now you also need to install the CodeSniffer standards:

sudo apt-get install php-codesniffer
cd /usr/share/php/PHP/CodeSniffer/Standards
sudo git clone git:// Symfony2
sudo nano Symfony2/ruleset.xml

Remove the last 3 rules that start with “<rule ref=”Symfony2.Commenting” and end with “</rule>”, because somehow those dont work.

You will also have to configure some of the tools from within Eclipse before they work:

  • Subversive: After restart Choose the SVNKit version that matches the output of “svn –version” (e.g. choose SVNKit 1.3.8 for SVN 1.6.18).
  • PHP executable: Add a PHP executable for path “/usr/bin/php” choose “CLI” and “XDebug”. NB: if this fails remove the “/tmp/zend_debug/” directory if it exists.
  • PHP Tools: All pages need to point to the added PHP executable and the internal PEAR library. You also need to set the Symfony2 code style: Go to “Window” > “Preferences” > “PHP” > “Code Style” > “Formatter (PDT Tools)” and choose as “Active profile”: “Symfony [built-in]”.
  • PHP CodeSniffer: You need to set Tab width to “4” and you should add and select the Symfony2 CodeSniffer Standard (path “/usr/share/php/PHP/CodeSniffer/Standards/Symfony2”).
  • DBViewer: You need to add the path to the file “/usr/share/java/mysql-connector-java.jar” which can be installed using “sudo apt-get install libmysql-java”

NB: If you run into “The currently displayed page contains invalid values.” when trying to configure the PHP executable, you might want to run “sudo chmod -R 777 /tmp/zend_debug/”.

That’s it, enjoy your full-featured Symfony2 IDE!


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:
$ 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:
  $test = 'test';
  echo $test;
$ nano .gitignore
  NB: Insert the following text:
$ 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 ""
  NB: 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.