How To: Editing PHP Sites With Eclipse

While most people consider Eclipse an IDE for Java (I use it every day as my Java IDE), many probably don’t know it also makes a great IDE for PHP development. I will walk you through setting up a new Eclipse installation for use with PHP against a MySQL database. My installation will assume that the source for your site is (1) accessible via FTP (2) you want to edit the source files directly directly on the server and (3) your MySQL database is accessible on the PC you want to install Eclipse onto.

The software mentioned in this guide is either free, open source, or is licensed to be freely available. Nothing for you to buy.

0. Install the most recent version of the Java Development Kit (JDK 5.0 Update 6 at the time of this writing). I know, you don’t want to develop Java code, but, Eclipse is written in Java. Despite what you may think about Java, Eclipse performs pretty well and has the look and feel of a native application.

1. Get NetDrive. NetDrive is a nifty program that makes an FTP site available as a drive letter on a Windows machine. Install NetDrive. Run NetDrive and and mount the site in question to a drive letter, such as T:. You may have to use the Advanced options to set the initial directory where you want it.

2. Download Eclipse (version 3.1.2 was the current version at the time of this writing). Save the Eclipse ZIP to C:\

3. Expand the Eclipse ZIP C:\ (it will make its directory, “eclipse”).

4. Make a shortcut (Icon) on your desktop to start Eclipse, but, specify the directory for your workspace. The target of the shortcut should be something like “C:\eclipse\eclipse.exe -data C:\save\eclipse\workspacephp”. This way you can always get a new version of Eclipse and not worry about your workspace. (Make sure the directories you specified exist).

5. Start Eclipse with your shortcut. The first time you run Eclipse you will be presented with the Welcome to Eclipse 3.1 screen. In the top right you will see an Arrow (when you hover over the arrow it will say Workbench). Click the arrow.

6. You are now in the “Java Perspective”. As a PHP person, this perspective is of little use to use. From the Window menu, select Open Perspective | Other… Now click on the Resource perspective and click OK. This is the perspective I use most. As you probably won’t use the Java perspective much in the future, look in the toolbar at the top right of the Eclipse window where it says both Resource and Java, right click on Java and select Close. For future reference, these are buttons to quickly switch between Eclipse Perspectives.

6a. Next, we want to install the PHPEclipse plugin. From the Help menu select Software Updates | Find and Install… Make sure Search for new features to install is selected then click Next.

6b. Click New Remote Site. Set

Name: PHPEclipe
Click OK

6c. Making sure only PHPEclipse is checked, click Finish. Eclipse will now go see what is available in the PHPEclipse distribution site. Check the PHPEclipse top level, which will select all of the plug-ins that are contained within PHPEclipse. Click Next. Note: The extra plug-ins include Quantum DB (a very nice Database browser) and Subclipse (the Subversion plug-in for eclipse).

6d. Click that you accept the license. Click Next.

6e. Click Finish to start the installation of PHPEclipse.

6f. PHPEclipse will be downloaded. This will take a few minutes (or more) depending on how faster your internet connection is. Once the download is complete you will be asked to verify the installation. Click Install All. Once all of the plug-ins are installed you will be prompted to restart Eclipse, click Yes.

7. Once Eclipse has restarted, you are ready to create your PHP project. As you were in the Resource perspective when you last quit Eclipse, you should still be in that perspective. If not, switch to it. From the File menu click New | Project… The project type you want to create is a PHP | PHP Project then click Next.

8. Name the project to your liking, but, where it says Project Contents UNCHECK Use Default and click Browse to find the directory of your site that you now have from NetDrive, as result of step 1 of this gude. Click Finish.

9. Eclipse will now scan through the contents of the project (the directories and the files offered by your FTP server). This can take a little time, so be patient.

10. The Navigator pane (on the left) should now show a single project, PHP. If you add other projects they will be show here, you can have any number of projects. Browser through the directory structure and double click to open files, edit them, when you save, the files will be saved, via FTP, directly to the server (thanks to NetDrive).

11. The last thing to do is to setup Quantum DB so you can browse your remote MySQL database. Before you can do this, you will need to make sure your PC has the privileges to access the MySQL database.

12. Before Quantum DB can access a MySQL database you will need the MySQL JDBC driver JAR file. You can get this from’s Connector/J site. I would suggest the 3.1 “production” version. Download the source and binaries ZIP file. From this ZIP file you will need to extract the JAR file, which is probably named “mysql-connector-java-3.1.12-bin.jar”. Place this file somewhere on your hard drive (making a note where you put it).

13. Now, we need to open the Quamtum DB perspective. Go to the Window menu and select Open Perspective | Other… select Quantum DB and click OK. The Quantum DB perspective is now open. It is worth noting that you can now switch between the Perspectives you will commonly use from the toolbar, upper right hand side, Resource, Quantum DB, PHP, etc. Don’t forget these buttons as you will probably use them quite a bit.
14. We need to configure your database connection. Make sure you are in the Quantum DB perspective. From the Database Bookmarks pane (on the left) right click and select New Bookmark.

15. We need to add the MySQL JDBC driver. Click Add Driver. Click Add External Jar… then find the MySQL jar file you downloaded in step 12. Next, we need to specify the Class name. Click the Browse… button and select the com.mysql.jdbc.Driver entry. The Type should automatically change to MySQL. Click Finish.

16. We are now ready to add a Bookmark to your actual database. Select the MySQL driver and click Next. Now, fill in the connection information for your database and click Next. Name the bookmark (this is a descriptive name for you). Click Finish.

17. If you double click the new Bookmark, you can now browse the database. If you get a connection error you can right click on the bookmark and select Properties to change the connection properties of the bookmark. If you double click a table you can browse the contents of the table in the lower right in the Quantum Table View. In the upper right is the Quantum SQL Query Editor view where you can enter SQL commands and then click the arrow (on the right of this view) to execute the commands against your database. It should be noted when you are viewing a table (in the Quantum Table View) you can right click to Insert, Delete, Update the rows in the table.

18. You probably already know, but, to get back to editing your PHP code, in the top right, click Resource or PHP button to switch to one of those perspectives.

Future directions… You already have the Eclipse Subclipse plug-in (for Subversion) and Eclipse comes standard with CVS functionality. If you want to change from using FTP via NetDrive, you can use either Subversion or CVS using Eclipse’s Team functionality. What I have shown you is currently, to my knowledge, the best want to handle FTP with Eclipse. There is an FTP and Webdav plug-in for Eclipse, but, I didn’t find it to be terribly helpful.

Good luck. I hope you enjoy Eclipse as much as I do.

Leave a Reply