Phing

phing

Using SSH and SCP in Phing

Phing allows the running of SSH commands on servers and the copying of files to servers via SCP. Before you can use SSH and SCP commands in Phing you need to install the PECL extension SSH2. The SSH2 PECL extension requires the libssh2 package, so you need to install that before you can get started. The following install instructions are based on a Linux environment.

Download the libssh2 package from www.libssh2.org and install it by using the following commands. Your package version may vary.

Getting Time And Date Values In Phing

The tstamp task in Phing can be used to generate a timestamp that can be used anywhere within the current project. The default behavior of tstamp is to create the properties DSTAMP, TSTAMP and TODAY, which contain time and date values. All you need to do is include the tstamp XML tag in your project somewhere.

<tstamp />

The properties DSTAMP, TSTAMP and TODAY use the PHP strftime() function as a basis for formatting the time. The following table shows the value of each property.

Deploy PHP Project From SVN Using Phing

Automatic building with Phing makes deploying to a server nice and easy, and if you are using SVN as your source control system then you can easily deploy directly from your repository to your web server.

To allow Phing to utilise an SVN server you must first install the VersionControl_SVN pear library. Although this is in alpha release I have used it quite a bit with no issues. The only thing is that you will need to specify the version number to pear if you want to install it, like this:

Using Phing To Deploy To FTP

Although most developers might not like it FTP is quite a common way of deploying the files for a site to the server. To simplify this process Phing comes with a handy FTP transfer action called ftpdeploy.

In order to use the ftpdeploy we first need to install the Net_FTP package. To install this package just enter the following command:

pear install Net_FTP

The first thing we need to create is a build.properties file to store our ftp details

Drupal Files Migration Script Using Phing

The other day I needed to copy a Drupal project from my source folder to another folder, so rather than manually copy the files I decided to create a Phing script that would do it for me in one go. This Phing script will export your Drupal project into another directory, change the database credentials and create zip and tar files of the project. The first thing to do is create a properties, here is the contents of that file.

Using Different Loggers In Phing

When you run a phing script it will print things out to the console. These messages are either system messages (eg. BUILD STARTED) or echo messages that you have put into your build.xml file. All of this output is controlled and created by a logger file. The default logger is called (unsuprsingly) DefaultLogger and will be used as a default. There are a few different types of logger available, all of which can be found in the listener folder in your PEAR\phing directory.