Today I will mention how to install Jenkins and necessary plugins/tools for doing Continuous Integration. This is just a very first step of using Jenkins for PHP Continuous Integration work.
I choose to start with a Virtual Machine with Ubuntu 16 and use LAMP with PHP7 for the web stack.
- First, we will use Apache as proxy web server, so install it:
[bash]apt-get install apache2
a2enmod proxy
a2enmod proxy_http
service apache2 restart[/bash] - Next, install PHP & MySQL:
[bash]add-apt-repository ppa:ondrej/php
apt-get update
apt-get install php php-mysql php-curl php-mbstring php-xdebug mysql-client mysql-server php5.6 php5.6-mysql php-gettext php5.6-mbstring php5.6-curl php5.6-dom libapache2-mod-php5.6 libapache2-mod-php7.0
a2dismod php7.0 ; a2enmod php5.6 ; service apache2 restart
ln -sfn /usr/bin/php5.6 /etc/alternatives/php[/bash] - Install openjdk 8, ant, git and composer:
[bash]apt-get install openjdk-8-jdk
apt-get install ant
apt-get install git
curl -sS https://getcomposer.org/installer | sudo php — –install-dir=/usr/local/bin –filename=composer[/bash] - Then, install Jenkins:
[bash]wget -q -O – http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | apt-key add –
echo "deb http://pkg.jenkins-ci.org/debian binary/" | tee -a /etc/apt/sources.list.d/jenkins.list
apt-get update
apt-get install jenkins[/bash]- Create proxy from apache to jenkins at /etc/apache2/sites-available/jenkins.conf as follows:
[bash]<VirtualHost *:80>
ServerName YOUR_DOMAIN_NAME
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPreserveHost on
ProxyPass / http://localhost:8080/
</VirtualHost>[/bash] - Enable jenkins virtualhost and restart apache:
[bash]a2ensite jenkins
service apache2 reload[/bash]
- Create proxy from apache to jenkins at /etc/apache2/sites-available/jenkins.conf as follows:
- Access your jenkins website, create your first admin account and install the following plugins for doing CI with PHP: GitHub, Checkstyle, Clover PHP, Crap4J, DRY, HTML Publisher, JDepend, Plot, PMD, Violations, xUnit
- Configure basic settings for Jenkins:
- Goto Manage Jenkins | Configure System , edit Jenkins Location information (URL + email)
- Under SSH Server, disable SSHD port
- GO to the E-mail Notification section and click on the Advanced button, fill in the email info there for later notification sending. Click on Test configuration to test it.
- Install PHP tools: Note that we can use pear, composer with global scope, or install it from apt-get. My recommendation is to install from apt-get if a tool has according package, since the pear channel might be out-dated and might cause a lot of problems for processing your build.
- We will need to install pdepend, phpmd, phpunit, phpcpd, phploc, PHP_CodeBrowser, phpDocumentor:
[bash]pear channel-discover pear.pdepend.org
pear install pdepend/PHP_Depend
apt-get install phpmd
apt-get install phpunit
apt-get install phpcpd
apt-get install phploc
wget https://github.com/Mayflower/PHP_CodeBrowser/releases/download/1.1.1/phpcb-1.1.1.phar
chmod +x phpcb-1.1.1.phar
mv phpcb-1.1.1.phar /usr/local/bin/phpcb
pear channel-discover pear.phpdoc.org
pear install phpdoc/phpDocumentor
apt-get install zip unzip
cd /usr/share/php/phpDocumentor
composer require –dev phpdocumentor/phpdocumentor
apt-get install graphviz[/bash] - We will install php-codesniffer and use Symfony coding standard as the base coding standard:
[bash]apt install php-codesniffer
cd /usr/share/php/PHP/CodeSniffer/Standards/
git clone git://github.com/escapestudios/Symfony2-coding-standard.git Symfony2
cd Symfony2
mv Symfony2/* .
phpcs –config-set default_standard Symfony2[/bash]
- We will need to install pdepend, phpmd, phpunit, phpcpd, phploc, PHP_CodeBrowser, phpDocumentor:
- Finally, create your project with necessary build files (build.xml, phpmd.xml, phpunit.xml, etc.), submit to git, create a new job in Jenkins and can test the build