Deploy DHIS2 on Alibaba Cloud ECS Instance

Prerequisite

Deploying DHIS2 on Ubuntu 16.04 ECS Instance

Step 1: Setting Server Time Zone

sudo dpkg-reconfigure tzdata

Step 2: Creating an Ubuntu User to Run DHIS2

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

Step 3: Creating the Configuration Directory

sudo mkdir /home/dhis/config
sudo chown dhis:dhis /home/dhis/config

Step 4: PostgreSQL Installation and Tuning

sudo apt-get install postgresql-9.5 postgresql-contrib-9.5 postgresql-9.5-postgis-2.2
sudo -u postgres createuser -SDRP dhis
sudo -u postgres createdb -O dhis dhis2
sudo -u postgres psql -c "create extension postgis;" dhis2
sudo nano /etc/postgresql/9.5/main/postgresql.conf
max_connections = 200
shared_buffers = 3200MB
work_mem = 20MB
maintenance_work_mem = 512MB
effective_cache_size = 8000MB
checkpoint_completion_target = 0.8
synchronous_commit = off
wal_writer_delay = 10000ms

Step 5: Creating DHIS2 Configuration File

sudo -u dhis nano /home/dhis/config/dhis.conf
# 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

Step 6: Java Installation

mkdir /usr/java/cd /usr/java/
wget -O java-linux-x64.tar.gz http://oracle-java-download-link
tar zxvf java-linux-x64.tar.gz

Step 7: Tomcat Installation

sudo apt-get install tomcat7-user
cd /home/dhis/
sudo tomcat7-instance-create tomcat-dhis
sudo chown -R dhis:dhis /home/dhis/tomcat-dhis/
sudo nano /home/dhis/tomcat-dhis/bin/setenv.sh
export JAVA_HOME='/usr/java/jre1.8.0_191/'
export JAVA_OPTS='-Xmx2000m -Xms1000m'
export DHIS2_HOME='/home/dhis/config'

Step 8: DHIS Installation

wget https://s3-eu-west-1.amazonaws.com/releases.dhis2.org/2.30/dhis.war
sudo mv dhis.war tomcat-dhis/webapps/ROOT.war
sudo nano /home/dhis/tomcat-dhis/bin/startup.sh
#!/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"

Step 10: Running DHIS2

sudo -u dhis tomcat-dhis/bin/startup.sh
tail -f tomcat-dhis/logs/catalina.out
Username: adminPassword: district
sudo -u dhis tomcat-dhis/bin/shutdown.sh

Step 11: Starting DHIS2 at Server Startup

sudo nano tomcat
#!/bin/sh
#Tomcat init script
HOME=/home/dhis/tomcat-dhis/bincase $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
sudo mv tomcat /etc/init.dsudo chmod +x /etc/init.d/tomcat
sudo /usr/sbin/update-rc.d -f tomcat defaults 81

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store