Web Development with Eclipse Europa, Part 2: PHP Development Tools How to Use Eclipse Europa for Web Development Using Java Technology, PHP, and Ruby
Total Page:16
File Type:pdf, Size:1020Kb
Web development with Eclipse Europa, Part 2: PHP development tools How to use Eclipse Europa for Web development using Java technology, PHP, and Ruby Skill Level: Michael Galpin ([email protected]) Developer eBay 11 Dec 2007 No matter what combination of technologies you prefer to work with as a Web developer, Eclipse is a single integrated development environment (IDE) that can increase your productivity. In Part 1 of this three-part "Web development with Eclipse Europa" series, you saw how the latest release of Eclipse — Europa — can be used to develop Java™ Web applications rapidly. Here Part 2, we'll see how easy it is to develop PHP applications using a different set of Eclipse plug-ins, collectively known as the PHP Development Toolkit (PDT). Section 1. Before you start Are you a PHP developer? If so, then what do you use as your development environment? Maybe you're a minimalist who likes to engage in vi vs. Emacs debates. Or maybe you prefer an IDE, but haven't been impressed with the commercial offerings available. Either way, you'll want to take a look at the PHP Development Toolkit for Eclipse. That's right — Eclipse. It's not just for Java developers anymore. A background in PHP programming is essential for getting the most out of this tutorial. Familiarity with the Eclipse IDE is helpful, but not necessary. For some background information about Eclipse, see Resources. About this series In this "Web development with Eclipse Europa" series, you'll see how no matter what PHP development tools © Copyright IBM Corporation 1994, 2008. All rights reserved. Page 1 of 41 developerWorks® ibm.com/developerWorks your language of choice is, Eclipse is the platform for Web development. Its flexible plug-in system makes it easy to create versions of Eclipse customized for Web development with Java technology, PHP, and Ruby. You'll see how different plug-ins give Eclipse unique capabilities for each language. You'll also see some of the common features that all Web developers can take advantage of. Throughout this series, we will be creating a sample baseball Web application, which will allow us to enter in game data for baseball players and calculate statistics for those players. About this tutorial Eclipse has been a favorite IDE for Java developers for many years. However, Eclipse was designed to be a development platform for any language. Eclipse is written in the Java programming language, so, naturally, Java development was an obvious starting point for it. Eclipse's plug-in architecture has led to a bounty of powerful plug-ins and has been key in the success of Eclipse. Taking these two facts together — Eclipse's strength as a development platform for any language and Eclipse's plug-in architecture — and you have the ingredients for an Eclipse-based IDE for PHP. That's exactly what has happened with the development of the PHP Development Toolkit. This is Part 2 of a three-part tutorial series on developing Web applications with Eclipse. So far, we've seen how easy it is to develop Web applications in the Java language using the Eclipse IDE for Java EE Developers. The Java EE edition is really just a collection of plug-ins running on the Eclipse Platform. In this tutorial, we'll see how to develop PHP applications using a different set of Eclipse plug-ins, collectively known as the PHP Development Toolkit (PDT). We'll also see a reprise of some features in the Java EE Edition that are also part of the PDT. Prerequisites A background in Java programming is essential for getting the most out of this tutorial. Familiarity with the Eclipse IDE is helpful, but not necessary. System requirements You'll need the following installed on your computer: Eclipse Europa This tutorial uses Eclipse V3.3 (Europa). Java Development Kit (JDK) This tutorial shows you how to develop Web applications using Java technology, so you'll need the Java Development Kit (JDK) 5.0 or higher. Download V5.0 or V6.0. Eclipse IDE for Java EE Developers You'll also need the Eclipse IDE for Java EE Developers. PHP development tools Page 2 of 41 © Copyright IBM Corporation 1994, 2008. All rights reserved. ibm.com/developerWorks developerWorks® Java Runtime Environment (JRE) To run Eclipse, you must have a JRE. Apache Tomcat The application uses a Apache Tomcat as its container. MySQL V5.0 The application uses MySQL V5.0 as its database. Java Persistence API You will also need the Java Persistence API and, in particular, the OpenJPA implementation. Eclipse PHP Development Toolkit (PDT) This tutorial shows you how to develop Web applications using PHP, so you'll need the PHP Development Toolkit You can get this as a set of plug-ins for an existing Eclipse installation. If you're new to Eclipse, you can get an all-in-one installation that includes the Eclipse platform and the PDT plug-ins. PHP You need PHP, so get the latest version, which at the time of this writing was V5.2.1. Apache HTTP Server You need a Web server that integrates with PHP. This tutorial was developed using Apache V2.0.59. Fancy PHP debugger You need a PHP debugger. We used the Zend Debugger V5.2.10. Operating system You need an operating system capable of running all of the above. We used Mac OS X when creating this series, but you can use a modern version of Windows® or Linux®, as well. Adjust locations of files accordingly. Section 2. Introducing the PHP Development Toolkit The PDT hit its 1.0 release in September 2007, so what are you waiting for? Let's start using the PDT and becoming more productive PHP developers. Why an IDE? Of course, one of the beauties of PHP is that you can accomplish much with very simple tools. You can write code directly in a "live" directory on your Web server, point your browser to the page, and voilà! Need to change the code? Just modify it PHP development tools © Copyright IBM Corporation 1994, 2008. All rights reserved. Page 3 of 41 developerWorks® ibm.com/developerWorks with a text editor and refresh your browser. Who needs an IDE? Applications can start out simple, but inevitably become more complex. The second law of thermodynamics (entropy increases over time) applies as much to software engineering as it does to Maxwell's demon (see Resources if you find these metaphors are a bit obscure). For most developers, it is much easier to develop such systems if they have a debugger to stop the execution of code, step through the code, examine the state of the application, etc. Complex applications usually involve multiple developers working on them. Source control usually comes into play, and it's nice to have that integrated into your development environment. Using source control often involves keeping your source and execution environments (Web server, typically) separate. In that case, it's nice to have a development environment that makes it easy to deploy code to your Web server for you. PHP development almost always involves working with a database, as well. Of course, you can use command-line and text-based tools for working with a database. Or you can use a graphical program to make this easy. It's nice if your graphical environment is integrated in to your development environment. There's that term: Integrated Development Environment. The PDT is definitely just that. Why PDT? Let's assume you're convinced an IDE offers advantages for PHP development. The PDT is not the first or only IDE for PHP. There are some highly regarded commercial IDEs for PHP. Eclipse PDT is free of charge and is open source. It's built on Eclipse, which means that you get all of the advantages of the Eclipse Platform. It is cross-platform, so you can use it on Windows, Mac OS X, or the Linux distribution of your choice. There's a huge ecosystem of plug-ins for Eclipse and, thus, for PDT, so you can add on specialized functionality as needed, as well as develop in other languages as needed. Let's take a look at just what you get with the PDT. What do you get? We've said that the PDT is simply a collection of plug-ins for the Eclipse Platform. Each plug-in provides specific functionality designed to enhance your productivity. The core PHP plug-ins provide syntax highlighting, syntax hints, and integrated look-up of all PHP core functions. It integrates with your Web server and lets you easily deploy your code to the Web server. You can view the page in an internal Web browser or you can designate an external browser (Firefox, Internet Explorer, Safari, etc.) for viewing your pages. As mentioned, one of the most valuable things you get is an integrated debugger. You can execute your PHP code directly from the PDT (it includes a PHP executable) and also debug directly that way. You can also configure your Web server to use a debug-enabled version of PHP and debug scripts running live on your Web server. PHP development tools Page 4 of 41 © Copyright IBM Corporation 1994, 2008. All rights reserved. ibm.com/developerWorks developerWorks® Last but certainly not least, you get non-PHP specific features, thanks to the extensibility of Eclipse. This includes database tools for connecting to any database (any that has a JDBC driver available, which is pretty much all databases,) creating tables, querying and updating data, etc. There's also a built-in CVS client in the PDT.