How to install a cool PHP development environment on Linux
Cool means “official java version + eclipse + svn plugin + debugging + firefox extension for debugging”
In this article I use Linux Redhat and explain how to install
- Java version 6 update 1
- Eclipse 3.2.2 Build id: M20070212-1330
- PHPEclipse 1.1.9 CVS
- DBG 2.15.5
- SVN plugin Subclipse 1.2.2
on PHP 5.2.2 (but would work from PHP 4.3 to PHP 5.2)
1) Official Java version provided by sun
- Download Java on java.com
- Then some basic commands to install java
su
chmod +x jre-6u1-linux-i586-rpm.bin
./jre-6u1-linux-i586-rpm.bin
- once it’s installed you need to change the default GIV slow java virtual machine provided by linux so that the system uses the sun java. To do that I create a symlink to the sun java.
ln -s /usr/java/jre1.6.0_01/bin/java /usr/bin/java
- at this point executing “java” should give you the help from the official JAVA version. You shouldn’t see any “GIV” stuff.
java
2) Eclipse
- Download Eclipse 3.2
http://www.eclipse.org/downloads/
- Unpack the archive
- Execute eclipse by clicking on the eclipse/eclipse executable
3) PHPEclipse
- Download the latest CVS Version (the only one compatible with eclipse 3.2)
http://sourceforge.net/project/showfiles.php?group_id=57621
the release is phpeclipse-1.1.9-cvs-20060920
- To install a plugin in eclipse, it’s very easy: unpack the archive (plugins and features directory) in your eclipse directory
- Now you can create a PHP project in Eclipse
4) Install the PHP extension that allows debugging
- Download the extension on http://dd.cron.ru/dbg/downloads.php
In our case “DBG 2.15.5 dbg modules [152Kb] - May 1, 2007 gzip’d archieve contains pre-compiled dbg modules for php 4.3 up to 5.2.”
- unpack the archive and copy the good extension in your PHP modules directory, in my case “/usr/lib/php/modules/”
you can rename this extension to the more simple “dbg.so” so you now have the file “/usr/lib/php/modules/dbg.so”
- edit php.ini
vi /etc/php.ini
- add the following lines in the “Dynamic Extensions” section
extension=dbg.so
[debugger]
debugger.enabled=on
debugger.profiler_enabled=on
debugger.hosts_allow=localhost
debugger.hosts_deny=ALL
debugger.ports=10001
- restart apache
/etc/init.d/httpd restart # on redhat or /etc/init.d/apache2 restart on ubuntu
- check that DBG is installed
A <? phpinfo(); ?> gives you somewhere some DBG information : “Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies with DBG v2.15.5, (C) 2000,2007, by Dmitri Dmitrienko”
5) Setup the debugger in Eclipse
- Once the DBG php extension works, read that valuable page
http://www.plog4u.org/index.php/Using_PHPEclipse_:_Installation_:_Installing_the_DBG_Debugger
- at the end you should be able to debug a script as explained in the page. If your debugger doesn’t stop at breakpoint, but if it breaks at the function DebugBreak(); then check carefully the debug path settings
For the example my settings are:
I want to debug the page http://localhost/dev/openadssvn/trunk/tests/run.php
Here are some informations in the Debug options for my Test configuration
Debug > File > File, I have “trunk/lib/OA/Upgrade/DB_UpgradeAuditor.php” the name of the file currently opened and being debugged (but the debugger can of course switch to other files while debugging)
Debug > Arguments > Working Directory, I have “/home/matt/dev/openadssvn/trunk/tests/”
Debug > Environment > Remote Debug, I have Remote debug checked and the others unchecked ; the “Remote Sourcepath” is “/home/matt/dev/openadssvn/”
NB: final slashes after the Working Directory & Remote Debug seem to be very important.
NB2: Very important, “Remote Sourcepath” and the “File” should give you the absolute path to your php file that you want to debug. If this is not the case, then the debugger may not break on the breakpoints you have set. But it can still break if you add the function call DebugBreak(); when you want the debugger to break into your PHP code.
6) Firefox extension to make debug easy
- Install PHP Debugger 0.3 for Firefox : A php debugger for GDB
https://addons.mozilla.org/en-US/firefox/addon/3227
- Use it; launch the debugger on eclipse (port 10001 for example). While the debugger client in eclipse is waiting for a connection, in firefox click on PHPDebugger. That will create a cookie which I guess is read by the PHP GDB extension, which launches the connection. It is the same as if you visit your URL adding the parameter &DBGSESSID= 1@clienthost:10001
- When the debug is finished, click on the toolbar PHPDebugger > Kill debug session ; it will destroy the cookie and you can now execute your pages without triggering the debugger. Otherwise you will get the message “DBG - Failed to start debug session reason: failed to establish connection to client host on localhost:10001″.
Killing the debug session is the same as if you visit your URL adding the parameter &DBGSESSID=1
7) Installing the SVN Plugin in Eclipse
Installing a plugin is very easy in Eclipse. We will install Subclipse http://subclipse.tigris.org/.
To do that simply go to Help > Software and install > Find and install
Click Search for new features to Install > New remote site > and paste this URL http://subclipse.tigris.org/update_1.2.x
Then it’s very straightforward. At the end of the process, you can try the right click onto your project > Team > lots of SVN options.
It’s very easy to use and very timesaving for conflicts resolving, in my opinion. I have never been a fan of the command line version when it comes to conflicts, or to compare the current version with a previous release, etc. Here it’s very easy! It’s good if your SVN server is fast though.
8) Tips & tricks
- Increase Eclipse Performance
You can edit your eclipse/eclipse.ini settings.
For example on my 2GB ram machine, I have the following eclipse.ini:
-vmargs
-Xms512m
-Xmx512m
-XX:PermSize=256m
-XX:MaxPermSize=256m
See also http://www.eclipsezone.com/eclipse/forums/t61618.html
- Custom fonts in eclipse
Some fonts are not editable in the eclipse configuration. And by default fonts are quite big so you may need to change them. Eclipse uses the default environment fonts. You can execute “gnome-font-properties” to edit the global gnome fonts settings that eclipse uses.
- Key shortcuts
It’s important to use keyboard shortcut that make life easier, maybe I changed them so check your keys shortcut in Windows > Preferences > General > Keys
- ALT+LEFT to go to the last code seen (like a previous in firefox)
- CTRL+Q to go to the last edit location
- CTRL+SPACE for the code assistant / suggestion
Do you have some more to suggest?
- Eclipse feature: Local History of a file
You can compare your current file to its any of its local history. Eclipse keeps all changes to your files in its database. Don’t be scared to change and delete some code, you could always find it back :-) It is VERY VERY useful. And of course you could always compare with the SVN version.
- Remote debugging
Want to debug a test server which is different from your development machine? It should be quite easy using the eclipse Remote Debugging in the Debug panel options. See also http://www.nth-design.com/developerresources/php/SettingUpRemoteDebugging.php (not tested)
Tutorial Eclipse
I highly advise to check the animated tutorials proposed by the opensource gallery2 project on their developer wiki : http://codex.gallery2.org/Gallery2:Animated_Eclipse_Tutorial
Conclusion
It took me around 3 days to find all the good settings + versions to be able to debug php in eclipse :-( This is quite painful to get to work without some clear explanations. But it’s worth it, the eclipse environment is really good :-)
Share with me your experience with eclipse; is this tutorial easy to follow? Did you have problems?
Do you have some interesting tips on improving eclipse usage, to share with us?
Please post comments :-)














