Posts about the PHP build package Phing

Phing Logo

Deploy PHP Project From SVN Using Phing

16th November 2010 - 6 minutes read time

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:

pear install VersionControl_SVN-0.3.4

To get Phing to export from an SVN repository you can use the svnexport task. The following build file sets up some parameters (for use in this task), runs a target to delete the existing export and then runs a target that exports from the SVN repository we have set up.

Read the full article

Phing Logo

Using Phing To Deploy To FTP

31st January 2010 - 3 minutes read time

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 file to store our ftp details

Read the full article

Phing Logo

Drupal Files Migration Script Using Phing

24th November 2009 - 5 minutes read time

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.

Read the full article

Phing Logo

Using Different Loggers In Phing

17th November 2009 - 9 minutes read time

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 (unsurprisingly) 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.

To select a different logger script to be used just use the -logger flag in your phing call. To specify the DefaultLogger use the following:

phing -logger phing.listener.DefaultLogger

To specify an XML logger that will create an XML document of the phing events that occurred in the current working directory use the XmlLogger logger.

Read the full article

Phing Logo

Integrating Phing With PHPUnit

16th January 2009 - 3 minutes read time

PHPUnit is a unit testing framework, written in PHP, and which is used to test PHP code. You can integrate the testing that PHPUnit does into Phing. You might want to use Phing to create a nightly build that contains the latest version of your program. The last thing you want is Phing to create a nightly build that is riddled with errors.

The way around this is to use PHPUnit to test our code whilst we are running Phing. If any tests fail then Phing will not finish the build.

Create a target at the top of your build.xml file and make sure it is run first. Then add the following code to the target, This will use PHPUnit to test your code.

Read the full article

Phing Logo

Create Compressed Files With Phing

15th January 2009 - 4 minutes read time

Building your projects into directories is nice, but distributing these projects is difficult if you have to build the compressed files yourself. Phing has the ability to create zip and tar files using simple commands.

The most convenient way of using the tar and zip commands is by using a fileset. But rather than use the fileset that was used to copy the files into the build directory it is best to create a separate fileset that is used to compress the contents of the build directory.

Read the full article

Phing Logo

Create A File Or Directory With Phing

14th January 2009 - 3 minutes read time

After following the last post on deleting files and directories in Phing you might now be wondering if you can create things as well. The answer is yes.

To create a directory with Phing you need to use the mkdir element. The dir attribute is used to give the name of the directory to be created. The following example will create a directory called myProject_build in the current working directory (ie. where you are running phing from).

<mkdir dir="myProject_build" />

That is about as complicated as the mkdir element gets, although you can also pass a parameter to the dir attribute.

Read the full article

Phing Logo

Deleting Directories With Phing

13th January 2009 - 3 minutes read time

Although using Phing is mainly about copying files, you might also need to delete directories and files using the delete element. Remember that the default behavior of copy command copies files only if the source files are different from the destination files. A prudent approach might be to delete the build directory and then recreate it, ready for Phing to copy files into.

To delete a directory you need to use the dir attribute of the delete element, the delete element also accepts the file attribute to delete specific files. The following target will delete the directory myProject_build.

<target name="prepare">
<delete dir="myProject_build" />

The delete element can also accept a fileset element, which will delete multiple files. the following code will delete any php file from the myProject_build folder and from a sub folder called app.

Read the full article

Phing Logo

FilterChain Element In Phing

12th January 2009 - 6 minutes read time

The FilterChain element is where the power of Phing really comes into its own. This element will allow you to change the contents of the files of a fileset. This can range from a simple stripping of comments, to replacing values and numerous other filters.

One of the simplest thing that can be done with filterset is to strip all comments from the files in question. Take the following PHP file with two comments.

 * This is a comment
echo 'Hello World!';
// another comment.

These comments can be stripped out of the file by using the stripphpcomments element. This is added to the copy element in the following way.

Read the full article

Phing Logo

Built In Properties In Phing

9th January 2009 - 5 minutes read time

Aside from assigning and using your own properties Phing also comes with a set of built in properties that can be used to find out all sorts of information regarding the system that Phing is run on.

As an example, let's say you wanted to found out the operating system that phing is being run on. In this case you would use the variable host.os, which on a Windows XP system would print out WINNT.

There are a lot of different properties available, so I have included the table from the phing website at the bottom of this post as a reference. However, there is one special variable called env that needs further explanation. The env variable references any environment variables that have been set. For example, if you set an environment variable using the following shell command (on UNIX based systems only).

export TESTVAR=mytestvar

You can now reference this in your build.xml file by using the following.

Read the full article