Now that we have our instance set up and we are connected to it successfully, it is time to add the required tools and components to it. Basically, it is a fresh Ubuntu box with nothing on it. To make it act like a CI server, we need to install LAMP (Linux, Apache, MySQL, and PHP), Jenkins, and a few other libraries.
Installing Apache
Having the Linux in place already, let's start by installing the Apache web server:
Before installing anything, first of all, update your Linux packages and install English language packs and locales:
$ sudo apt-get update
Then, install the locale package as follows:
$ sudo apt-get install language-pack-en
Now we can install Apache2 and some required modules to proxy the Jenkins server:
Finally, we need to set up a virtual host for our Jenkins application. To do so, create a new jenkins.conf file and add the following content to it:
$ sudo vim /etc/apache2/sites-available/jenkins.conf<VirtualHost *:80> ServerName ec2-54-79-31-45.ap-southeast-2.compute.amazonaws.com ProxyRequests Off <Proxy *> Order deny,allow Allow from all </Proxy> ProxyPreserveHost on ProxyPass / http://localhost:8080/</VirtualHost>
Now enable the site:
$ sudo a2ensite jenkins
Restart Apache:
$ sudo apache2 reload
To test your installation, simply fire a browser window and visit your hostname (in my case, ec2-54-79-31-45.ap-southeast-2.compute.amazonaws.com). If everything is set up properly, you should be able to see a welcome page as follows:
So far, we set up a free AWS account, created an EC2 instance (a Ubuntu virtual machine), and installed a LAMP stack and Jenkins in it. Now we are ready to configure Jenkins.
Setting up security and installing plugins in Jenkins
We need some sort of security to make sure that only an authorized user can access and manage Jenkins:
First, we need to set the security. Navigate to Manage Jenkins | Configure Global Security and check the Enable security box:
Note that the options you choose for your security are totally dependent on your projects and needs. For this book, select the options that you see in the preceding image.
As soon as you press the Save button, you will be asked for a username and password. Simply click on the Jenkins link on top of the page to lead to a sign-up page. Fill in the form here and press Sign up:
Now, we need to install plugins required for CI. Navigate to Manage Jenkins | Manage Plug-ins, and you will see that there are some plugins installed already in the Updates tab. Before installing any new plugins, select them all and update them:
When you press the Download now and install after restart button, a progress page shows up with the list of plugins to install. Check the option at the bottom of this page to restart Jenkins:
Note
Note that when you restart Jenkins, it might take a couple of minutes and ask you to log in again.
Now, go to the Manage Plug-in page again and visit the Available tab this time. On the search field, look for the following plugins one by one, select them, and when they are all selected, download and install them. Each plugin should be self-explanatory, but if you want more details about each one of them, visit their websites and read the documentation:
GitHub (access to GitHub repositories)
Checkstyle (reading CodeSniffer logs in the Checkstyle format)
Clover PHP (processing PHPUnit's Clover log file)
Crap4J (processing PHPUnit's Crap4J XML log file)
DRY (processing phpcpd logs in the PMD-CPD format)
HTML Publisher (publishing documentation generated by phpDox, for instance)
JDepend (processing PHP_Depend logs in the JDepend format)
Plot (processing phploc CSV output)
PMD (processing PHPMD log files in the PMD format)
Violations (processing various log files)
xUnit (processing PHPUnit's JUnit XML log file)
Apart from adding the GitHub plugin to Jenkins, we need to go back to our instance terminal and install Git here:
$ sudo apt-get install git
Now security settings and required plugins are in place and ready to set up management settings. Before that, we need to set up a mail server. This mail server will act as a notification system. In other words, every time a build is made successfully or fails or some reports are generated during CI, we need to be informed about it. So we need a mail server to send these notifications to us.
AWS comes with a service to handle e-mails, and we are about to see how to use it in our project.