Installing SonarQube on Ubuntu


Java JRE
DBMS (MySQL in my case)

Create SonarQube database and user

First run MySQL through terminal:

mysql -u root -p

Then create database and user:
CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER 'sonar' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar';
FLUSH PRIVILEGES;

Download and unzip SonarQube distribution

Visit the SonarQube official site for the current version.

wget http://dist.sonar.codehaus.org/sonarqube-5.0.1.zip
unzip sonarqube-5.0.1.zip
mv sonarqube-5.0.1 /opt/sonar

Edit sonar.properties

Open /opt/sonar/conf/sonar.properties with your favourite text editor, and modify it.

MySQL settings

Comment out the H2 setting, and comment in the MySQL related settings

#sonar.jdbc.url=jdbc:h2:tcp://localhost:9092/sonar
...
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.jdbc.driverClassName=com.mysql.jdbc.Driver
sonar.jdbc.validationQuery=select 1
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true

Web Server settings
The following settings allow you to run the server on page
http://localhost:9000/sonar

sonar.web.host=127.0.0.1
sonar.web.context=/sonar
sonar.web.port=9000

Implement SonarQube server as a service [optional]

Copy sonar.sh to etc/init.d/sonar and modify it according to your platform.

sudo cp bin/linux-x86-64/sonar.sh /etc/init.d/sonar
sudo gedit /etc/init.d/sonar

Insert two new lines:
SONAR_HOME=/opt/sonar
PLATFORM=linux-x86-64

Modify the following lines:
WRAPPER_CMD="${SONAR_HOME}/bin/${PLATFORM}/wrapper"
WRAPPER_CONF="${SONAR_HOME}/conf/wrapper.conf"
...
PIDDIR="/var/run"

Register as a Linux service:

sudo update-rc.d -f sonar remove
sudo chmod 755 /etc/init.d/sonar
sudo update-rc.d sonar defaults

Create Desktop icons [optional]
Install gnome-panel if missing:
sudo apt-get install gnome-panel --no-install-recommends
Open Dialog for creating new item for starting SonarQube:
sudo gnome-desktop-item-edit /usr/share/applications/ --create-new

Copy the item to the Desktop:
sudo cp /usr/share/applications/SonarQube\ Start.desktop /home/user/Desktop/

Open Dialog for creating new item for stopping SonarQube:
sudo gnome-desktop-item-edit /usr/share/applications/ --create-new

Copy the item to the Desktop:
sudo cp /usr/share/applications/SonarQube\ Stop.desktop /home/user/Desktop/

Run SonarQube server

Start SonarQube server whether typing the direct command:

sudo /opt/sonar/bin/linux-x86-64/sonar.sh start

or typing the service command:

sudo /etc/init.d/sonar start

or clicking on the SonarQube Start icon which was created before (with password).

Visit SonarQube web page at http://localhost:9000/sonar

Stop SonarQube server whether typing the direct command:

sudo /opt/sonar/bin/linux-x86-64/sonar.sh stop

or typing the service command:
sudo /etc/init.d/sonar stop

or clicking on the SonarQube Stop icon which was created before (with password).

TechieQA

Dharma is a QA for more than 3 years of experience in Android and iOS application testing and developement.Like to explore all domain and new technologies.

No comments: