sonnar qube installation

1

Launch EC2 Instance

  • Log in to AWS Management Console.

  • Launch an EC2 instance:

    • Choose Amazon Linux 2 or Ubuntu Server.

    • Select instance type (e.g., t2.medium or better recommended for SonarQube).

    • Configure security groups to allow inbound ports:

      • SSH (port 22) for access

      • HTTP (port 9000) for SonarQube UI

2

Connect to EC2 Instance

Use SSH to connect to your instance from your terminal:

ssh -i /path/to/your-key.pem ec2-user@<EC2-PUBLIC-IP>
3

Update System Packages

sudo yum update -y
4

Install Java (SonarQube requires Java 11 or higher)

sudo amazon-linux-extras install java-openjdk11 -y

Verify Java installation:

java -version
5

Create SonarQube User

Create a dedicated user to run SonarQube:

sudo useradd sonar
sudo passwd sonar
6

Download SonarQube

Navigate to /opt (or choose a directory of your preference) and download the SonarQube Community Edition:

cd /opt
sudo wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-10.0.0.60804.zip

Note: Replace the link with the current version from the SonarQube download page if needed.

7

Unzip SonarQube

sudo yum install unzip -y

Then unzip and set ownership:

sudo unzip sonarqube-10.0.0.60804.zip
sudo mv sonarqube-10.0.0.60804 sonarqube
sudo chown -R sonar:sonar sonarqube
8

Configure SonarQube

Edit the SonarQube configuration file:

sudo vi /opt/sonarqube/conf/sonar.properties
  • Set database connection if you plan to use an external database (by default it uses embedded H2 for testing).

  • (Optional) Edit sonar.web.host=0.0.0.0 to make it accessible on all interfaces.

Save and exit.

9

(Optional) Install and Configure PostgreSQL (for production)

circle-info

SonarQube recommends PostgreSQL or MySQL for production. The embedded H2 DB is suitable for testing only.

If you want PostgreSQL installed (example for Amazon Linux 2):

sudo amazon-linux-extras enable postgresql13
sudo yum install postgresql postgresql-server postgresql-devel postgresql-contrib postgresql-docs -y
sudo service postgresql initdb
sudo service postgresql start
sudo -i -u postgres psql

Then create the database and user for SonarQube inside the psql prompt.

10

Start SonarQube

Switch to the sonar user and start SonarQube:

sudo su - sonar
cd /opt/sonarqube/bin/linux-x86-64
./sonar.sh start
11

Access SonarQube Web Interface

  • Open your browser and navigate to:

    http://<EC2-PUBLIC-IP>:9000
  • Login with default credentials:

    Username: admin
    Password: admin
12

Optional — Configure SonarQube as a systemd Service

Create the systemd unit file /etc/systemd/system/sonarqube.service with the following content:

[Unit]
Description=SonarQube service
After=syslog.target network.target

[Service]
Type=forking
ExecStart=/opt/sonarqube/bin/linux-x86-64/sonar.sh start
ExecStop=/opt/sonarqube/bin/linux-x86-64/sonar.sh stop
User=sonar
Restart=always

[Install]
WantedBy=multi-user.target

Reload systemd and enable the service:

sudo systemctl daemon-reload
sudo systemctl enable sonarqube
sudo systemctl start sonarqube

If you want this adjusted for a different OS or to cover production settings with an external database, tell me which OS and database you'd like and I can adapt the steps.