how to use phing to build php projects

by Hamid Reza Fahimi Madjd @ Jun 25, 2011

Some days ago I found a solution to build php project that called Phing.
Phing is a build framework based on Apapche Ant. If you are familiar with Ant and its role in Java *E projects, you can learn Phing very fast.
Like Ant, there is a (or more) build file named build.xml (default name) to define operations that you like occur on your project.

Now i'm going to describe it by a practical example:

Consider a php project with following structure:


I want "build.xml" do following operations:

  1. export project from subversion repository and copy it to a temp directory
  2. make an archive file and name it based on latest version number
  3. copy archive file to a remote server over ssh (scp)

I made build.xml file put following code in it:

<?xml version="1.0" encoding="UTF-8"?>
<!-- define project name and default target -->

<project name="my-project" default="dist">

<!-- define some properties (variables) -->
  <property name="path.dive.root" value="/home/hamid/temp" />
  <property name="path.dive" value="${path.dive}/${}" />

<!-- empty related temp directory (delete old one and create new one) -->
  <target name="prepare">
    <echo msg="delete and create ${path.dive} directory" />
    <delete dir="${path.dive}" includeemptydirs="true" verbose="true" failonerror="true" />
    <mkdir dir="${path.dive}" />

  <target name="build" depends="prepare">

<!-- export project from reposiroey and copy to temp directory -->
    username="username" password="password"
    force="true" nocache="true"

<!-- get latest version number and save in svn.lastrevision property -->

<!-- generate archive file name -->
   <property name="archive.filename" value="${}-v${svn.lastrevision}.tar.gz" />

  <target name="dist" depends="build">

<!-- archive directory and save it -->
    <tar destfile="${path.dive.root}/${archive.filename}" basedir="${path.dive}" compression="gzip"/>

<!-- copy archive file and copy to sources foler on remote server -->
    <scp username="username" password="password"
    file="${path.dive.root}/${archive.filename}" />

after that go to path that build file is there and type:

$ phing

cause build file name is build.xml, it's not necessary to specify it.
Also if you use PhpStorm, you can add build.xml to Phing Build tool window and deal with that inside the IDE.
Now, I did build process just in 10 Seconds instead of 5 Minutes.

I hope this example encourage you to use Phing.
You can get more detail information from its website.

phing, php

add your comment

name (required)
email (required)

not readable? sorry, click here

last tweet

Developed withDeveloped with
Clicky Web Analytics