Skip to content

Categories:

Setting up phpUnderControl on Gentoo Linux

phpUnderControl is a popular open source addon for the continuous integration tool CruiseControl. In this blog post I’ll try to explain how you can setup phpUnderControl and CruiseControl. This guide is mostly focused on getting phpUnderControl to work on a Gentoo Linux system, so some things are OS specific.

Preparing the application

I’m assuming that you already have a working PHP setup, so I’ll skip that part. The first thing we need to do is to install the required packages. CruiseControl is a Java based application, so we need to do is install the JDK:

emerge dev-java/sun-jdk

The next step is to install Xdebug. At this time Gentoo still has Xdebug version 2.0.2 in its portage system, so this will require some fine tuning

emerge dev-php5/xdebug

After the package has been emerged, we will need to locate our xdebug ebuild file, so we run:

find /usr/portage -iname "xdebug-2.0.2.ebuild"

This will return the path of where the ebuild is located, and with this path we can create a new custom ebuild, based on the 2.0.2 version:

cp /usr/portage/dev-php5/xdebug/xdebug-2.0.2.ebuild /usr/portage/dev-php5/xdebug/xdebug-2.0.5.ebuild

Now we need to tell Gentoo that it should ignore our mirror list, and use the package url from the ebuild file:

nano /usr/portage/dev-php5/xdebug/xdebug-2.0.5.ebuild

and add the following line to the top of the file:

RESTRICT="mirror"

Save the file, and create the digest:

ebuild /usr/portage/dev-php5/xdebug/xdebug-2.0.5.ebuild digest

We will now have to do the exact same thing, but for the xdebug client.

cp /usr/portage/dev-php/xdebug-client/xdebug-client-2.0.2.ebuild /usr/portage/dev-php/xdebug-client/xdebug-client-2.0.5.ebuild
nano /usr/portage/dev-php/xdebug-client/xdebug-client-2.0.5.ebuild

and again we add the following line to the top of the file:

RESTRICT="mirror"

Save the file, and create the digest:

ebuild /usr/portage/dev-php/xdebug-client/xdebug-client-2.0.5.ebuild digest

Our custom ebuild for Xdebug 2.0.5 is now ready to be compiled, so let’s emerge it again:

emerge =dev-php5/xdebug-2.0.5

Once the build is done we should check if the proper Xdebug version is loaded. To do so, execute the following command:

php -v | grep Xdebug

If everything went well, you should see something like “with Xdebug v2.0.5, Copyright (c) 2002-2008, by Derick Rethans”. The version 2.0.5 is the important part here.

In the next step we need to install a couple of PEAR packages. I’m assuming you already have a working version of PEAR installed, or know how to set it up, as it’s fairly simple.

pear channel-discover pear.phpunit.de
pear install --alldeps phpunit/PHPUnit
pear install PHP_CodeSniffer
pear install --alldeps phpunit/phpUnderControl

Installing CruiseControl & phpUnderControl

In this part we will download the CruiseControl archive, and extract it

cd /opt
wget http://heanet.dl.sourceforge.net/sourceforge/cruisecontrol/cruisecontrol-bin-2.8.2.zip
unzip /opt/cruisecontrol-bin-2.8.2.zip
mv -f cruisecontrol-bin-2.8.2 cruisecontrol
phpuc install /usr/local/cruisecontrol

By default, cruisecontrol doesn’t have a start-up script, so let’s create it in /etc/init.d/cruisecontrol:

#!/sbin/runscript

PIDFILE=/opt/cruisecontrol/cc.pid

start() {
ebegin "Starting CruiseControl"
cd /opt/cruisecontrol/
./cruisecontrol.sh > /dev/null 2>&1
eend $?
}

stop() {
ebegin "Stopping CruiseControl"
start-stop-daemon --stop --quiet --pidfile $PIDFILE
rm -f $PIDFILE
eend $?
}

Set the file to have executable rights, and start the cruisecontrol server:

chmod +x /etc/init.d/cruisecontrol
/etc/init.d/cruisecontrol start

If everything worked, you should now be able to browse to http://yourhost:8080/dashboard/, and you should see a working cruisecontrol server page. If you don’t,  have a quick look at the cruisecontrol logs in /opt/cruisecontrol/cruisecontrol.log to find out what might be the problem.

Let’s stop the CruiseControl server for now:

 /etc/init.d/cruisecontrol stop

Adding your project to phpUnderControl

phpUnderControl ships with a command line tool which allows you to automatically create CruiseControl XML configuration files. The following example assumes that CruiseControl has been installed into /opt/cruisecontrol.

phpuc project --version-control svn --version-control-url svn://yourhost/trunk --test-case AllTests --test-file AllTests.php --test-dir tests --project-name ProjectName /usr/local/cruisecontrol

After you’ve run this comand, phpUnderControl will create a build file for you in /opt/cruisecontrol/projects/<projectname>/build.xml.
However, the file which phpUnderControl automatically creates for you is a little bit outdated. Fire it up with your favorite editor, and make sure it looks something like the following:


<?xml version="1.0" encoding="UTF-8"?>
<project name="ProjectName" default="build" basedir=".">
 <target name="build" depends="checkout,phpunit"/>
 <target name="checkout">
   <exec executable="svn" dir="${basedir}/source" failonerror="on">
     <arg line="up"/>
   </exec>
 </target>
 <target name="phpunit">
   <exec executable="phpunit" dir="${basedir}/source/tests" failonerror="on">
     <arg line="--log-junit ${basedir}/build/logs/phpunit.xml --coverage-html ${basedir}/build/coverage AllTests"/>
   </exec>
 </target>
</project>

You could now do a Ant testrun, and if it succeeds you can start the CruiseControl server again:

/opt/cruisecontrol/apache-ant-1.7.0/bin/ant -f /opt/cruisecontrol/projects/ProjectName/build.xml
/etc/init.d/cruisecontrol start

Go to http://yourhost.com:8080/cruisecontrol/, have a beer and celebrate. You are now ready use the full benefits of continuous integration.

Other resources

Posted in PHP.

Tagged with , , , .