Step by Step guide to install SonarQube on Ubuntu Server


It’s been very simple to run a static code analysis tool on any project developed in any language. Here I am targeting a PHP project and SonarQube Installation on Ubuntu OS.

This is a step by step guide to install and run SonarQube on Ubuntu.


  • Oracle JRE 8 onwards or OpenJDK 8 onwards
sudo apt-get install oracle-java8-installer


  • Database
    • MS Sql Server :
      • 2012 (MSSQL Server 11.0) with bundled Microsoft JDBC driver.
      • 2014 (MSSQL Server 12.0) with bundled Microsoft JDBC driver.
    • MySql :
      • 5.6
      • 5.7
      • Note : Only innoDB is supported not MyIsam
    • Oracle :
      • 11G with Oracle 11.2.x drivers
      • 12C with Oracle 11.2.x drivers
  • Hardware Requirements
    • The SonarQube server requires at least 2GB of RAM to run efficiently and 1GB of free RAM for the OS.



  • Download and unzip the SonarQube distribution (let’s say in “C:\sonarqube” or “/opt/sonarqube”)
  • Start the SonarQube server:
    • On other operating system,Open the console and execute:
bash /opt/sonarqube/bin/[OS]/ console


Note : The above command will not register sonar as service. So once the user will    press ^C , process will be terminated.

  • To register sonar as a service you will first need to setup the sonar server.


Creating Mysql database

  • Install the mysql database
  • Open the command prompt to login mysql database using following command
Mysql -u <username> -p<password>


  • Create a new database to store sonar results.


GRANT ALL ON sonar.* TO ‘sonar’@’%’ IDENTIFIED BY ‘sonar’;

GRANT ALL ON sonar.* TO ‘sonar’@’localhost’ IDENTIFIED BY ‘sonar’;



Editing Properties file

  • Edit the ‘conf/’ file and remove the # against the following line to use embedded Mysql server.


  • Uncomment and use mysql credentials for below lines



Register Sonarqube as service

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

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

sudo gedit /etc/init.d/sonar


Insert two new lines:




Modify the following lines:




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


Start SonarQube server either by typing the direct command:

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


or by typing the service command:

sudo /etc/init.d/sonar start


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

Stop SonarQube server either by typing the direct command:

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


or by typing the service command:

sudo /etc/init.d/sonar stop


After Sonarqube started

SonarQube will start creating database tables. Then  web process will up.


Installing Sonar-Scanner to run the analysis

  • Download the sonar-scanner from the link or wget command using command prompt.
  • Unzip the zip file and place the sonar-scanner folder into /opt
  • Use command ‘sudo nano /opt/sonar-scanner/conf/’ to edit the configuration file.
    • Un comment  and update the URL of sonarqube as value i.e.,<url>:9000/sonar/
  • Create a ‘’ file into root folder of project using following code
# must be unique in a given SonarQube instance

sonar.projectKey=<project key given in sonar portal while adding project into it>

# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.

sonar.projectName=<Project name>

sonar.projectVersion=<Project version (this is important because after every analysis sonarqube compares with previous verion)>

# Path is relative to the file. Replace “\” by “/” on Windows.

# Since SonarQube 4.2, this property is optional if sonar.modules is set.

# If not set, SonarQube starts looking for source code from the directory containing

# the file.


sonar.exclusions=**/*.js, **/stats.php

# Encoding of the source code. Default is default system encoding



  • Now user need to go to root folder of project and run following command to run the code analysis
sudo bash /opt/sonar-scanner/bin/sonar-scanner