26 Oct 2007

phpeclipse on ubuntu

First of all; I have finally found a feature rich, cross platform php development environment (IDE). phpEclipse is a great tool and has matured to a quiet stable platform. However, due to utilization of eclipse it can also be (although extremely configurable) quiet complicated to setup.

Here are some installation instructions and problems I have experienced while using phpeclipse on ubuntu feisty.

Installation of java and eclipse

The installation of phpeclipse is fully covered by debian's package manager and eclipse (for the phpeclipse extension). First of all, Install eclipse itself:

sudo apt-get install -y eclipse
The eclipse package will install gcj (a free -as in freedom- java implementation, the GNU Compiler for Java) but phpeclipse will crash if you are using the default jre. You need sun's implementation of java. You must activate the multiverse repository in Ubuntu to make it available to the various package managers. Fortunately ubuntu feisty ships with sun's java implementation. The newest version is sun's java 6 (jre 1.6). I have experienced strange "Computing hasChildren" errors while running a php script in the eclipse debugger. Sun's java jre 1.5 solved the problem.

install it:
sudo apt-get install -y sun-java5-bin
after that, you must make sure that eclipse is using the newly installed jvm. You can set the order of used jvm's for eclipse eighter in /etc/eclipse/java_home or in ~/.eclipse/eclipserc (if you want to use your personal jre).
sudo gedit /etc/eclipse/java_home
make sure you add the line '/usr/lib/jvm/java-1.5.0-sun' on top of all entries. My /etc/eclipse/java_home looks like this:
# This file determines the search order the Eclipse Platform uses to find a
# compatible JAVA_HOME. This setting may be overridden on a per-user basis by
# altering the JAVA_HOME setting in ~/.eclipse/eclipserc.

/usr/lib/jvm/java-1.5.0-sun
/usr/lib/jvm/java-6-sun
/usr/lib/jvm/java-gcj
/usr/lib/kaffe/pthreads
/usr/lib/j2se/1.5
/usr/lib/j2se/1.4
/usr/lib/j2sdk1.5-ibm
/usr/lib/j2sdk1.4-ibm
/usr/lib/j2sdk1.5-sun
/usr/lib/j2sdk1.4-sun
phpeclipse update

The easiest and safest way to install phpeclipse in ubuntu is to use the eclipse update manager. First of all, make sure to run the latest version of eclipse itself. Select "Help » Software Install » Find and Install" from the menu:



Search for updates of already installed software. Make sure to up your eclipse (and installed features) to the latest stable version (or snapshot if you are keen, don't email me). In my case, I have updated to version 3.2.2.

You should now have the latest and greatest of eclipse, but no php support yet.

phpeclipse installation

you can also use eclipses update mechanism to install new features. You just need to add a new software repository to install a new feature and future updates.

Open "Help » Software Install » Find and Install" from the menu. Then select "Search for new features to install".



Click "Next »" and add a new repository by clicking "New remote site ...". The use one of the following repositories:

Stable
http://phpeclipse.sourceforge.net/update/releases

Unstable (if you are keen)
http://phpeclipse.sourceforge.net/update/nightly



Click Ok, select the repo and click "Finish".



This should install all phpEclipse components.

Running phpeclipse.

The first time you start up eclipse, you will see a java perspective. A perspective defines how your environment looks like. The java view will not offer you the information you want. Click on the "open Perspective" icon and select "Other" and then "PHP". If eclipse crashes these settings will probably not be stored, so an eclipse restart is recommended.

Then it is time to import projects into your workspace. First fo all, create a new php project. Right click the "Navigator" and select "New » PHP Project".



Php web scripts can be imported with right clicking the "Navigator" and the selecting "New » Folder". Make sure to link this folder to an NFS or Samba (or Windows) share.



Make sure to check the "Advanced »" Tab and the enter the path of the linked directory. That way, eclipse will not hold a copy of the files but will just link to your project. this is handy to use already existing projects.

Once you have imported the directory, you should be able to edit php files, see the class three and navigate to include files. Debugging scripts via http seems to be called; debugging remote scripts. Although they can be served via localhost. As far as I have seen, it is hard to get the settings right. It seems to be able to get the configuration to work for localhost debugging. It does not seem to be working (as of eclipse 3.22 and phpeclipse 1.8) for actual remote debugging (eg. your php script is run on an remote server with php_dbg.so enabled).

Serverside setup

Serverside means apache and php on localhost here, since I did not get it working for remote sites yet. install the php debugger extension from dd.cron.ru. If run from localhost you should be able to get debugging working with sun's java 1.5 jvm.

No comments: