DHIS2 Installation on Ubuntu 19.04 LTS – Digital Ocean

DHIS2 Installation on Ubuntu 19.04 LTS – Digital Ocean

DHIS2 Installation Outline-Updated: 9th June-2020

PostgreSQL-11, Tomcat-9, DHIS2-2.34

2.1 Setting server time zone: It may be necessary to reconfigure the time zone of the server to match the time zone of the location which the DHIS2 server will be covering. If you are using a virtual private server, the default time zone may not correspond to the time zone of your DHIS2 location. You can easily reconfigure the time zone by invoking the below and following the instructions.

sudo dpkg-reconfigure tzdata

2.2.1 Creating a user to run DHIS2: You should create a dedicated user for running DHIS2. Under no circumstances, should you run the DHIS2 server as a privileged user such as root. Create a new user called dhis by invoking:

sudo useradd -d /home/dhis -m dhis -s /bin/false

2.2.2 Then to set the password for your account invoke: Make sure you set a strong password with at least 15 random characters.

sudo passwd dhis

2.3.1 Creating the configuration directory : Start by creating a suitable directory for the DHIS2 configuration files. This directory will also be used for apps, files and log files. An example directory could be:

sudo mkdir /home/dhis/config

2.3.2 Set ownership of the directory to ‘dhis’ user created above

 sudo chown dhis:dhis /home/dhis/config 

2.4 PostgreSQL installation:

2.4.1 Install PostgreSQL by invoking:

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

See detail:

How to Install PostgreSQL 11 on Ubuntu: https://tecadmin.net/install-postgresql-server-on-ubuntu


2.4.2 Install Postgis: Click here

sudo apt-get install postgis

2.4.3 Create a non-privileged user called dhis by invoking:

 sudo -u postgres createuser -SDRP dhis 

2.4.4 Enter a secure password at the prompt. Create a database by invoking:

 sudo -u postgres createdb -O dhis dhis2 

Return to your session by invoking exit You now have a PostgreSQL user called dhis and a database called dhis2 .

2.4.5 The PostGIS extension is needed for several GIS/mapping features to work. DHIS 2 will attempt to install the PostGIS extension during startup. If the DHIS 2 database user does not have permission to create extensions you can create it from the console using the postgres user with the following commands:

 sudo -u postgres psql -c "create extension postgis;" dhis2 

2.5 Database Configuration

2.5.1. The database connection information is provided to DHIS2 through a configuration file called dhis.conf . Create this file and save it in the DHIS2_HOME directory. As an example this location could be:

 sudo -u dhis nano /home/dhis/config/dhis.conf 

A configuration file for PostgreSQL corresponding to the above setup has these properties:

# Hibernate SQL dialect
connection.dialect = org.hibernate.dialect.PostgreSQLDialect

# JDBC driver class
connection.driver_class = org.postgresql.Driver

# Database connection URL
connection.url = jdbc:postgresql:dhis2

# Database username
connection.username = dhis

# Database password
connection.password = dhis

# Database schema behavior, can be validate, update, create, create-drop
connection.schema = update

# Encryption password (sensitive)
encryption.password = xxxx

The encryption.password property is the password used when encrypting and decrypting data in the database. Note that the password must not be changed once it has been set and data has been encrypted as the data can then no longer be decrypted. Remember to set a strong password of at least 24 characters.

Note that the configuration file supports environment variables. This means that you can set certain properties as environment variables and have them resolved by DHIS 2, e.g. like this where DB_PASSWD is the name of the environment variable.

2.6 Java Installation :

The installation directory is /usr/lib/jvm/java-8-openjdk-amd64 which may change depending on the java version. Run below command to check the exact directory:

ls /usr/lib/jvm

2.7 Tomcat and DHIS2 Installation

2.7.1 Install tomcat 9

 sudo apt-get install tomcat9-user 

2.7.2 To create a Tomcat instance for DHIS2 move to the dhis folder created above:

 cd /home/dhis/ 

2.7.3 Create Tomcat instance:

 sudo tomcat9-instance-create tomcat-dhis 

2.7.4 Set ownership of the created folder to dhis user

 sudo chown -R dhis:dhis /home/dhis/tomcat-dhis/

2.7.5 Edit setenv.sh:

 sudo nano /home/dhis/tomcat-dhis/bin/setenv.sh

2.7.6 Add the following lines to the bottom of the file:

export JAVA_HOME='/usr/lib/jvm/java-8-openjdk-amd64/'
export JAVA_OPTS='-Xmx2000m -Xms1000m'
export DHIS2_HOME='/home/dhis/config'

2.7.7 Please make sure the java installation directory matches the path given in JAVA_HOME above.

The next step is to download the DHIS2 WAR file and place it into the webapps directory of Tomcat:

 sudo wget https://s3-eu-west-1.amazonaws.com/releases.dhis2.org/2.34/dhis.war

2.7.8 Move the WAR file into the Tomcat webapps directory. We want to call the WAR file ROOT.war in order to make it available at localhost directly without a context path:

sudo mv dhis.war tomcat-dhis/webapps/ROOT.war

2.7.9 DHIS2 should never be run as a privileged user, so edit the startup.sh:

sudo nano /home/dhis/tomcat-dhis/bin/startup.sh

2.7.10 Replace everything in the file with the following lines:

set -e

if [ "$(id -u)" -eq "0" ]; then
   echo "This script must NOT be run as root" 1>&2
   exit 1

export CATALINA_BASE="/home/dhis/tomcat-dhis"
echo "Tomcat started"

2.8 Running DHIS2 :

2.8.1 DHIS2 can now be started by invoking:

sudo -u dhis tomcat-dhis/bin/startup.sh 

2.8.2 Warning: The DHIS2 server should never be run as root or other privileged user. DHIS2 can be stopped by invoking:

 sudo -u dhis tomcat-dhis/bin/shutdown.sh 

2.8.3 To monitor the behavior of Tomcat the log is the primary source of information. The log can be viewed with the following command:

sudo tail -f tomcat-dhis/logs/catalina.out 

2.8.4 Assuming that the WAR file is called ROOT.war, you can now access your DHIS2 instance at the following URL:

Username: admin
Password: district

2.9 File store configuration Create init scripts:

 sudo nano tomcat 

2.9.1 Enter the following lines:

#Tomcat init script


case $1 in
   sudo -u dhis ${HOME}/startup.sh
   sudo -u dhis ${HOME}/shutdown.sh
   sudo -u dhis ${HOME}/shutdown.sh
   sleep 5
   sudo -u dhis ${HOME}/startup.sh
exit 0

2.9.2 Move the script to the init script directory and make it executable by invoking:

				sudo mv tomcat /etc/init.d
				sudo chmod +x /etc/init.d/tomcat

Next make sure the tomcat init script will be invoked during system startup and shutdown:

sudo /usr/sbin/update-rc.d -f tomcat defaults 81 

Enjoy the Day!!!

If you face errors like `404-not-found` or `out of shared memory`, you can follow this post: 


More informaiton about DHIS2 instillation in linux

https://docs.dhis2.org/2.28/en/implementer/html/install_server_setup.html https://github.com/adeelshahid/dhis2-core-ansible

DHIS2 instillation in Mac OSX


You can visit Megha's blog:


Configure your domain and hosting in Digital Ocean Droplet


Last updated: 2019-08-17

Mohammad Julhas Sujan Cell: +8801989-442856 Email: julhaspustcse@gmail.com Skype: julhas08