In my last article, I talked about installing PHP. With PHP installed, you will want to start writing code, so today's article is about developing PHP using the open source Eclipse integrated development environment (IDE).
Eclipse started as a Java IDE and evolved into a generic IDE with a strong Java bias. If you start out with a standard Eclipse installation and without any Eclipse experience, it may take you a while to figure out the best way to set it up for use with PHP. This article will make the PHP setup fast and easy.
Why use Eclipse?
The reasons for using Eclipse are the same as those for using most IDEs:
- Syntax highlighting
- Syntax validation as you type
- Editing assistance (indentation, auto-completion, etc.)
- Access to documentation as you type
- Refactoring assistance
- Debugging assistance
- Integration with other tools (documentation creation, source control, etc.)
Currently, the PHP version of a feature is often more limited than the Java version. For example, refactoring is limited to moving files; if you want to rename a class, method or function, you will need to use the Find/Replace tool (which, luckily, can be applied to all files in a project). I expect that the PHP tools will improve with time.
PDT
Eclipse consists of a core set of functions and a flexible plugin system. The plugins provide many of the features that we usually think of as standard parts of an IDE. This is what makes it possible to adapt Eclipse to many computer languages.
PDT is the PHP Development Tools plugin, which is essential for working with PHP inside Eclipse. Over time, you may choose to enhance your Eclipse installation with other plugins, but for PHP development, you only need PDT (and its few dependencies).
Getting started: Download
Begin by downloading the all-in-one Eclipse/PDT ZIP file. This contains all you need to start using Eclipse with PDT.
If you don't have Java Runtime Environment (JRE) 5 (or greater) installed, then you'll also need to download the latest JRE.
Getting started: Install
Start by installing the JRE, if you need it.
The Eclipse all-in-one package comes as a ZIP file. On Windows, you can extract the contents to C:\Program Files. This will create a folder called "eclipse". For easy access, copy the eclipse.exe file in the folder and paste it as a shortcut on the desktop.
Getting started: Configure
Start Eclipse by running the eclipse.exe file. This will ask you to select a "workspace", a folder that will store a collection of your projects. You can have more than one workspace.
Eclipse will suggest a location for the workspace. If you're happy with it, click OK. On Windows, I would suggest using something like My Documents\Eclipse. If you don't intend to create multiple workspaces, select "Use this as the default and do not ask again" before clicking on OK (you can change your mind later).
Eclipse should appear and display the Welcome screen (you can return to the Welcome screen through the Help menu). Now I will introduce you to Eclipse's rather intimidating preferences system: select . Under , select PHP 4 or 5.
There are many other options you will want to customize, but this is sufficient to get started. You'll return to this menu many times to tweak how Eclipse works.
Getting started: Update
You should also become familiar with Eclipse's update system. Select . Select a mirror or let Eclipse select one for you. Eclipse will now begin a rather slow search for updates. You can place the update dialog into the background and continue to work while the search takes place.
When Eclipse locates all the updates, a window will appear, showing you your update options. Select everything and begin the update. Once you have installed all updates, you may need to restart Eclipse. Your installation is now up-to-date.
The update method is also the way you add new features to Eclipse. Use , but this time select "Search for new features to install". You'll be able to search for features on a collection of sites.
For example, let's say you use doxygen to generate your PHP documentation. You would click on "New Remote Site", enter "Eclox" for the name and http://download.gna.org/eclox/update/ for the URL. This creates a new entry in the sites list.
You can visit Eclipse Plugin Central to find additional plugins to install. But let's leave that for later.
Creating a project for existing PHP code
Your Eclipse installation may coincide with the creation of a new PHP project, but it is more likely that you already have existing code you want to use within Eclipse. This is where most people get a little stuck—if you know the magic incantation, the process is easy.
Let's say you have a PHP Web site at My Documents\Sample\Web Site and that you test the Web site using the local server address http://localhost/sample.
Fire up Eclipse and select . Enter a project name. Disable the toggle and browse to the My Documents\Sample\Web Site folder. Click . The files in the My Documetns\Sample\Web Site folder are now part of an Eclipse project.
You probably also reference code through a PHP include path. Select to include folders in your Web site's include path. Click .
Our project now appears in Eclipse's PHP Explorer pane. Eclipse will place a .project file in the My Documents\Sample\Web Site folder, but your content is otherwise undisturbed. You are ready to use Eclipse. You can also continue to work on your code using your existing development tools.
Editing with Eclipse
Using the PHP Explorer pane, you can double-click on a file and have it appear in Eclipse's editor pane. The features here are pretty standard, so I won't talk about them too much. You may want to return to the preferences dialog to customize the editing features.
One nice editor feature is called "code assist". Eclipse will pop up various displays that offer documentation or auto-completion help. If the code assist popup doesn't appear automatically, you can call it with Ctrl + Space. One caveat: if you have enabled the Emacs key bindings, the magic sequence is Alt + /.
Executing PHP
You can still run your Web pages by typing http://localhost/sample/some_page.php into your Web browser. But let's try running the page from eclipse.
First, some setup: Using , we create a new server, Sample, with a URL of http://localhost/sample. If you would like to use your default browser, go to , select and enable .
Open up your Web page in the editor. Select . In the dialog that appears, verify that the is correct. The page will appear in your Web browser.
You may notice that the URL has many parameters attached to it. These are for coordinating with the debugger. This may be a bug in Eclipse since debug parameters should only be added when debugging a script.
Go to . You'll see that you can create a "run configuration" that controls what happens when you select . For my "sample" project, I right-clicked on and selected . I set the debugger to XDebug, the PHP Server to Sample and the file to /Sample/index.php. On the tab, I toggled Run under .
Now I can run the index.php page by selecting the Run icon on the tool bar and then selecting the run configuration I created from the tool bar drop down. Using this method, the page appears without the debugging parameters attached.
As far as I can tell, you would have to create one run configuration per page. Or, as I pointed out earlier, you could just enter the page address directly in your browser and bypass Eclipse.
Debugging PHP
If you have your system set up to use either the Zend debugger or XDebug, it's easy to debug with Eclipse.
Configuring PHP for debugging is beyond the scope of this article. The Eclipse portion of the setup involves using to get to a dialog very similar to the Run Dialog. Create a configuration for debugging index.php and enabled the Debug toggle on the Common tab.
On the tool bar, you can use the debug button drop-down to select your debug configuration. Normally, the debugger will break on the first line.
When you start debugging, Eclipse will offer to switch to the PHP Debug perspective, which will give you the right panes and controls to run the debugger.
Additional resources
I hope these instructions give you a head start at using Eclipse for PHP. Here are some other places you may get assistance.
- Visit http://www.eclipse.org/, the home page of the Eclipse project.
- Visit http://wiki.eclipse.org/PDT, the home page for PDT.
- Visit http://wiki.eclipse.org/PDT/FAQ for a list of frequently asked questions about PDT.
- Use and open up the for the online manual.




As addition to pdt a very
As addition to pdt a very nice ssh, sftp console tool
http://www.eclipse.org/dsdp/tm/tutorial/
update url: http://download.eclipse.org/dsdp/tm/updates/2.0/
Above needs the following library: (install this first)
http://www.eclipse.org/cdt/downloads.php
update url: http://download.eclipse.org/tools/cdt/releases/europa
to update/install these kind of tools:
Help -> Software update -> find and install -> search new features to install -> new remote site
Enjoy your new perspective (top right) remote system explorer
Thanks!
Thanks for the article, it got me started with Eclipse and PDT.
good article - but can you 'share' some info. on other IDEs?
For example, Netbean and its 'new' php support :)
Thanks!
J
Hi, Jack, I've used Netbeans
Hi, Jack,
I've used Netbeans in the past, but switched to Eclipse because it seemed most other people were using it. I'd love to share some info on Netbean's PHP support, but I have nothing to share. Perhaps you could write an article and drop a pointer to it here?
Tony Freixas
Tiger Heron LLC
http://www.tigerheron.com
what server?
Hi Tony, I really appreciate you putting up this how-to guide, but I'm still too dumb to figure it out. I'm a n00b at php, but I downloaded PDT and Eclipse and Zend and have run my php as a script successfully. But everytime I try to run it as a Web Page, I get the host not found. This is understandable (as a Java developer) because I've not associated my project with any server; I've not even created a server! I tried to create an HTTP Server instance, but that did not work.
I do see my Default PHP Server that was created as http://localhost, but how does it run? How do I associate it with my project?
thanks,
josh
Hi, Josh,
You'll need to install a server on your PC. I use Apache 2. There are plenty of sites out there with instructions on setting up Apache to run PHP. Then you need to put your PHP code where the server can find it. If you use http://localhost, then the code needs to be wherever you set up your server's document root.
I'm not sure if my answer makes sense to you, but try searching for information on Apache and PHP and what you find may help this start making sense.
Tony Freixas
Thanks!
Thanks for your quick response. I guess I was over thinking it. I have a LAMP server already running on my Linux box, but none of the tutorials for Eclipse spell out that you first need to create the http server and get PHP running before you can make use of testing with Zend and PDT. I think I was or am also confused about what Zend does. Like I said, I'm still a n00b.
I'll give it another whirl. thanks, again!
Eclipse PDT PHP
A nice article. Thanks for the same. It should get me started fast on PHP development. By the way, re there any samples that could hep me develop an end to end application in PHP?
Rams
Opening exising project files
I'm one of those people stuck on opening an existing project on my web root.
Ive followed your instructions and i get "" the location already exists and contains files" delete them? or create in location/projname
Which dosn't leave me editing those files in my new IDE!
Well written, very informative
I've always been an old-schooler, using notepad and sometimes Homesite for my development. I thought I'd try out Eclipse with the PDT add-on, and this article helped get me going very quickly. Thanks!
XAMPP or WAMP
Two programs that simplify setting up a localhost server for testing php locally:
Xampp
http://www.apachefriends.org/en/xampp.html
WampServer
http://www.wampserver.com/en/
Both work great. I find WampServer to be more user-friendly, but it only works on Windows where as Xampp has multiple versions for multiple OSs.
If running Vista, be sure to run either WampServer or Xampp with Admin rights, otherwise the "services" will not be able to start up.
Oh, thanks for the great reference. I am new to PHP and have been using Notepad++. It's been rough since I am used to using Visual Studio for other languages. Hopefully I will enjoy using Eclipse so I don't have to drop hundreds for Zend Studio!!!
Bonjour et merci beaucoup !! | Hello and thanks a lot !!
Bonjour,
J'ai beaucoup apprécié cette aide, qui m'a permis d'installer eclipse et de tester mon premier projet php sous cet IDE...
Ce sera mieux que le bloc-note ;)
Bonne continuation !
Hugo
---
Hello,
I've really appreciate this help which allows me to install eclipse and test my first php's project under this IDE...
It could be so much better than a simple text-editor ;)
Best regards,
Hugo
Problem with Run
I'm having a problem getting "Run" to open my local files with the correct URL. It keeps appending the URL with the name of the directory my files are in. For example, my project is in a folder called "testsite" and my server is configured to run "testsite" as the document root such that if I manually type in http://local.testsite.com/index.php, it will successfully open the index.php which lies at the root of the "testsite" folder. But when I use "Run" in Eclipse, it automatically generates http://local.testsite.com/testsite/index.php, acting like my testsite folder is not the document root but a folder inside. I know I can manually override that but is there a way I can configure it so it automatically generates the proper URL?
thanks in advance for any help!
Karl
A great big thank you!!!
I used Eclipse about 2 years ago. At that time, it was already set up for me when I reported. I had never used it before and thought it was absolutely the coolest developer's IDE I ever saw.
That was then; this is now. Since then I have downloaded this application a dozen times and each time ended in just absolute frustration. I would usually wind up going back to NetBeans and deleting the entire Eclipse folder. It just reported absolute gibberish when there was a problem and I had no way to find out how to fix it.
I followed your directions to a T and was flabbergasted. My existing project developed over the last three weeks ran the first time. I even got into the debugger.
I think this is the best help I've ever found on the internet for Eclipse. I'm now going to start using it exclusively. I kow I'll run into those nonsense errors again, but I'll work around them. At least I got a PHP project running in Eclipse. That is light years ahead of where I was the last time I used it.
Thanks and I hope others find this piece of information.
Dave
Creating a new PHP Project in Eclipse from existing source code
I'd like to add that I wrestled with this even after reading this article, and that what my solution was was that I had to fire up Eclipse in the default workspace (or at least not the same one I was trying to create in!). That seems like a no-brainer in retrospect, but it tripped me up.
-Bronius
eclipse-php-galileo-SR1-win32 v/s PHPEclipse-1.2.3
i have to develope a project in php..i want to know that which way is better to use eclipse for that..
1) Direct use eclipse-php-galileo OR
2) Use eclipse classic and add php plugin...which one is better??
Thank you
Thanks a lot for the information and it helped me immensely!
Post new comment