Select Page
How to Install ProcessWire CMS on Ubuntu 18.04 LTS

How to Install ProcessWire CMS on Ubuntu 18.04 LTS

ProcessWire is a free and open source PHP-based content management system and content management framework. It is a simple, flexible and powerful CMS built to save you time and work the way you do. ProcessWire provides easy to use web interface that enables you to publish websites easily. It is specially designed for ease of use that allows you to create powerful and dynamic content websites.

Features

  • Role-based access control system.
  • Web-based graphical installer.
  • Provides fully modular plugin architecture and powerful template system.
  • Multi language support.
  • Supports rich text editing.
  • Drag-and-drop file and image uploads and editing functions.

In this tutorial, I will explain how to install ProcessWire with Apache web server on Ubuntu 18.04 LTS.

Requirements

  • A server running Ubuntu 18.04..
  • A non-root user with sudo privileges.

Getting Started

Before starting, you will need to update your system with the latest version. You can do this by running the following command:

sudo apt-get update -y
sudo apt-get upgrade -y

Once your system is updated, restart the system to apply the changes.

Install Apache, MariaDB and PHP

First, you will need to install Apache web server, MariaDB server, PHP and other PHP modules to your server. You can install all the packages by just running the following command:

sudo apt-get install apache2 mariadb-server unzip wget php7.2 php7.2-mysql php7.2-curl php7.2-json php7.2-cgi libapache2-mod-php7.2 php7.2-xmlrpc php7.2-gd php7.2-mbstring php7.2 php7.2-common php7.2-xmlrpc php7.2-soap php7.2-xml php7.2-intl php7.2-cli php7.2-ldap php7.2-zip php7.2-readline php7.2-imap php7.2-tidy php7.2-recode php7.2-sq php7.2-intl -y

Once all the packages are installed, open php.ini file and make some changes:

sudo nano /etc/php/7.2/apache2/php.ini

Make the following changes:

memory_limit = 300M
upload_max_filesize = 200M
max_execution_time = 400
date.timezone = Asia/Kolkata
sudo systemctl restart apache2
sudo systemctl restart mariadb
sudo systemctl enable apache2
sudo systemctl enable mariadb

You can now check the status of MariaDB service with the following command:

sudo systemctl status mariadb

Output:

? mariadb.service - MariaDB 10.1.34 database server
   Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2018-12-01 22:46:13 UTC; 9h ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 1317 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 1313 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
  Process: 935 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`/usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemc
  Process: 931 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 819 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
 Main PID: 1164 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 27 (limit: 2323)
   CGroup: /system.slice/mariadb.service
           ??1164 /usr/sbin/mysqld

Dec 01 22:45:54 ubuntu1804 systemd[1]: Starting MariaDB 10.1.34 database server...
Dec 01 22:46:05 ubuntu1804 mysqld[1164]: 2018-12-01 22:46:05 140324667522176 [Note] /usr/sbin/mysqld (mysqld 10.1.34-MariaDB-0ubuntu0.18.04.1) 
Dec 01 22:46:13 ubuntu1804 /etc/mysql/debian-start[1318]: Upgrading MySQL tables if necessary.
Dec 01 22:46:13 ubuntu1804 systemd[1]: Started MariaDB 10.1.34 database server.

Configure MariaDB

By default, MariaDB installation is not secured. So, you will need to secure it first. You can secure it by running the following command:

sudo mysql_secure_installation

Answer all the questions as shown below:

    Enter current password for root (enter for none):
    Set root password? [Y/n]: N
    Remove anonymous users? [Y/n]: Y
    Disallow root login remotely? [Y/n]: Y
    Remove test database and access to it? [Y/n]:  Y
    Reload privilege tables now? [Y/n]:  Y

Once the MariaDB is secured, log in to MariaDB shell:

mysql -u root -p

Provide your root password. Then, create a database and user for ProcessWire with the following command:

MariaDB [(none)]> CREATE DATABASE processdb;
MariaDB [(none)]> CREATE USER process;

Next, grant privileges to the ProcessWire database with the following command:

MariaDB [(none)]> GRANT ALL PRIVILEGES ON processdb.* TO 'process'@'localhost' IDENTIFIED BY 'password';

Next, flush the privileges with the following command:

MariaDB [(none)]> FLUSH PRIVILEGES;

Next, exit from the MariaDB console with the following command:

MariaDB [(none)]> exit

Download and Install ProcessWire

You can download the latest version of ProcessWire from Git repository using the following command:

wget https://github.com/processwire/processwire/archive/master.zip

After downloading, unzip the downloaded file with the following command:

unzip master.zip

Next, copy the extracted directory to the Apache web root directory with the following command:

sudo cp -r processwire-master /var/www/html/processwire

Next, give proper permissions to the processwire directory with the following command:

sudo chown -R www-data:www-data /var/www/html/processwire/
sudo chmod -R 777 /var/www/html/processwire/

Configure Apache for ProcessWire

Next, you will need to create an Apache virtual host file for ProcessWire. You can do this by running the following command:

sudo nano /etc/apache2/sites-available/processwire.conf

Add the following lines:


     ServerAdmin [email protected]
     DocumentRoot /var/www/html/processwire
     ServerName example.com

     
          Options +FollowSymlinks
          AllowOverride All
          Require all granted
     

     ErrorLog ${APACHE_LOG_DIR}/processwire_error.log
     CustomLog ${APACHE_LOG_DIR}/processwire_access.log combined

Save and close the file, when you are finished. Then, enable Apache virtual host file and rewrite module with the following command:

sudo a2ensite processwire.conf
sudo a2enmod rewrite

Finally, restart Apache service to apply all the changes:

sudo systemctl restart apache2

Access ProcessWire

Open your web browser and type the URL http://example.com. You will be redirected to the ProcessWire Welcome page:

ProcessWire Installer

Now, click on the Get Started button. You should see the following page:

Site Installation Profile

Select Classic site installation profile and click on the Continue button. You should see the following page:

Compatibility Check

After validating all the requirements, click on the Continue To Next Step button. You should see the following page:

Database setup

Timezone and file permissions

HTTP Host Name

Here, provide your database details like, hostname, database name, database username and password, Timezone. Then, click on the Continue button. You should see the following page:

Test Database configuration

Admin account setup

Cleanup

Here, provide your Admin login URL, admin username and password. Then, click on the Continue button. Once the installation completed successfully, you should see the following page:

Setup completed

Now, click on the Login To Admin button. You should see the following page:

Admin Login

Provide your admin username and password. Then, click on the Login button. You should see the ProcessWire default dashboard in the following page:

Admin dashboard

Install WordPress 5 with Apache on Debian 9

Install WordPress 5 with Apache on Debian 9

This tutorial will show you how to install and configure the latest version of WordPress 5 on top of a LAMP stack in Debian 9 – Stretch. WordPress, without a doubt, is one of the most popular open-source Content Management System or CMS used in these days for internet publishing, which powers more than 60 million websites worldwide, whether small blogging sites or notable huge name brands. Based on PHP and MySQL engine, WordPress is often associated with LAMP collection, either installed on dedicated servers or virtual private servers or on shared web-hosting providers. LAMP acronym describes a collection of software, aka software bundle, which usually consists of Linux Open Source kernel, regardless of the chosen distribution, Apache HTTP server, which is one of the most popular open-source web server in internet due to its stability, flexibility and performance, PHP server-side interpreted programming language and MariaDB relational database management system (RDBMS), which one of the most popular database software, forked and simultaneously developed by the open-source community from original MySQL.

Requirements

  • A clean installation of Debian 9 operating system on a virtual private server or a virtual machine or directly on a dedicated bare-metal machine.
  • SSH remote access in case of a VPS or a remote server or direct console access
  • At least a static IP Address for a network interface configured on the server
  • In case the webpage should be publicly available in internet you would need a registered public domain name with proper DNS records configured. During this tutorial, we’ll be using the example.com as the example domain and a static IP address from private space, in NAT, behind the main router. The domain will be accessible from the internet by port forwarding the Apache 80 and 443 ports from the router side to internal self-hosted virtual machine LAN.

Install LAMP Software Bundle

The first thing you want to do before starting to install all LAMP components is to log in to Debian 9 server and perform an up-to-date procedure for all system components, such as kernel upgrades, package updates or security patches, by issuing the following commands with root privileges.

apt-get update
apt-get upgrade
apt-get dist-upgrade

In the next step, you should set up the name of your machine by replacing the hostname variable with your own descriptive name by running the below command. Be aware that you might need to reboot the system in order to apply the new hostname accordingly.

hostnamectl set-hostname hostname.yourdomain.com

You should also install the following utilities which will come in handy later for various troubleshooting problems.

apt install net-tools sudo wget curl bash-completion

After the machine hostname has been applied, login again with root privileges and install Apache HTTP server, which is, by default, pre-compiled into a binary package and provided by Debian 9 repositories.

apt install apache2

Next, install the latest version of PHP language interpreter and all required modules needed for Apache web server in order to deploy WordPress CMS by issuing the following command.

apt install libapache2-mod-php7.0 php7.0 php7.0-gd php7.0-xml php7.0-curl php7.0-mbstring php7.0-mcrypt php7.0-xmlrpc

The last component missing now in order for LAMP stack to be complete is MariaDB database server. Execute the following command to install MariaDB server alongside with PHP module required to access the database from Apache HTTP server.

apt install php7.0-mysql mariadb-server mariadb-client

After MariaDB database has been installed, start the daemon and secure the database my running mysql_secure_installation script as illustrated in the below excerpt. Mainly answer with yes on all question the script prompts you. Also, make sure you choose a strong password for root account. Be aware that MySQL root account is not identical will Linux root account. The first is used only to manage the MariaDB database and the second is the superuser account in every Linux system. These accounts never overlap in a system.

systemctl start mariadb
mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
 
In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
 
Enter current password for root (enter for none):
OK, successfully used password, moving on...
 
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
 ... Success!
Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
 ... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
 ... Success!
Cleaning up...
All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!

We’re not done with securing MariaDB database yet. By default, you can log in to MariaDB from localhost with the database root account without being asked for a password. To prevent possible security issues, login to the database with root user and issue the following commands.

mysql -u root -p
MariaDB> use mysql;
MariaDB> update user set plugin='' where User='root';
MariaDB> flush privileges;
MariaDB> quit

 Remove plugin from MySQL root user

Now, test the database by trying to log in with root account without the password. You should be denied access to MariaDB database.

In the next step, we’ll enable and configure TLS and rewrite modules for Apache web server, which by default are disabled. Run the below commands to enable both modules.

a2enmod rewrite ssl
a2ensite default-ssl.conf

Then, open Apache configuration files for both enabled sites and add the following block below the DocumentRoot directive as illustrated in the following screenshot.

nano /etc/apache2/sites-enabled/000-default.conf
nano /etc/apache2/sites-enabled/default-ssl.conf

 In both configuration files add the following block of code:

    
       Options Indexes FollowSymLinks MultiViews
       AllowOverride All
       Require all granted
   

 Grant access to /var/www/html directory and allow overrides

In apache default-ssl.conf TLS configuration file you can also add the below content, if not existing, in order to improve security of Apache SSL protocol. These lines of code should fix common SSL vulnerabilities.

SSLProtocol all -SSLv2 -SSLv3
# Add SSL Cipher in one long line
SSLCipherSuite          ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA
SSLHonorCipherOrder     on
SSLOptions +StrictRequire
 
Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains"
Header always set X-Frame-Options DENY
Header always set X-Content-Type-Options nosniff

Set strict SSL settings in apache2

If the lines illustrated in the above excerpt already exist in the Apache SSL configuration file, make sure you modify them to look as described above. In order to apply these settings, enable the Apache headers module and restart the service by executing the following commands:

a2enmod headers
systemctl restart apache2.service

For a production website, it should be mandatory to enable Apache TLS module because WordPress CMS generates mostly dynamic content via PHP gateway and also handles the authentication process for its internal users. Using TLS technology guarantees that the transferred information is encrypted at both ends and that the connection is secured. A third-party or a man-in-the-middle can intercept traffic but can not decrypt the content, because the information is not delivered in plain text.

After you’ve made all the above changes, test Apache configuration in order to detect potential syntax errors and if everything is ok then restart LAMP daemons in order to reflect all changes made so far and enable the services system-wide by issuing the following commands.

apache2ctl -t
systemctl restart apache2.service mariadb.service
systemctl enable apache2.service mariadb.service

Finally, check if Apache and MariaDB services have opened ports in listening state by issuing netstat command and filter the output using egrep By now, Apache web server should have ports 80 and 443 (corresponding to HTTP and https protocols) generally exposed and MariaDB should be only binding on localhost:3306 socket. Use the -n flag against netstat command to suppress displaying service names.

netstat -tlp| egrep 'http|mysql'

 Check if MariaDB is started

To make sure your web server is accessible from the internet via HTTP and HTTPS protocols open a browser and navigate to your domain name. Browsing via HTTPS protocol, a certificate error will be displayed in the browser. This is because Apache default TLS configuration file is configured to use Self-Signed Certificates. You should accept the TLS error and continue navigating to the default web page as illustrated below.

http://www.yourdomain.com 

Apache2 test page

https://www.yourdomain.com 

Apache 2 test page in SSL mode

In case you cannot visit your domain default web page from the internet you should first verify if some firewall rules in the system are blocking the requests or make sure the proper ports on the router are forwarded into your internal LAN in case the server sits behind a NAT-ed network. You might also want to check the DNS records in your domain registrar panel and make sure they point to your WAN IP and if the records finished propagating on the internet.

In order to test if PHP is working as expected on the server side, create a PHP php in /var/www/html/ system path, which is the default web document root path of Apache web server, issuing the below command and navigate to the following URI from browser to get the result: http://www.yourdomain.com/info.php

echo '' > /var/www/html/info.php

 PHP info test page

Install WordPress 5.0

Now that the LAMP stack is fully configured, the installation of WordPress CMS is relatively straightforward. First, log in to MariaDB database and create an installation database for WordPress and a user with the proper password for installing and managing WordPress CMS, by issuing the below commands. Feel free to replace the database name and database credentials to match your own requirements.

mysql -u root -p
CREATE DATABASE wordpress;
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress-user'@'localhost' IDENTIFIED BY 'wordpress-pass';
FLUSH PRIVILEGES;

 Create WordPress MySQL database and Database User

Next, download the latest WordPress tarball from the official website using wget utility and extract the compressed archive with tar utility. Copy the installation files to Apache web server document root path by issuing the below commands. Also, make sure you remove the default index.html webpage.

cd /tmp
wget http://wordpress.org/latest.tar.gz
tar xfz latest.tar.gz
cp -rf wordpress/* /var/www/html/
rm /var/www/html/index.html

 Download and unpack WordPress on your server

Modify the permissions of Apache webroot path as described below in order to grant web server www-data group full write permissions to the installation directory. This configuration will allow Apache web server to create or modify files and directories under this specific system path. The most important ones would be the uploads directory and .htaccess file, which can be used to control and extend Apache functionality.

chmod -R 775 /var/www/html/
chgrp -R www-data /var/www/html/
ls -al /var/www/html

 WordPress files

Now, that everything is in place, let’s start to install WordPress. The installation process will be performed from the browser. Open a browser and visit your domain via HTTPS protocol. On the first screen of the installation hit on Let’s go button to start the installation.

 WordPress web installer

In the next installation screen, add the name of the database, the database access credentials and the database host you’ve created earlier for WordPress installation and hit the Submit button to continue. The configuration of the database will be saved in /var/www/html/wp-config.php You can manually modify the file at a later date for special WordPress purposes.

Database settings

On the next screen click on Run the install button and fill your website title, the website admin credentials, and email address. A strong password should be automatically generated by the installation scripts. You can choose to save this password or provide your own strong password. When you’ve finished, hit Install WordPress button to complete the installation process.

Run installation

WordPress site information

Finally, after the installation successfully completes, log in to WordPress dashboard with the credentials created during the installation process and start managing your own website.

 WordPress Installation Success

WordPress admin login

Log into WordPress backend.

WordPress Backend

WordPress Admin Dashboard.

Editing a post in the new WordPress Gutenberg Editor.

WordPress 5.0 Frontend with new TwentyNineteen Theme.

Congratulations! You’ve successfully installed the latest version of WordPress CMS on top of LAMP software bundle in Debian 9, codename Stretch.

Virtual machine image download of this tutorial

This tutorial is available as ready to use virtual machine image in ovf/ova format that is compatible with VMWare and Virtualbox. The virtual machine image uses the following login details:

SSH / Shell Login

Username: administrator
Password: howtoforge

This user has su rights.

Username: root
Password: howtoforge

WordPress Login

Username: admin
Password: howtoforge

MySQL Login

Username: root
Password: howtoforge

The IP of the VM is 192.168.1.100, it can be changed in the file /etc/network/interfaces. Please change all the above passwords to secure the virtual machine.

How to Install SonarQube on Ubuntu 18.04 LTS

How to Install SonarQube on Ubuntu 18.04 LTS

SonarQube is an open source platform to continuously inspect code quality of applications. It is written in Java language and supports multiple databases. You can inspect code and check the health of an application for more than 20 programming languages including Java, C, C++, C#, PHP, and web languages like JavaScript, HTML and CSS. SonarQube can analyze source code, find security vulnerabilities, detect bugs and show the result on web-based dashboard. You can easily integrate SonarQube with Maven, Ant, Gradle, MSBuild, LDAP, Active Directory and GitHub.

In this tutorial, we will learn how to install SonarQube on an Ubuntu 18.04 LTS (Bionic Beaver) server.

Requirements

  • A server running Ubuntu 18.04.
  • A non-root user with sudo privileges.

Getting Started

Before starting, you will need to update your system with the latest version. You can do this by running the following command:

sudo apt-get update -y
sudo apt-get upgrade -y

Once your system is updated, restart the system to apply the changes.

Install Java

SonarQube is written in Java language, so you will need to install Java to your system. First, add the Java repository with the following command:

sudo add-apt-repository ppa:webupd8team/java

Next, update the repository and install Java with the following command:

sudo apt-get update -y
sudo apt-get install oracle-java8-installer -y

Once the Java is installed, check the Java version using the following command:

java -version

Output:

openjdk version "10.0.2" 2018-07-17
OpenJDK Runtime Environment (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.3)
OpenJDK 64-Bit Server VM (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.3, mixed mode)

Install and Configure PostgreSQL

By default, the latest version of PostgreSQL is not available in the Ubuntu 18.04 default repository. So you will need to add the PostgreSQL repository to your system.

You can do this with the following command:

sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add -

Next, update the repository and install PostgreSQL with the following command:

sudo apt-get update -y
sudo apt-get install postgresql postgresql-contrib

Once the installation is completed, check the status of PostgreSQL with the following command:

sudo systemctl status postgresql

Output:

? postgresql.service - PostgreSQL RDBMS
   Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
   Active: active (exited) since Sun 2018-12-02 08:49:29 UTC; 4h 30min ago
  Process: 1295 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
 Main PID: 1295 (code=exited, status=0/SUCCESS)

Dec 02 08:49:29 ubuntu1804 systemd[1]: Starting PostgreSQL RDBMS...
Dec 02 08:49:29 ubuntu1804 systemd[1]: Started PostgreSQL RDBMS.

Next, switch to the postgres user with the following command:

su - postgres

Next, create a sonar user with the following command:

createuser sonar

Next, switch to the PostgreSQL shell with the following command:

psql

Next, set password for sonar user and create a sonar database with the following command:

ALTER USER sonar WITH ENCRYPTED password 'password';
CREATE DATABASE sonar OWNER sonar;

Next, exti from the PostgreSQL shell:

q

Install and Configure SonarQube

First, create a user for SonarQube with the following command:

sudo adduser sonar

Next, download the latest version of SonarQube with the following command:

wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-6.7.6.zip

Once the download is completed, unzip the downloaded file with the following command:

unzip sonarqube-6.7.6.zip

Next, copy the extracted directory to the /opt with the following command:

sudo cp -r sonarqube-6.7.6 /opt/sonarqube

Next, give ownership to the sonar user with the following command:

sudo chown -R sonar:sonar /opt/sonarqube

Next, you will need to configure SonarQube to run as a sonar user. You can do this with the following command:

sudo nano /opt/sonarqube/bin/linux-x86-64/sonar.sh

Make the following changes:

RUN_AS_USER=sonar

Save and close the file. Then, open SonarQube default configuration file and modify the database credentials with the one we created earlier:

sudo nano /opt/sonarqube/conf/sonar.properties

Make the following changes:

sonar.jdbc.username=sonar
sonar.jdbc.password=password
sonar.jdbc.url=jdbc:postgresql://localhost/sonar
sonar.web.host=127.0.0.1
sonar.search.javaOpts=-Xms512m  -Xmx512m

Save and close the file, when you are finished.

Create Systemd Service file for SonarQube

Next, you will need to create a systemd service file to manage SonarQube service. You can do this with the following command:

sudo nano /etc/systemd/system/sonar.service

Add the following lines:

[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
Group=sonar
Restart=always

[Install]
WantedBy=multi-user.target

Save and close the file, when you are finished. Then, start SonarQube service and enable it to start on boot time with the following command:

sudo systemctl start sonar
sudo systemctl enable sonar

You can check the status of SonarQube service with the following command:

sudo systemctl status sonar

Output:

? sonar.service - SonarQube service
   Loaded: loaded (/etc/systemd/system/sonar.service; disabled; vendor preset: enabled)
   Active: active (running) since Sun 2018-12-02 13:55:34 UTC; 2min 52s ago
  Process: 2339 ExecStart=/opt/sonarqube/bin/linux-x86-64/sonar.sh start (code=exited, status=0/SUCCESS)
 Main PID: 2396 (wrapper)
    Tasks: 133 (limit: 2323)
   CGroup: /system.slice/sonar.service
           ??2396 /opt/sonarqube/bin/linux-x86-64/./wrapper /opt/sonarqube/bin/linux-x86-64/../../conf/wrapper.conf wrapper.syslog.ident=SonarQ
           ??2399 java -Dsonar.wrapped=true -Djava.awt.headless=true -Xms8m -Xmx32m -Djava.library.path=./lib -classpath ../../lib/jsw/wrapper-
           ??2445 /usr/lib/jvm/java-8-oracle/jre/bin/java -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOc
           ??2545 /usr/lib/jvm/java-8-oracle/jre/bin/java -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/opt/sonarqube/temp -
           ??2622 /usr/lib/jvm/java-8-oracle/jre/bin/java -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/opt/sonarqube/temp -

Dec 02 13:55:33 ubuntu1804 systemd[1]: Starting SonarQube service...
Dec 02 13:55:33 ubuntu1804 sonar.sh[2339]: Starting SonarQube...
Dec 02 13:55:34 ubuntu1804 sonar.sh[2339]: Started SonarQube.
Dec 02 13:55:34 ubuntu1804 systemd[1]: Started SonarQube service.

Configure Apache for SonarQube

By default, SonarQube listens on port 9000. So, you will need to install and configure Apache as the reverse proxy to access the SonarQube using port 80.

To do so, install Apache with the following command:

sudo apt-get install apache2 -y

Next, enable mod_proxy module with the following command:

sudo a2enmod proxy
sudo a2enmod proxy_http

Next, create an Apache virtual host file for SonarQube with the following command:

sudo nano /etc/apache2/sites-available/sonar.conf

Add the following lines:


    ServerName example.com
    ServerAdmin [email protected]
    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:9000/
    ProxyPassReverse / http://127.0.0.1:9000/
    TransferLog /var/log/apache2/sonarm_access.log
    ErrorLog /var/log/apache2/sonar_error.log

Replace example.com with your own domain name. Save and close the file. Then, enable SonarQube virtual host file with the following command:

sudo a2ensite sonar

Finally, restart Apache and SonarQube service to apply all the changes with the following command:

sudo systemctl restart apache2
sudo systemctl restart sonar

By default, SonarQube stores their logs on /opt/sonarqube/logs directory. You can check SonarQube log with the following command:

sudo tail -f /opt/sonarqube/logs/sonar.log

Output:

Launching a JVM...
Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org
  Copyright 1999-2006 Tanuki Software, Inc.  All Rights Reserved.

2018.12.02 13:55:43 INFO  app[][o.s.a.AppFileSystem] Cleaning or creating temp directory /opt/sonarqube/temp
2018.12.02 13:55:44 INFO  app[][o.s.a.es.EsSettings] Elasticsearch listening on /127.0.0.1:9001
2018.12.02 13:55:45 INFO  app[][o.s.a.p.ProcessLauncherImpl] Launch process[[key='es', ipcIndex=1, logFilenamePrefix=es]] from [/opt/sonarqube/elasticsearch]: /opt/sonarqube/elasticsearch/bin/elasticsearch -Epath.conf=/opt/sonarqube/temp/conf/es
2018.12.02 13:55:45 INFO  app[][o.s.a.SchedulerImpl] Waiting for Elasticsearch to be up and running
2018.12.02 13:55:48 INFO  app[][o.e.p.PluginsService] no modules loaded
2018.12.02 13:55:48 INFO  app[][o.e.p.PluginsService] loaded plugin [org.elasticsearch.transport.Netty4Plugin]
2018.12.02 13:56:34 INFO  app[][o.s.a.SchedulerImpl] Process[es] is up
2018.12.02 13:56:34 INFO  app[][o.s.a.p.ProcessLauncherImpl] Launch process[[key='web', ipcIndex=2, logFilenamePrefix=web]] from [/opt/sonarqube]: /usr/lib/jvm/java-8-oracle/jre/bin/java -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/opt/sonarqube/temp -Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError -cp ./lib/common/*:./lib/server/*:/opt/sonarqube/lib/jdbc/postgresql/postgresql-42.2.1.jar org.sonar.server.app.WebServer /opt/sonarqube/temp/sq-process420500314195865484properties

You can also check SonarQube web log using the following command:

sudo tail -f /opt/sonarqube/logs/web.log

Output:

2018.12.02 13:57:03 INFO  web[][o.s.s.p.ServerPluginRepository] Deploy plugin SonarJava / 4.15.0.12310 / 572454b93016ec73a53fe0e07b2ffdc356d21ba9
2018.12.02 13:57:03 INFO  web[][o.s.s.p.ServerPluginRepository] Deploy plugin SonarPHP / 2.11.0.2485 / 741861a29e5f9a26c6c99c06268facb6c4f4a882
2018.12.02 13:57:03 INFO  web[][o.s.s.p.ServerPluginRepository] Deploy plugin SonarPython / 1.8.0.1496 / 3fe3bc4d0273a5721ea2fb368dc45b1bb82fede3
2018.12.02 13:57:03 INFO  web[][o.s.s.p.ServerPluginRepository] Deploy plugin SonarQube :: Plugins :: SCM :: Git / 1.3.0.869 / 4da53e3f9e55f4f2e5796625cb0c5768ed152079
2018.12.02 13:57:03 INFO  web[][o.s.s.p.ServerPluginRepository] Deploy plugin SonarQube :: Plugins :: SCM :: SVN / 1.6.0.860 / 2111fdbd1dddda4ad6d4ed6486fd0b18c1010d3b
2018.12.02 13:57:03 INFO  web[][o.s.s.p.ServerPluginRepository] Deploy plugin SonarTS / 1.1.0.1079 / 042c9e65239a47d92d305f9767f730b3cc1e5ed3
2018.12.02 13:57:03 INFO  web[][o.s.s.p.ServerPluginRepository] Deploy plugin SonarXML / 1.4.3.1027 / 39588245cecf538bb27be4e496ff303b0143d20b
2018.12.02 13:57:07 INFO  web[][o.s.s.p.d.m.c.PostgresCharsetHandler] Verify that database charset supports UTF8
2018.12.02 13:57:09 INFO  web[][o.s.s.p.w.MasterServletFilter] Initializing servlet filter [email protected] [pattern=UrlPattern{inclusions=[/api/system/migrate_db/*, ...], exclusions=[/api/properties*, ...]}]
2018.12.02 13:57:09 INFO  web[][o.s.s.a.EmbeddedTomcat] HTTP connector enabled on port 9000
2018.12.02 13:57:16 INFO  web[][o.s.s.p.UpdateCenterClient] Update center: https://update.sonarsource.org/update-center.properties (no proxy)

Access SonarQube

SonarQube is now installed and configured. It’s time to access it through web browser.

Open your web browser and type the URL http://example.com. You will be redirected to the following page:

SonarQube

Here, click on the Log In button. You should see the following page:

Log In

Provide the default administrator account username and password as admin / admin and click on the Log In button. You should see the SonarQube default dashboard in the following page:

SonarCube Dashboard

Congratulations! you have successfully installed SonarQube on Ubuntu 18.04 server. You can now easily perform automatic reviews and check the health of an application using SonarQube.

Linux rename Command Tutorial for Beginners (with Examples)

If you work with files on the command line in Linux, renaming files is one of the most frequent tasks you may find yourself involved in. We’ve already discussed the mv command that lets you do this. And here, in this tutorial, we will discuss another such tool, dubbed rename.

But before we start with that, it’s worth mentioning that all examples in this article have been tested on an Ubuntu 18.04 LTS machine.

Linux rename command

As the name suggests, the rename command in Linux allows you to rename files. Following is its syntax:

rename [options] expression replacement file...

And here’s how the tool’s man page explains it:

rename will rename the specified files by replacing the first occurrence of expression in their name by replacement.

Note that if you don’t have the rename command installed, you can get it using the following command:

sudo apt install rename

Following are some Q&A-styled examples that should give you a better idea on how the rename command works.

Q1. How to use rename command?

Basic usage isn’t exactly straight forward, I must say, but it’s not difficult to understand. Let’s say you have a file named ‘test.txt’ and you want to rename it to ‘new.txt’. Then here’s how you use the rename command to do this.

rename 's/test/new/' test.txt

By default, the rename command just renames the file which is passed as input, even if it’s a symbolic link. However, if you want the tool to not rename symbolic links, but act on their targets instead, then use the -s command line option.

So if symlink.txt is a symbolic link that points to root.txt, then the following command will make sure the rename operation happens for root.txt:

rename -s 's/root/new/' symlink.txt

Q3. How to make a dry run with rename?

Suppose you only want to see the final change that’ll happen with a rename command, without actually carrying it out, then use the -n command line option. For example, the following command:

rename -n 's/new/test/' new.txt

produced the following output:

rename(new.txt, test.txt)

but didn’t actually rename new.txt to test.txt.

Q4. How rename handles overwriting of files?

By default, the rename command doesn’t perform the operation if it involves overwriting an existing file. However, you can force the tool to overwrite using the -f command line option.

For example, the following command:

rename 's/new/test/' new.txt

produced the following output:

new.txt not renamed: test.txt already exists

But when the -f command was used:

rename -f 's/new/test/' new.txt

The operation completed smoothly and test.txt got overwritten.

Conclusion

The rename command doesn’t offer too many options, and we’ve already discussed some of the main ones here. After you’re done practicing these, head to the tool’s man page to learn more about it.

Linux tree Command Tutorial for Beginners (6 Examples)

Linux tree Command Tutorial for Beginners (6 Examples)

It won’t be wrong to say the ls command is the gold standard when it comes to listing directory contents on the Linux command line. However, there do exist some alternatives that have their own strong points when compared to ls. Once such tool is tree, basics of which we’ll be discussing here in this tutorial.

But before we do that, it’s worth mentioning that all examples here have been tested on an Ubuntu 18.04 LTS machine.

Linux tree command

As the name suggests, the tree command in Linux lists contents of directories in a tree-like format. Following is its syntax:

tree [OPTIONS] [directory]

And here’s how the tool’s man page explains it:

Tree is a recursive directory listing program that produces a depth indented listing of files, 
which is colorized ala dircolors if the LS_COLORS environment variable is set and output is to tty.
With no arguments, tree lists the files in the current  directory. When directory arguments are
given, tree lists all the files and/or directories found in the given directories each in turn.
Upon completion of listing all files/directories found, tree returns the total number of files
and/or directories listed.

In case the tree command isn’t installed in your Ubuntu box, you can grab it using the following command:

sudo apt-get install tree

Following are some Q&A styled examples that should give you a good example of how the tree command works.

Q1. How does tree command work?

Basic usage is fairly easy. Just execute the ‘tree’ command sans any option.  Here’s an example:

tree

Here’s the output this command produced on my system:

How does tree command work

So you can see a tree-like structure was produced in the output. Note that it’s the current working directory whose contents are displayed by default. If you want to display contents of any other directory, then you’ll have to specify the path to that directory in input.

Q2. How to make tree display hidden files as well?

By default, the tree command doesn’t display hidden files. However, if you want, you can make tree do that by using the -a command line option.

tree -a

Here’s what the man page says about -a:

All files are printed. By default tree does not print hidden files (those beginning with a dot `.')
. In no event does tree print the file system constructs `.' (current directory) and `..'
(previous directory).

Q3. How to make tree only display directories in output?

Suppose you only want the tree command to display directory entries in output. You can do that using the -d command line option.

For example, the following command:

tree -d

produced this output:

How to make tree only display directories in output

Q4. How to make tree print complete path prefix for files?

This can be done using the -f command line option. Here’s an example:

tree -f

Here’s part of the output produced by this command on my system:

How to make tree print complete path prefix for files

Q5. How to control the depth of directory tree in output?

The tree command also lets you control the depth of directory tree produced in output. This you can do using the -L command line option which requires a numeric value that signifies the permitted directory depth. For example:

tree -d -L 1

The above command would make sure that only first level of directories get displayed in output.

Q6. How to selectively leave some names in output?

The tree command offers a -I command line option that requires you to pass a pattern as input. Depending on the names of files/directories you want not to be displayed in output, create a pattern. For example, I wanted to display only directories, but didn’t want any name with ‘Ubuntu’ pattern (case sensitive), so I used the -I command line option in the following way:

tree -d -I *Ubuntu

Conclusion

While we’ve discussed quite a few tree command line options, the fact is this tool offers a lot more features. Once you’re done practicing what all we’ve discussed here, head to the tree command man page to learn more about it.

How to Install LimeSurvey (CE) on CentOS 7

How to Install LimeSurvey (CE) on CentOS 7

LimeSurvey is an open source survey software written in PHP. LimeSurvey source code is hosted on GitHubIn this tutorial, we will walk you through the LimeSurvey Community Edition (CE) installation process on a fresh CentOS 7 system.

Requirements

In order to install LimeSurvey (CE) on your CentOS 7 system, make sure your system meets the following requirements:

  • Minimum 250 MB disk space.
  • MySQL 5.5.3 or later or MariaDB 5.5 or later. This tutorial will use MariaDB.
  • PHP 5.5.9 or later (PHP 7.0.0+ is recommended) with the following extensions: Mbstring, PDO database driver for MySQL or PostgreSQL, GD-Library, IMAP, LDAP, ZIP.
  • Apache 2.4 or later or Nginx 1.1 or later. This tutorial will use Nginx.

Initial steps

Check your CentOS system version:

cat /etc/centos-release
# CentOS Linux release 7.5.1804 (Core)

Set up the timezone:

timedatectl list-timezones
sudo timedatectl set-timezone 'Region/City'

Update your operating system’s packages:

sudo yum update -y

Install vim, git, unzip, and socat packages:

sudo yum install -y vim git unzip socat

Step 1 – Install PHP

LimeSurvey requires PHP version 5.5.9 or greater, while PHP 7.0.0+ is the recommended version. Default CentOS repositories contain older version of PHP, and thus we will need to set up a third-party repository to install a newer PHP version. We will use Webtatic repository.

Setup the Webtatic YUM repo:

sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

Install PHP, as well as the necessary PHP extensions:

sudo yum install -y php72w php72w-cli php72w-fpm php72w-common php72w-mbstring php72w-xml php72w-mysql php72w-gd php72w-zip php72w-ldap php72w-imap

Check the PHP version:

php --version

# PHP 7.2.12 (cli) (built: Nov 11 2018 14:54:16) ( NTS )
# Copyright (c) 1997-2018 The PHP Group
# Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

Start and enable PHP-FPM service:

sudo systemctl start php-fpm.service
sudo systemctl enable php-fpm.service

Step 2 – Install MariaDB and create a database for LimeSurvey

Install MariaDB database server:

sudo yum install -y mariadb-server

Check the MariaDB version:

mysql --version
# mysql Ver 15.1 Distrib 5.5.60-MariaDB, for Linux (x86_64) using readline 5.1

Start and enable MariaDB service:

sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

Run mysql_secure installation script to improve MariaDB security and set the password for MariaDB root user:

sudo mysql_secure_installation

Answer all the questions as shown below:

Enter current password for root (enter for none):
Set root password? [Y/n]: Y
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]: Y
Reload privilege tables now? [Y/n]: Y

Log into MariaDB shell as the user root:

mysql -u root -p
# Enter password

Create a MariaDB database and user that you will use for your installation of LimeSurvey, and remember the credentials:

CREATE DATABASE dbname;
GRANT ALL ON dbname.* TO 'username' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;

Exit from MariaDB shell:

quit

Step 3 – Install and configure Nginx

Install Nginx webserver:

sudo yum install -y nginx

Check the NGINX version:

nginx -v
# nginx version: nginx/1.12.2

Start and enable Nginx service:

sudo systemctl start nginx.service
sudo systemctl enable nginx.service

Run sudo vim /etc/nginx/conf.d/limesurvey.conf and populate the file with the following configuration:

server {
    listen 80;

    server_name example.com;
    root /var/www/limesurvey;

    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }
    
    location ~ .php$ {
        try_files $uri =404;
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

}

Test the NGINX configuration.

sudo nginx -t

Reload NGINX.

sudo systemctl reload nginx.service

Step 4 – Download and install LimeSuervey

Create a document root directory:

sudo mkdir -p /var/www/limesurvey

Change ownership of the /var/www/limesurvey directory to johndoe:

sudo chown -R [your_user]:[your_user] /var/www/limesurvey

Navigate to document root:

cd /var/www/limesurvey

Download the LimeSurvey ZIP installer:

wget https://www.limesurvey.org/stable-release?download=2514:limesurvey3155%20181115zip -O limesurvey.zip

Unzip LimeSurvey installer:

unzip limesurvey.zip
rm limesurvey.zip
mv limesurvey/* . && mv limesurvey/.* .
rmdir limesurvey

Change ownership of the /var/www/limesurvey directory to nginx:

sudo chown -R nginx:nginx /var/www/limesurvey

Create the directory/var/lib/php/session and set ownership to nginx.

sudo mkdir -p /var/lib/php/session && sudo chown -R nginx:nginx /var/lib/php

Run sudo vim /etc/php-fpm.d/www.conf and set the user and group to nginx. Initially, they will be set to apache:

sudo vim /etc/php-fpm.d/www.conf
# user = nginx
# group = nginx

Restart the PHP-FPM service:

sudo systemctl restart php-fpm.service

Step 5 – Complete the LimeSurvey setup

Open your web browser and type the URL http://example.com. You will be redirected to the following page:

LimeSurvey Installer

Select your preferred language and click on the Start Installation button. AfterThe LimeSurvey license page should appear.

Accept the license

Check and click on the I accept button if you agree with the license terms. After this step, you should see the LimeSurvey pre-installation check page:

pre-installation check

Make sure all the requirements are completed, then click on the Next button. This should direct you to the database configuration page.

Database configuration

Enter the database settings you want to use for LimeSurvey and click on the Next button.  You should see the following page:

Database settings

Click on the Populate database button. You should see the following page:

Administration settings

Here, provide your admin username and password, site name, email address, then click on the Next button. Once the installation has been completed, you should see the following page:

LimeSurvey installed successfully

Now, click on the Administration button. You should see the following page:

Log-in

Provide your login details, then click on the Log In button. You should see the LimeSurvey administration interface:

Lime Survey Dashboard

Links