As PHP has grown and matured, so have the tools for PHP developers. Integrated development environment
choices have never been greater. One such IDE is the open source Eclipse Platform. Eclipse, essentially
a rewrite of Visual Age for Java, was a donation to the open source community by IBM and quickly became
a household name in the Java world. Now, combined with the PHPEclipse plugin, Eclipse offers a
world-class development environment for PHP applications.
This article will help you get started with using Eclipse for PHP development. It provides an overview
of the Eclipse Platform, information on the installation of Eclipse and PHPEclipse, the Eclipse interface,
and some PHP-helpful features.
The Eclipse Architecture
Eclipse is written in Java and its GUI is handled by the Eclipse Standard Widget Toolkit (SWT).
This combination makes Eclipse a fast, cross-platform application. Pre-compiled binaries are
available for all major operating systems including Mac OS X, Linux (GTK and Motif), Windows,
By itself, Eclipse does nothing. The core piece of Eclipse is just a small kernel. All functionality
of the Eclipse platform is a result of interactions between plugins and the kernel. This includes the GUI
and file system managers. Since Eclipse made its name as a Java development platform, a Java Development
Toolkit (JDT) plugin is included with the standard Eclipse SDK for Java development.
The significance of this modular architecture cannot be overstated. It gives Eclipse a phenomenal
amount of flexibility. Via plugins, not only is Eclipse a professional IDE for many languages, but
it can also act as an interface for many other systems. With Eclipse, you can write Cobol code, and
use it as a front end for an LDAP server. The number of plugins is so diverse and numerous that Eclipse
Foundation maintains a separate site for the plugin community at http://www.eclipse-plugins.info/eclipse/index.jsp. A more compelling consequence of the architecture
is its meaning for open source in general. No longer are developers tied to one proprietary tool, product,
or closed license. With a C# plugin for Eclipse, you do not have to purchase Microsoft Visual Studio should
you wish to develop in .NET. It is the open source method of embrace and extend.
For this article, I will focus on the PHPEclipse plugin for PHP development. A bit of warning - PHPEclipse,
and this article, has a heavy Apache and MySQL bias. PHPEclipse can work with other web servers and databases
with very little functionality sacrifice.
Downloads and Installation
You should have Java, Apache running PHP, and MySQL installed locally. If you are running Windows and
do not have these components installed, consider following the wampp-based instructions on the PHPEclipse site:
http://phpeclipse.de. If you already have a development web server/database environment, follow
these basic instructions.
Download the latest version of the "Eclipse SDK" package for your operating system. The Eclipse
SDK package has the complete IDE and the Java JDT. Uncompressing the SDK creates a directory called
\eclipse. Move it to your favorite applications directory.
After unzipping the plugin, place all decompressed files in the plugins directory of the eclipse
directory. At a minimum, you will need these two packages for PHP development.
Additional features may require other software installations, as noted.
The Eclipse Interface
When Eclipse launches, it will ask you where you would like to place your Workspace. Your Workspace
is where all the files in your application go. Traditionally, this is placed in your individual user
directory or a separate workspace directory under the eclipse application directory. If you do
primarily web development, you may consider placing this in the DocumentRoot directory of your web server.
After Eclipse finishes startup (yes, it may take a while), you'll be presented with the main Eclipse
interface. The overall GUI is called the Workbench. In Eclipse, each tab is called a view. The arrangement
of views is a perspective. Each perspective is geared towards a certain task. Debugging has a perspective.
Java development, PHP development, and CVS integration are examples of other perspectives. By default, you
should see the Resource Perspective, which is a general-purpose default perspective.
Across the top, there is the Navigator View, which shows file system resources and the file
structure of each project. Next to that is the Editor. The Editor is used to edit code. In the far right
is the Outline view. The Outline is used to display the hierarchy of something, depending on what
perspective is using the Outline. In Java and PHPEclipse Perspectives, the Outline shows classes
and their methods. The pane below is a miscellaneous pane that displays views dependent on the
perspective. PHPEclipse Perspective puts web browser and system console panes here by default.
To change perspectives, go to the Window -> Open Perspective, or use the Shortcut Toolbar
in the upper right corner. Several other options in the Window menu allow you to customize
perspectives. To open views, go to Window -> Show View. For both these submenus, certain
views and perspectives may be hidden. Select the "Other..." option to view everything available.
Eclipse manages applications and websites by projects. To create a new project go to File ->
New -> Project... For PHP projects, select the PHP Project option. This will lead you through a
wizard and the end project will appear in the Navigation view. To add pages or files, select File
-> New -> PHP File. You can also add subdirectories and create your whole site hierarchy from
here. Each item appears in the tree structure of the Navigation view. When you click on a PHP file,
it will open in the Editor for editing.
Features for the PHP Developer
The Editor alone is worth the price of admission. In addition to being well versed in
syntax highlighting, The Editor also knows all the PHP functions and HTML tags. Within <?php
and ?> tags, try typing "mysql" and then hit Control and Space. All functions beginning with
"mysql" will appear. Select the one you want and hit Enter. You can see all HTML tags when you are
outside of the php directive tags. Type "<" and hit Control and Space. This is the Eclipse
template system at work. A template is also available in the Java Development Perspective for the
standard Java Class Libraries.
As with any good IDE, PHPEclipse has a debugger to set breakpoints, step through code, and
monitor variable values along the way. In the Editor, double click on the column just to the
left of the line number to set a breakpoint. To debug, click on the file and select Run -> Debug
As -> PHP Application. This will activate the Debug Perspective. From the Debug View, you can
step through code. The Variables View shows all application and environment variables, and their values.
The installation of the debugger is not for those with weak stomachs. Moreover, as of this writing,
there are a few reported bugs in the debugger of the latest version of PHPEclipse. For Windows users,
if you follow PHPEclipse's wampp-based instructions, it should work. For other platforms, you should use
the dbg section from those instructions as general guidelines. You will need to install and configure the
dbg debugger PHP extension available at http://dd.cron.ru/dbg/downloads.php.
PHPEclipse acts as a client to this extension.
SWT Browser Widget
The Standard Widget Toolkit includes a web browser, called the SWT Browser Widget. Eclipse uses the
Widget to view HTML documents as if a web browser were requesting them. The Widget's rendering engine
is dependent on your operating system - KHTML for Mac OS X, Gecko for Linux, and MSHTML for Windows.
Every time you save a file in the Editor, the Browser widget will make a request for the edited page
from the local web server.
To activate the Browser Widget preview, you'll need to specify your local web server's DocumentRoot
and localhost address in the Eclipse Preferences. Go to Window -> Preferences -> PHPEclipse
Web Developer -> Project Defaults. You'll also need to make sure the project is in the DocumentRoot
directory. If you didn't specify the default workspace to the DocumentRoot, you can override project
locations by right clicking on each project and selecting Properties.
Quantum Database Browser
With the Quantum DB Perspective, you can interface with a database directly from Eclipse. In
the SQL Editor, you can write SQL statements against a database and have the result set appear in the
Quantum Table View. You can also browse the schema of a database in the Database Bookmarks and
Quantum Table Views.
The Quantum Perspective acts as a client to a database using a JDBC connection. Your database must
have a JDBC driver installed. For MySQL, the official MySQL Connector/J driver is available at http://dev.mysql.com/downloads/connector/j/3.0.html.
Once you have this installed, you need to create a bookmark for each database by right-clicking in the Database
Bookmarks View. Eclipse will prompt you for the location of the driver and all the database settings.
Vaya Con Dios
Hopefully, this article will get you up and running with Eclipse and PHPEclipse, and convince you
that this is the right PHP development platform for you. This is just a very brief introduction to
Eclipse's functionality. There are many other features, settings, and plugins to explore. As you
discover more functionality, odds are that you'll find Eclipse even more useful. With widespread industry
support, an extensible architecture, and an open source license, Eclipse is an important player in freedom
of software choice and makes your PHP development easier.