Install Sonar 3.5.1 With MySQL On Tomcat 7 Running Ubuntu 13.04

Overview

This post assumes MySQL is already installed.

Create an empty schema for Sonar and a user with create, update, index, and delete like privileges.

Tomcat 7

sudo apt-get install tomcat7

Java

sudo apt-get install default-jdk

Sonar

Download and extract sonar-3.5.1.zip form http://www.sonarsource.org/

A folder called sonar-3.5.1 should be created by default. This will be referred to as {sonar} from now on.

Create a directory where sonar will use as SONAR_HOME. This directory cannot be deleted when using Sonar and must be made available to Tomcat to write to. In this example it will reside in ~/.sonar or /home/danny/.sonar where danny is the user’s home directory.
mkdir ~/.sonar

Copy the contents of the extracted zip to SONAR_HOME
cp -R {sonar}/* ~/.sonar

Edit sonar’s properties file in ~/.sonar/war/sonar-server/WEB-INF/classes/sonar-war.properties
find the line #SONAR_HOME= and remove the # in front of SONAR_HOME= to uncomment the line. after the = (equals) enter the full path to SONAR_HOME. For example SONAR_HOME=/home/danny/.sonar Save and exit the file.

Edit ~/.sonar/conf/sonar.properties file with the database connection.
Enter the database username on line sonar.jdbc.username and password on sonar.jdbc.password.
Comment out the default H2 database by putting a hash ‘#’ (without quotes) infront of the line sonar.jdbc.url: jdbc:h2:tcp://localhost:9092/sonar.
Delete the hash ‘#’ for the MySQL connection string sonar.jdbc.url: jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true changing localhost with the server address and 3306 for the port number. Leave these as they are if MySQL is on the same server on the default port.

In the terminal go to the war directory in SONAR_HOME cd ~/.sonar/war

Make the build script executable:
chmod +x build-war.sh

Run the build file to create a deployable war file:
sh ~/.sonar/war/build-war.sh
If the build was successful it will create a sonar.war file in ~/.sonar/war directory.

Copy sonar.war file out of SONAR_HOME directory e.g cp ~/.sonar/war/sonar.war ~. The example will copy it to user’s home directory.

Change the ownership of SONAR_HOME to the Tomcat user so it can access SONAR_HOME:
sudo chown -R tomcat7:tomcat7 ~/.sonar

Deploy the sonar.war file onto Tomcat. This can be done by either copying the war file to /var/lib/tomcat7/webapps directory or through the web interface on http://localhost:8080/manager/html if Tomcat was installed and configured with default install.

Go to the sonar application page e.g http://localhost:8080/sonar/ which should display the sonar dashboard if it was deployed successfully.

On of the first things to do is to log in and change the administrator’s password. The default username and password is admin and admin.

Summary

Sonar is not the easiest to install but it is a valuable tool for checking code quality and compliance. It is however flexible in it’s setup with various database support, standalone and deployed web application.

Sonar throws exception when starting on Tomcat 6 running on OS X Server

About Danny

I.T software professional always studying and applying the knowledge gained and one way of doing this is to blog. Danny also has participates in a part time project called Energy@Home [http://code.google.com/p/energyathome/] for monitoring energy usage on a premise. Dedicated to I.T since studying pure Information Technology since the age of 16, Danny Tsang working in the field that he has aimed for since leaving school. View all posts by Danny → This entry was posted in Java, Linux, Software and tagged , , , , , , , , , . Bookmark the permalink.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.