Guide for installing DHIS2 on Ubuntu 16.04 LTS
Thanks to https://dhis-2.blogspot.com.ng/
Works up to DHIS 2.28
This guide assumes Ubuntu 16.04 LTS is installed on a local machine/VPS with 4GB of RAM and DHIS2 is used for testing purposes. This is based on the official DHIS2 documentation, correcting some of it's mistakes in the commands.
Login with the Ubuntu 'root' account or any account in the Ubuntu sudoers list.
This guide assumes Ubuntu 16.04 LTS is installed on a local machine/VPS with 4GB of RAM and DHIS2 is used for testing purposes. This is based on the official DHIS2 documentation, correcting some of it's mistakes in the commands.
Login with the Ubuntu 'root' account or any account in the Ubuntu sudoers list.
- Setting server time zone
sudo dpkg-reconfigure tzdata - Creating an Ubuntu user to run DHIS2
Create a new user called 'dhis' by invoking:
sudo useradd -d /home/dhis -m dhis -s /bin/false
Then set the password for the account by invoking:
sudo passwd dhis
Make sure you set a strong password - Creating the configuration directory
sudo mkdir /home/dhis/config
Set ownership of the directory to 'dhis' user created above
sudo chown dhis:dhis /home/dhis/config - PostgreSQL installation
sudo apt-get install postgresql-9.5 postgresql-contrib-9.5 postgresql-9.5-postgis-2.2
Create a non-privileged PostgreSQL user called 'dhis' by invoking:
sudo -u postgres createuser -SDRP dhis
Create a database by invoking:
sudo -u postgres createdb -O dhis dhis2
Create the PostGIS extension
sudo -u postgres psql -c "create extension postgis;" dhis2 - Creating DHIS2 configuration file
sudo -u dhis nano /home/dhis/config/dhis.conf
Insert following lines to the file (update PostgreSQL dhis user password according what you set above):
# 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 =xxxx
# Database schema behavior, can be validate, update, create, create-drop
connection.schema = update
# Encryption password (sensitive)
encryption.password = xxxx - Java installation
Oracle Java will need to be installed manually because it no longer supports installation via apt-get.
Create a directory to install Java
mkdir /usr/java/
cd /usr/java/
wget -O java-linux-x64.tar.gz http://oracle-java-download-link
(You need to replace http://oracle-java-download-link with "Linux x64" download link from this page: https://www.java.com/en/download/linux_manual.jsp
It will be something like: http://javadl.oracle.com/webapps/download/AutoDL?BundleId=233162_512cd62ec5174c3487ac17c61aaa89e8)
tar zxvf java-linux-x64.tar.gz - Tomcat and DHIS2 installation
sudo apt-get install tomcat7-user
To create a Tomcat instance for DHIS2 move to the dhis folder created above:
cd /home/dhis/
Create Tomcat instance:
sudo tomcat7-instance-create tomcat-dhis
Set ownership of the created folder to dhis user
sudo chown -R dhis:dhis /home/dhis/tomcat-dhis/
Edit setenv.sh:
sudo nano /home/dhis/tomcat-dhis/bin/setenv.sh
Add the following lines to the bottom of the file:
export JAVA_HOME='/usr/lib/jvm/java-8-oracle/'
export JAVA_OPTS='-Xmx2000m -Xms1000m'
export DHIS2_HOME='/home/dhis/config'
The next step is to download the DHIS2 WAR file and place it into the webapps directory of Tomcat:
wget https://www.dhis2.org/download/releases/2.28/dhis.war
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
DHIS2 should never be run as a privileged user, so edit the startup.sh:
sudo nano /home/dhis/tomcat-dhis/bin/startup.sh
Replace everything in the file with the following lines:
#!/bin/sh
set -e
if [ "$(id -u)" -eq "0" ]; then
echo "This script must NOT be run as root" 1>&2
exit 1
fi
export CATALINA_BASE="/home/dhis/tomcat-dhis"
/usr/share/tomcat7/bin/startup.sh
echo "Tomcat started" - Running DHIS2
DHIS2 can now be started by invoking:
sudo -u dhis tomcat-dhis/bin/startup.sh
To monitor the behavior of Tomcat, the log is the primary source of information. The log can be viewed with the following command:
tail -f tomcat-dhis/logs/catalina.out
DHIS2 can be stopped by invoking:
sudo -u dhis tomcat-dhis/bin/shutdown.sh
Assuming that the WAR file is called ROOT.war, you can now access your DHIS2 instance at:
http://localhost:8080 or
http://your.server.ip.address:8080
Default login details:
Username: admin
Password: district - Starting DHIS2 at server startup
Create init scripts:
sudo nano tomcat
Enter the following lines:
#!/bin/sh
#Tomcat init script
HOME=/home/dhis/tomcat-dhis/bin
case $1 in
start)
sudo -u dhis ${HOME}/startup.sh
;;
stop)
sudo -u dhis ${HOME}/shutdown.sh
;;
restart)
sudo -u dhis ${HOME}/shutdown.sh
sleep 5
sudo -u dhis ${HOME}/startup.sh
;;
esac
exit 0
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