jump to navigation

Using Phing To Deploy Your Projects via FTP September 17, 2012

Posted by Tournas Dimitrios in PHP, Uncategorized.

The last step of a web-development process is to deploy the code to a [live] hosting server (usually this is done via a FTP client) .Of course , repetition is  tedious and error prone .Fortunately for us , building-tools exists to handle all the repetitive task in an automatic manner . Phing , is a PHP project build system or build tool based onApache Ant . You can do anything with it that you could do with a traditional build system like GNU make , and it uses a simple XML build file . It’s an easy-to-use and highly flexible build framework which has an extensible  list of ready-to-run “tasks” . With just a few key-strokes we can automate tasks like : Unitests (including test result and coverage reports) , minify of js/css files , compression , file system operations , interactive build support , dB-migrations , branching to GitHub , etc… I could list a whole range a tasks , but this article will only focus on “Using Phing To Deploy Your Projects via FTP” .

Prerequisites : The reader should already be familiar with basic terminal-tasks  and fluent with handling of PEAR packages . A local development server with PHP5.2 should already “running” and a remote hosting  server with FTP access must already be “set-up” .

Phing is a PEAR-package , if it’s not already installed on your computer open up a terminal and make the installation . Our FTP-deploy task demands also another PEAR-package (Net/FTP) , so install both packages as follows .

pear   channel-discover   pear.phing.info
pear   install   phing/phing
pear  install  Net_FTP

Verify that both packages were installed successfully .

Verify that both pear packages are installed

Next step is to create Phing’s build file ,  it defines all tasks that will automatically executed . The example file follows (replace Ftp-credentials with your own)  :

<?xml version="1.0" encoding="UTF-8" ?>
<project name="FtpUpload" default="main">
   <!-- Define FTP properties file. -->
 <property name="ftp.host" value="ftp.example.com"/>
 <property name="ftp.port" value="21"/>
 <property name="ftp.username" value="user"/>
 <property name="ftp.password" value="password"/>
 <property name="ftp.destination.dir" value="/public_html/"/>
 <property name="ftp.mode" value="ascii"/>   
    <fileset dir="ftpuploads" id="srcfiles">
      <include name="zztest*.php" />
		<fileset refid="srcfiles" />
    <target name="main">
     <echo>FTP Upload Finished!</echo>

As seen on previous example , FTP-credentials were hard-coded into the build-file . Usually all configurations are written into an external file and imported with the following command.

<!-- Include properties file. -->
<property file="ftp.build.properties">

And the ftp.build.properties file should have the following structure :


Name the buil-file as  ftpbuild.xml (the name is up to you) and move it into the root directory of your project . Open the terminal into your project’s  root location and run :  phing  -f  ftpbuild.xml . The project will automatically  deployed to your hosting server .

The whole preparation process (installing packages and writting a build-file)  has only to be done once . Thereafter  each deployment is only one single line of code .  Even your IDE can be configured to “run”  Phing just by clicking one button (without the need to open a terminal) .


1. akuba - September 26, 2012

Having read this I believed it was rather
enlightening. I appreciate you spending some time and energy to put this information together.
I once again find myself spending way too much time both reading and leaving comments.

But so what, it was still worth it!

2. Mark - October 12, 2012

this was a really quality post. in theory i’d like to write like this too. taking time and real effort to make a good article.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s