Install Jenkins for PHP Continuous Integration


Jenkins for PHP Continuous Integration

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.

  1. 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]

  2. 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]

  3. Install openjdk 8, ant, git and composer:

    [bash]apt-get install openjdk-8-jdk
    apt-get install ant
    apt-get install git
    curl -sS | sudo php — –install-dir=/usr/local/bin –filename=composer[/bash]

  4. Then, install Jenkins:

    [bash]wget -q -O – | apt-key add –
    echo "deb binary/" | tee -a /etc/apt/sources.list.d/jenkins.list
    apt-get update
    apt-get install jenkins[/bash]

    1. 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
      ProxyPreserveHost on
      ProxyPass / http://localhost:8080/

    2. Enable jenkins virtualhost and restart apache:

      [bash]a2ensite jenkins
      service apache2 reload[/bash]

  5. 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
  6. Configure basic settings for Jenkins:
    1. Goto Manage Jenkins | Configure System , edit Jenkins Location information (URL + email)
    2. Under SSH Server, disable SSHD port
    3. 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.
  7. 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.
    1. We will need to install pdependphpmdphpunitphpcpd, phplocPHP_CodeBrowserphpDocumentor:

      [bash]pear channel-discover
      pear install pdepend/PHP_Depend
      apt-get install phpmd
      apt-get install phpunit
      apt-get install phpcpd
      apt-get install phploc
      chmod +x phpcb-1.1.1.phar
      mv phpcb-1.1.1.phar /usr/local/bin/phpcb
      pear channel-discover
      pear install phpdoc/phpDocumentor
      apt-get install zip unzip
      cd /usr/share/php/phpDocumentor
      composer require –dev phpdocumentor/phpdocumentor
      apt-get install graphviz[/bash]

    2. 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:// Symfony2
      cd Symfony2
      mv Symfony2/* .
      phpcs –config-set default_standard Symfony2[/bash]

  8. 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

About NhocConan

A super lazy guy who tries to write tech blog entries in English.He is lazy, so he can only write when he is in a good mood or when he is tired of coding.

Leave a comment

Your email address will not be published. Required fields are marked *