Install Sonarqube with PostgreSQL

Hi! I’m about to introduce you a small step-by-step HowTo of Sonarqube + PostgerSQL installation on CentOS Minimal.

What is SonarQube?

SonarQube is an open source platform for continuous inspection of code quality to perform automatic reviews with static analysis of code to detect bugs, code smells and security vulnerabilities on 20+ Programming language including Java (including Android), C#, PHP, JavaScript, C/C++, COBOL, PL/SQL, PL/I, ABAP, VB.NET, VB6, Python, RPG, Flex, Objective-C, Swift, Web and XML.

First Steps

First, you need to prepare a Linux server as a platform for SonarQube application. For example, you can use Vagrant for that purposes. In my case I use CentOS 7 Minimal:

[dmitriy.unterov@localhost ~]$ uname -a
Linux localhost.localdomain 3.10.0-693.11.1.el7.x86_64 #1 SMP Mon Dec 4 23:52:40 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[dmitriy.unterov@localhost ~]$ cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)

For complete this tutorial we need to install the following packages:

  • java
  • wget
  • unzip
sudo yum install wget java unzip

Great! Next we have to download and unzip a SonarQube package. You can get a link to tha latest Package on the official site.

cd sonarqube-6.7

Nice. But we still have no DB! Let’s fix it!


Again, installation of packages in Linux (if they exist in repository =) is easy as 1-2-3.

sudo yum install postgresql-server postgresql-contrib
sudo postgresql-setup initdb

On that moment we need to configure postresql with the following:

sudo vi /var/lib/pgsql/data/pg_hba.conf

Make sure, that you changed METHOD to md5

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all               md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                peer
#host    replication     postgres            ident
#host    replication     postgres        ::1/128                 ident
#host    replication     sonar             ident

And finally we have to start postgres daemon and enable it with systemctl:

sudo systemctl start postgresql
sudo systemctl enable postgresql

Make Them Work Together!

Ok, for now we have all components we need. But they still don’t work. To fix it we need to create a ‘user’ and base for SonarQube instance. Just FYI: During PostgreSQL installatin user ‘postgres’ was created. So, let’s create a password for it and do the following:

passwd postgres
su - postgres
createuser sonar
ALTER USER sonar WITH ENCRYPTED password 'sonar';

Done! Next, we are going to config SonqrQube by editing ./conf/sonar.propertie file (I hope you are still in the root of sonarqube install directory?)

vi conf/

You have to uncomment a number of strings and edit a couple of them:


By the way, if you use a CentOS firewall you may type the following:

sudo firewall-cmd --add-port=9000/tcp --permanent
sudo firewall-cmd --reload

It will permanently add TCP port 9000 to the accepted ports’ list.

The Last Step

Now we are ready to the Triumph!

./bin/linux-x86-64/ start

Please note, that you should run it without a sudo. Now open a web browser and type

http://yourserverip:9000 (you can get you ip with ip a command)

You should see the sonarqube’s login page like this

SonarQubes's main screen

As a conclusion, I want to say that is not an official manual or a full guide. It is a small HowTo (and a basically a memo for me). But if it was useful to you - you’re welcome!

See you!.

Written on December 10, 2017