Sunday, February 15, 2009

Configuring Ubuntu, Eclipse w/phpEclipse plugin, and LAMPP running on a web server

Developing with Eclipse. I've always been a notepad IDE person (obviously hence the blog name but....real work has required me to use Eclipse and CVS).

This covers Ubuntu/8.04 (hardy), Eclipse Ganymede with phpEclipse plugin, and LAMPP. LAMPP is a quick way to get an Apache2 web server up and running for development purposes, with mySQL and PHP automatically set up. But the ultimate solution and purpose of this post, getting Eclipse to output files that run on a web server, will work on any web server. In addition configure phpEclipse and Eclipse workspace folders which requires a few additional steps which are detailed here.

If you don't have LAMPP, you can get xampp-linux-1.7.tar.gz from:
Linux http://www.apachefriends.org/en/xampp-linux.html

Note: If apache2 is installed somewhere else on the system, LAMPP can coexist, but the other Apache daemons will have to be stopped before LAMPP will start (system will check and warn).

Eclipse Ganymede was downloaded and installed from the Eclipse.org site since an older Eclipse was available from the Syntaptic Package Manager and I wanted Ganymede, but really you can use whichever you want, it will not affect these instructions.

Once LAMPP is running and localhost is showing the XAMPP page and Eclipse is configured and loaded with phpEclipse and all the web tools, the Eclipse workspace will normally be placed in your home folder. However, if you're writing PHP files with Eclipse (you installed phpEclipse, afterall) obviously both the web server and Eclipse needs to know where to find the folders. The secret is to put those Eclipse php folders on the webserver. Then put symlinks in the Eclipse workspace that point to the those folders.

Demonstration:

1. make a folder called 'projectX', or whatever you want to call it, in htdocs (the default server document root which can be found at /opt/lampp ) and give it permissions so it is owned by the user:

chown $user /opt/lampp/htdocs/projectX

(in all these examples, $user should be replaced by your Ubuntu username in the commands)

2. make a symbolic link to this to file, and put it (the symlink) in the workspace to be used by Eclipse to hold projects. When Eclipse saves to the folder, the files will actually be written to the folder that was created in the web server's document root (in htdocs).

The rule for creating a symbolic link:

ln -s /path/to/real/file /path/to/non-existant/file

modified for this demo:

ln -s /opt/lampp/htdocs/projectX /home/$user/workspace

Which will result in a folder with an arrow on it in the users eclipse workspace!! It will have zero items in it until files are download from Eclipse CVS or the phpEclipse IDE is used to create or edit files. Most importantly, the files can be browsed and read by the development web server.