Skip to content

Instantly share code, notes, and snippets.

@praful-dhabekar
Last active November 9, 2023 01:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save praful-dhabekar/cef6829f7812bbfae2aa21246e6387b3 to your computer and use it in GitHub Desktop.
Save praful-dhabekar/cef6829f7812bbfae2aa21246e6387b3 to your computer and use it in GitHub Desktop.
Sonarqube installation on CentOS

Step 1: Create the directory that will hold the SonarQube files:

sudo mkdir /opt/sonarqube

Step 2: Once the directory is created, update the permissions so that the sonarqube user will be able to read and write files in this directory:

sudo chown -R sonarqube:sonarqube /opt/sonarqube

Step 3: SonarQube releases are packaged in a zipped format, so install the unzip utility using your package manager so you can extract the distribution files:

sudo apt-get install unzip

Step 4: Next, we need to create a database and credentials that SonarQube will use. Log in to the MySQL server as the root user:

mysql -u root -p

Step 5: Then create the SonarQube database:

mysql> CREATE DATABASE sonar;

mysql> EXIT;

Step 6: Now create the credentials that SonarQube will use to access the database.

mysql> CREATE USER sonar@localhost IDENTIFIED BY 'some_secure_password';

mysql> GRANT ALL ON sonar.* to sonar@localhost;

Step 7: Then apply the permission changes and exit the MySQL console:

mysql> FLUSH PRIVILEGES;

mysql> EXIT;

Step 8: Downloading and Installing SonarQube

Start by changing the current working directory to the SonarQube installation directory: cd /opt/sonarqube

Step 9: Then, head over to the SonarQube downloads page and grab the download link for SonarQube 7.0. There are two versions of SonarQube available for download on the page, but in this specific tutorial we'll be using SonarQube 7.0.

wget --header "Cookie: oraclelicense=accept-securebackup-cookie" https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-7.6.zip

Step 10: Then unzip the file:

sudo unzip sonarqube-7.0.zip

Step 11: Once the files extract, delete the downloaded zip file, as you no longer need it: (Optional)

sudo rm sonarqube-7.0.zip

Now that all the files are in place, it's time to configure SonarQube.

Step 12: Configuring the SonarQube Server

We'll need to edit a few things in the SonarQube configuration file. Namely:

We need to specify the username and password that the SonarQube server will use for the database connection.

We also need to tell SonarQube to use MySQL for our backend database.

We'll tell SonarQube to run in server mode, which will yield improved performance.

  1. sonar.jdbc.username=sonar

  2. sonar.jdbc.password=sonar (your own password)

  3. sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false Uncomment this line

  4. sonar.web.host=0.0.0.0 Uncomment this line

  5. sonar.web.context=/sonar (Optional)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment