Configure, Package and Deploy Php projects : Part 1

Configuring , packaging and deploying is often tedious process. In this series of article we will learn about how to make automate this tasks.

In this tutorial series we will create a build configuration to build, configure and deploy php application to the cloud. Most cloud servers will give you ssh tools so we will deploy using scp or sftp commands.

In this first part, we will crate build files for Phing tool.

We use Phing to configure and package the project. We create Build.xml, other configuration files and properties file those will be used by Phing to configure and package the application.


		<?xml version="1.0" encoding="UTF-8"?>
<project name="MyApplication" default="main" basedir=".">
    <property file="./build/properties/" />
        <isset property="build.env" />
            <echo message="Overwriting with ${build.env}.properties" />
            <property file="./build/properties/${build.env}.properties" override="true" />

    <target name="main">
        <echo message="+------------------------------------------+"/>
        <echo message="|                                          |"/>
        <echo message="| Building The Project                     |"/>
        <echo message="|                                          |"/>
        <echo message="+------------------------------------------+"/>
 	<phing phingfile="${project.basedir}/build/build-configuration.xml" target="configuration" />
       <zip destfile="" basedir="./php">
            <include name="*" />



build.xml defines the main task, it performs the following tasks.

Loads default properties file and overrides it with environment property file if specified. Configures the project based on the configuration file. Packages the base project folder in a zip file.

build/properties/ =
db.user = root
db.password = root
db.database = foobar

build/properties/ =livehost
db.user = realuser
db.password = dottellme
db.database = livedb


    <?xml version="1.0" encoding="UTF-8"?>
<project default="configuration">

    <target name="configuration">
        <echo msg="Building configuration..." />
        <copy todir="${project.basedir}/php/application/config/" overwrite="true">
            <filelist dir="${project.basedir}/build/templates/" files="" />
            <mapper type="regexp" from="^(.*).build$" to="\1"/>

                <expandproperties />


build-configuration file creates the database configuration file using the template file and properties file and copies to the relevant application folder. In the above example it creates database.config and copies to the php/application/config folder (database configuration file for codeigniter based php project).

php is our main application folder.

See below the template file has parameters that will be replaced by values from the properties file.

$db['default']['hostname'] = '${}';
$db['default']['username'] = '${db.user}';
$db['default']['password'] = '${db.password}';
$db['default']['database'] ='${db.database}';
        <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = ${};
$db['default']['username'] = '${db.user}';
$db['default']['password'] = '${db.password}';
$db['default']['database'] ='${db.database}';

$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
$db['default']['active_r'] = TRUE;

/* End of file database.php */
/* Location: ./application/config/database.php */ 

In this next part we will crate build configurations on the teamcity server.

Configure, Package and Deploy Php projects : TeamCity Part 2

Alternatively you can use batch file to automate the task if you don't like to install php server.

Like us

See also

Configure, Package and Deploy PHP applications using Phing and SSH

Alternative method to Teamcity, we can use simple batch files to run the phing commands and other ssh commands.

Configure, Package and Deploy Php projects : TeamCity Part 2

In this part we create build configurations to actually make use of build files on the previous article and deploy to the cloud using ssh commands.

MSBuild integration on Cruise.Net

Here is the basic steps on how to integrated msbuild task on open source to automatic your visual studio builds.