As far as I have seen the most popular method
to transfer PHP web application to remote server is FTP.
This post is not about whether it is good or bad practice,
but I would rather try explain how to automatize this procedure
using Apache Ant.
Actually Ant is the tool which Java developers use everyday.
But you do not have to work with Java projects to use this handy tool.
So what is Ant?
In simple words just run scripted tasks defined in XML,
for a sake of automatizing things.
Would not it be nice to be able to upload application files to ftp
and clean cache by only running a single command?
Of course, but how to do it?
Here is how – a simple script
that you just put into the root of your web application
- ant.xml::
<project name="my symfony2 website" default="upload" basedir=".">
<!-- Include config file containing FTP credentials -->
<property file="build.properties" />
<!-- This target will do all required job -->
<target name="upload">
<!-- Clean cache of web application on ftp server -->
<ftp action="delete" server="${ftp.server}" userid="${ftp.user}"
password="${ftp.password}" remotedir="${ftp.dir}/app/cache"
verbose="true" passive="yes">
<fileset>
<include name="**/*"/>
</fileset>
</ftp>
<!--
Upload three directories to their respective locations on ftp server
-->
<ftp server="${ftp.server}" userid="${ftp.user}"
password="${ftp.password}" remotedir="${ftp.dir}/app"
binary="yes" verbose="false" passive="yes" >
<fileset dir="app">
<include name="**/*" />
<exclude name="cache/" /><!--Everything but the cache -->
</fileset>
</ftp>
<ftp server="${ftp.server}" userid="${ftp.user}"
password="${ftp.password}" remotedir="${ftp.dir}/src"
binary="yes" verbose="false" passive="yes" >
<fileset dir="src">
<include name="**/*" />
</fileset>
</ftp>
<ftp server="${ftp.server}" userid="${ftp.user}"
password="${ftp.password}" remotedir="${ftp.dir}/public_html"
binary="yes" verbose="false" passive="yes" >
<fileset dir="web">
<include name="**/*" />
</fileset>
</ftp>
<!--
Note how the last task here uploaded contents
of our local web directory
to the public_html on the server,- this is because Symfony2 default
directory structure is not the same as the structure on my server -->
</target>
</project>
and settings defined in build.properties:
#Ftp settings
ftp.server=server.url
ftp.user=username
ftp.password=password
ftp.dir=/dir
The script with deploying instructions is now ready,
but we need to install Ant itself
Install Apache Ant with Ftp task on Ubuntu
As and everything on ubuntu it installs like:
# sudo apt-get install ant
But this is not sufficient to run ftp task,
so we have to install libcommons-net-java:
# sudo apt-get install libcommons-net-java
By doing this file /usr/share/java/commons-net.jar
and /usr/share/java/oro.jar should be created.
It is now possible to execute FTP tasks by running command:
$ ant -lib /usr/share/java/commons-net.jar:/usr/share/java/oro.jar
By linking this file to where Ant is installed:
$ sudo ln -s /usr/share/java/commons-net.jar /usr/share/ant/lib
$ sudo ln -s /usr/share/java/oro.jar /usr/share/ant/lib
we can achieve that we do not have to add the lib as a parameter,
so we could simply run:
$ ant
in order to execute upload task
Install Apache Ant with Ftp task on Windows 7
In windows this might not be so trivial
as first you have to download Ant [http://ant.apache.org/] and extract it.
Search in start menu for “Edit system environment variables” and open it.
Add new system variable ANT_HOME with value of “C:ant”
(or something regarding to where you extracted ant binaries).
Also adjust “Path” variable – add aditional path “%ANT_HOME%\bin” to it.
Download commons-net [http://commons.apache.org/net/download_net.cgi]
and jakarta-oro [http://archive.apache.org/dist/jakarta/oro/] jars
and place them into C:antlib.
But when you run ant you will get an error,
it complains about some permission denied.
This is good windows firewall standing on the way,-
turn it off by this command:
netsh advfirewall set global StatefulFTP disable
Try to run upload script and it should work.
Run Apache Ant Ftp task within Eclipse
All you have to do in Eclipse Preferences is in
Ant -> Runtime -> Classpath to Ant home entries
add jars commons-net and jakarta-oro.
After doing this you should be able to run Ant within Eclipse like this:

To run it press Alt + Shift + X Q
There are comments.