Deploying your Site with phpEclipse - Using Ant for Deployment
(Page 3 of 4 )
You may have heard of Ant in the Java development world. Being a pure Java tool, Ant is often called 'the Java version of make'. With Ant, you create scripts called build files that are interpreted by the Ant parser. These scripts aid you in Java development by compiling your code and deploying it in your build directory. For both small home-grown projects and large Java enterprise environments, Ant has become an absolutely critical tool for Java developers. In the PHP world, though, we do not have any code to compile, and often, FTP is adequate for moving files into production. Why, then, as PHP developers, do we care about Ant?
In some business environments, production web servers are tightly controlled. Developers are not allowed anywhere near the servers, let alone pushing out code at their whim. The sheer act of deploying new code often occurs only after a long ritual of meetings and approvals at various levels. In these environments, deployment occurs with a script that automates the delivery of an application from one area to the production site. Ant scripts can do this job for you for applications in any language.
Even if you are not working in such an environment, why would you use Ant? A key benefit is Ant's integration with CVS and Subversion. Using Ant, you can write a script to grab all files in the repository with a certain tag and FTP them to a production server. Imagine the time saved and reduction in human error with this. In a large application with PHP class files in one directory, HTML view files in another, JavaScript files in their own separate directory, and stylesheets in yet another, a deployment involves a huge effort and it is difficult to keep track of what has changed.
At deployment time, you have to check out all the correct files from CVS or Subversion and then FTP all of them again to the production web server. If all you have to do is tag a file at the end of testing, you have drastically reduced the chance that you'll miss something when retrieving from the code repository or FTPing.
Finally, Ant scripts are easy to write. Being XML-based, these scripts are fairly simple and intuitive. If we were not concerned with code cleanliness, it would take only one line of code to check out a project from the code repository, and another line to FTP files. The reference documentation is excellent. If you require any more support, Ant is supported by a large user base and online community. Being an Apache Foundation project doesn't hurt its popularity either.
Eclipse integrates Ant smoothly into our development environment. Included with the JDT, Eclipse has a nice Ant editor, templates, and tag help. You can execute them directly from Eclipse. Let's walk through an example using CVS.
The official Ant release does not support Subversion. Luckily, Ant employs an extensible architecture like Eclipse. Tigris.org, the developer of Subversion, has created an Ant task called svnAnt that allows Ant to interface with Subversion repositories. More information about this proect is available at http://subclipse.tigris.org/svnant.html
Next: Setting up Ant for FTP >>
More Web Authoring Articles
More By PACKT Publishing
|
This article is excerpted from PHPEclipse: A User Guide, written by Shu-Wai Chow (Packt Publishing, 2006; ISBN: 1904811442). Check it out today at your favorite bookstore. Buy this book now.
|
|