Note that the instructions below are now out of date
- for example, you would need to use OpenJDK now
See Installing DHIS 2 dependencies on Linux for dependencies
The following code was run by an ordinary user with sudo privileges to install DHIS 2 (version 2.28) on Ubuntu 17.10.
Information was taken from:
- https://docs.dhis2.org/master/en/implementer/html/install_server_setup.html (check the commands carefully as there are occasional errors)
- http://dhis2bd.blogspot.com/2017/03/dhis2-installation-in-ubuntu.html
First create a user called dhis.
sudo useradd -d /home/dhis -m dhis -s /bin/falseSet a password for user dhis.
sudo passwd dhisCreate a config folder for the dhis user.
sudo su
mkdir /home/dhis/config
chown dhis:dhis /home/dhis/config
exitYou can set the time zone with:
sudo dpkg-reconfigure tzdataSet the locale e.g.
sudo locale-gen en_PK
sudo locale-gen en_PK.UTF-8
sudo update-localeInstall Postgres and required extensions (note that there may be later versions available on your system).
sudo apt-get install postgresql-9.5 postgresql-contrib-9.5 postgresql-9.5-postgis-2.2Create the database user dhis and set a password (remember this password as you will need it).
sudo -u postgres createuser -SDRP dhisCreate the database dhis2.
sudo -u postgres createdb -O dhis dhis2Create the PostGIS extension.
sudo -u postgres psql -c "create extension postgis;" dhis2Edit a configuration file for Postgres (will have different name for later versions of Postgres). I use the Vim text editor - substitute another text editor if required.
sudo vim /etc/postgresql/9.5/main/postgresql.confThe lines I uncommented are shown below.
max_connections = 200
shared_buffers = 3200MB
work_mem = 20MB [uncommented]
maintenance_work_mem = 512MB [uncommented]
effective_cache_size = 8000MB [uncommented]
checkpoint_completion_target = 0.8 [uncommented]
synchronous_commit = off [uncommented]
wal_writer_delay = 10000ms [uncommented]
Save and close the file.
At this point you should also do database performance tuning, which I did not do but which would be required for a production instance. I also didn’t set up database encryption but this would also be required.
Restart the database for the new configuration to take effect.
sudo /etc/init.d/postgresql restartConfigure DHIS 2 with the database settings.
sudo -u dhis vim /home/dhis/config/dhis.confMake the following changes at the appropriate points in that file.
connection.username = dhis
connection.password = [whatever password you chose for user dhis on the database dhis2]
encryption.password = [a strong password]
Save and close the file.
Change the permissions on the DHIS 2 configuration file.
sudo chmod 0600 /home/dhis/config/dhis.confInstall Java (this is how I did it but there are other ways).
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installerAccept the terms of use for Java.
Install Tomcat server.
sudo apt-get install tomcat7-userCreate a Tomcat instance.
cd /home/dhis/
sudo tomcat7-instance-create tomcat-dhis
sudo chown -R dhis:dhis tomcat-dhis/Configure Tomcat server.
sudo vim /home/dhis/tomcat-dhis/bin/setenv.shSet Java options in this file for RAM usage for your machine.
export JAVA_HOME='/usr/lib/jvm/java-8-oracle/'
export JAVA_OPTS='-Xmx7500m -Xms4000m'
export DHIS2_HOME='/home/dhis/config'
Change to webapps directory, download DHIS 2 WAR file and change permissions and name
wget https://www.dhis2.org/download/releases/2.28/dhis.war
sudo chown -R dhis:dhis dhis.war
sudo mv dhis.war ROOT.warModify the startup script.
#!/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"Start DHIS 2
sudo -u dhis tomcat-dhis/bin/startup.shThere should be considerable initial CPU/RAM usage, after which the app should be visible at MACHINE_IP_ADDRESS:8080/dhis-web-commons/security/login.action. I think the default admin user name is admin and the password is admin - this should obviously be changed immediately.
Monitor for errors (lots of lines beginning “INFO” are OK).
sudo tail -f tomcat-dhis/logs/catalina.out