OpenSRP Server Build
OpenSRP is an open source project that uses multiple platforms.
For a full server build you will need to install the technology components/programs to install OpenSRP.
JDK 1.8 or above (1.8 is recommended)
Development Editor
CouchDB 1.6.1 - port :5984. (Remember to put properties file, bean id and configure in appcontext of spring); /start couchDB
- CouchDB Lucene 1.1
PostgresSQL 10.2 or above (Install as a service since its only used for reporting) - Port: 5432; /start postgres windows service
ActiveMQ 5.4.2 (To stop Exception of JMS for ActiveMQ appearing in console, change in activemq.prop.. tcp:// to vm:// since both are on same server); /start ActiveMQ
- Mysql 5.6 or above (This is required by the Quartz plugin and opensrp-web)
- Maven 2 or above
Apache-Tomcat 7 or above (Tomcat 7 is recommended)
OpenMRS version 1.12.x or OpenMRS version 2
Debian Linux Installation
You will need to Install jdk1.8 to run the application. To do so, first install OpenJDK or Java JDK (both can be used to build OpenSRP however OpenJDK is recommended).
To install OpenJDK run the following commands from terminal:
sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install openjdk-8-jdk
- After installing Java, set the JAVA_HOME variable - you will need this later in the set up so be sure to set it correctly.
First find out the path of your Java Installation
sudo update-alternatives --config java
It should return something like this:There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1062 auto mode 1 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1061 manual mode 2 /usr/lib/jvm/java-8-oracle/jre/bin/java 1062 manual mode Press enter to keep the current choice[*], or type selection number:
Copy your installed Java path and put it into file /etc/environment
sudo nano /etc/environment
Add the following line at the end of the file (Replace YOUR_PATH with your Java path above up to the base directory
JAVA_HOME="YOUR _PATH"/usr/lib/jvm/java-8-openjdk-amd64/
There's no need to include /jre/bin/java)Reload this file
source /etc/environment
Test it by executing
echo $JAVA_HOME
If you have set it correctly, your path should now show on screen (ie. /usr/lib/jvm/java-8-openjdk-amd64/)
CouchDB v 1.6.1 is used for data storage. Your package manager may have a different version. In this case, we recommend installing a PPA for the development environment. Production setup may be different. CouchDB 2.x is not supported (v 2.x stopped supporting the PPA as well).
sudo apt-get install software-properties-common sudo add-apt-repository ppa:couchdb/stable sudo apt-get update sudo apt-get install couchdb
For ubuntu 18.04 use the following installation method
sudo apt-get install curl curl -L https://couchdb.apache.org/repo/bintray-pubkey.asc \ | sudo apt-key add - echo "deb https://apache.bintray.com/couchdb-deb bionic main" \ | sudo tee -a /etc/apt/sources.list.d/apache_couchdb_bionic.list sudo apt-get update sudo apt-get install apache2 couchdb
Alternatively, follow the CouchDB setup instructions for your environment here.
Install PostgreSQL 10.2 or above.
To install PostgreSQL execute the following commands
sudo apt-get update sudo apt-get install postgresql postgresql-contrib
Connect to the default database with user postgres
sudo -u postgres psql template1
Set the password for user postgres, then exit psql (Ctrl-D)
ALTER USER postgres with encrypted password 'xxxxxxx';
Edit the
pg_hba.conf
filesudo vi /etc/postgresql/10.2/main/pg_hba.conf
And change "peer" to "md5" on the line concerningpostgres
local all postgrespeermd5Restart the database
sudo /etc/init.d/postgresql restart
Whenpostgresqlservice stops use the command to start
sudo service postgresql start
We use Apache ActiveMQ for scheduling activities on the server side (JMS, Quartz, Motech, etc.)
- To install Apache ActiveMQ download the latest stable release from Apache ActiveMQ Site
Extract the download to /opt
sudo tar -xf apache-activemq-x.x.x-bin.tar.gz -C /opt/
To create an ActiveMQ service, create a soft link in init.d using the following command:
sudo ln -snf /opt/apache-activemq-x.x.x/bin/linux-x86-64/activemq /etc/init.d/activemq sudo update-rc.d activemq start 66 3 5 . stop 34 0 1 6 . sudo service activemq start
- Verify it's running by checking the following url:
http://localhost:8161/
Install Maven 2 or above. To install from terminal execute the following command
sudo apt-get install maven
Install tomcat7 you can download it from tomcat apache site. You can follow this instructions to get it up and running.
sudo apt-get install tomcat7
Install mysql using the instructions specified on the mysql documentation for your platform.
For most Debian versions we recommend MySQL 5.6
sudo apt-get install mysql-server-5.6 #If you're using Ubuntu 15.10 or greater sudo apt-get install mysql-server #For those using ubuntu 18.04 and greater, use maria-db instead of Mysql
If you are using Ubuntu 18.04 or greater, use Maria DB 10.3 is recommended
#install software-properties-common sudo apt-get install software-properties-common #Import gpg key sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8 #add the repo. sudo add-apt-repository 'deb [arch=amd64] http://mirror.zol.co.zw/mariadb/repo/10.3/ubuntu bionic main' #install Maria DB sudo apt update sudo apt -y install mariadb-server mariadb-client #you can select your setting for the next set of instructions
Create and initialize the quartz database in MySQL as follows
Download this file tables_quartz_mysql.sql
- Create the quartz database by running: CREATE DATABASE motechquartz; Ensure that the user you created has permission to this database.
- (Optional) Create a user for quartz that only has access to the motechquartz database
- To create the database tables for the motechquartz database: mysql -u root -p"$MYSQL_ROOT_PASSWORD" "motechquartz" < "$PATH_TO"/tables_quartz_mysql.sql
- Install CouchDB Lucene v1.1
Download the source code and unpack the tarball (https://github.com/rnewson/couchdb-lucene/releases/tag/v1.1.0)
tar -xzf couchdb-lucene-1.1.0.tar.gz -C ~/
Enter the directory
cd ~/couchdb-lucene-1.1.0/
Build the project with maven
mvn install
Run maven
mvn
Unzip the build file and install it in the /opt/ directory
sudo tar -xzf target/couchdb-lucene-1.1.0-dist.tar.gz -C /opt/
Rename the distribution folder
sudo mv /opt/couchdb-lucene-1.1.0 /opt/couchdb-lucene
- Configure CouchDB to work with Lucene
Edit the local.ini file
sudo nano /opt/couchdb/etc/local.ini
- Add the following line under the [httpd_global_handlers]
_fti = {couch_httpd_proxy, handle_proxy_req, <<"http://127.0.0.1:5985">>}
- Enter into directory by the command cd /opt/couchdb-lucene/tools/etc/init.d/couchdb-lucene/
- Edit the couchdb-lucene file as DAEMON=/opt/couchdb-lucene/bin/run for your application directory path.
- If you have set your admin user in couchdb Navigate to /opt/couchdb-lucene/conf/ then Edit the couchdb-lucene.ini and edit the last code url = http://localhost:5984/ with url = http://youradminuser:youradminpass@localhost:5984/
- Navigate to /opt/couchdb-lucene/tools/etc/init.d/couchdb-lucene/
- After saving run the command in the terminal cp couchdb-lucene /etc/init.d/
- Restart couchdb service to fall your change effect executing the command sudo service couchdb restart
- Start the couchdb-lucene service executing the command sudo service couchdb-lucene start to create the Channel with couchdb server
- Installing Redis
Install necessary tools to compile redis and dowload the latest version of stable redis
#update your repo sudo apt-get update #download a compiler with build essentials sudo apt-get install build-essential #download tcl language sudo apt-get install tcl8.5 #download the latest stable redis wget http://download.redis.io/releases/redis-stable.tar.gz #untar the package tar xzf redis-stable.tar.gz
Compile and build REDIS Server
#switch to the directory cd redis-stable #elevate your terminal user and type in your password sudo su #run the following tcl commands to compile and install #build make #run tests to ensure there are no errors. Pay attention to any errors shown on screen and resolve make test #install make install
- Run Configuration of Redis, you can use the default options if you like
#Redis comes with default configuration files in the util directory cd utils sudo ./install_server.sh #assuming you used the default options, start redis by using the commands sudo service redis_6379 start sudo service redis_6379 stop #test your redis server by using the command below to start the command line redis-cli #you can quit the cli by typing quit
Configure automatic startup on boot
sudo update-rc.d redis_6379 defaults
Secure your new Redis server
# ensure that the server is only bound to local host ip and has a pssword #open the config file using your preferred editor sudo nano /etc/redis/6379.conf #locate the line 'bind 127.0.0.1' if its commented with a hash sign remove it bind 127.0.0.1 # add a password to your redis server. Locate the line '#requirepass foobared' # remove the # and change 'foobared' to your new password requirepass foobared #restart the server and test the new password sudo service redis-server restart
(Optional) For the development environment install your preferred Java editor Eclipse, STS, NetBeans IDE, IntelliJ IDEA, etc.
STS and IntelliJ IDEA is preferable.
You can download STS (Spring Tools Suite) here
You can download IntelliJ IDEA hereWe changed the way we build the server after our refactor and clean up work
After Server Refactor and Cleanup (Recommended)
Checkout Server Web Build on how to build the generic web application
- Checkout OpenSRP Server Refactor and Clean up for more information
Before Server Refactor and Cleanup
Clone the appropriate OpenSRP Server git repository from https://github.com/OpenSRP/opensrp-server and checkout the correct branch.
git clone https://github.com/OpenSRP/opensrp-server.git git checkout BRANCH_NAME
Each implementation of OpenSRP is maintained in a distinct branch on the OpenSRP GitHub repository.
Below is a list of branches to clone:- Zambia Electronic Immunization - Branch Name: "path"
- TB Reach applicatoin - Branch Name: "tb-reach"
- mCare - Branch Name: "mcare-2"
- Bangladesh - Branch Name: "bd-family-planning"
- Indonesia - Branch Name: "indonesia-server-v2"
- (Optional) Import the git repository into your IDE
- Update the following files with password credentials (MySQL, PostgreSQL and CouchDB)
- assets/config/couchdb.properties
- assets/config/opensrp.properties
- opensrp-web/src/main/resources/quartz.properties
- opensrp-web/src/main/webapp/META-INF/context.xml
- assets/migrations/environments/development.properties
- Build the OpenSRP WAR file in your IDE or maven
- If using maven:
Enter the openrsrp-server folder and make sure you're on the correct branch
cd opensrp-server git status
Run
mvn clean install
from the root directory of opensrp-server. If there are test failures, you can run the mvn clean install -Dmaven.test.skip=true to build and install all the different modules.
- If using maven:
Once tomcat is running, you can install the opensrp.war file from opensrp-web into the webapps directory in order to run the application.
sudo cp opensrp-web/target/opensrp.war /var/lib/tomcat7/webapps/
- Proceed to install OpenMRS using the OpenMRS Installation Guide
Windows Installation
- You will need to download java jdk1.8 to run the application.
- Follow up the following steps to setup java jdk.
- Download and install any development environment of your choice ie, Netbeans, eclipse or Intellij IDE (All can be used however Intellij IDEA 3.0 window's version is recommended).
- Download and install Tomcat 7 to be used as an OpenSRP server.
- Download MySQL database from here and follow up these steps to set it up.
- Install CouchDB v 1.6.1.
- To install CouchDB, download the above release from CouchDB Relax site.
- Double click on the downloaded software to begin the installation process.
- Next on “Welcome” screen
- Accept the License agreement
- Select the installation directory
- Specify “Start Menu” group name
- Approve that you’d like to install CouchDB as service and let it be started automatically after installation (probably, you’d like so)
- Verify installation settings
- Install CouchDB
- Open up Fauxton (if you hadn’t selected autostart CouchDB after installation, you have to start it first manually)
- It’s time to Relax! CouchDB v 1.6.1 is required for data storage.
- Install ActiveMQ to be used for scheduling activities on the server side (JMS, Quartz, Motech, etc.).
- To install ActiveMQ, download the latest release from the Apache ActiveMQ site.
- Copy the downloaded folder to any directory of your choice eg (E:\apache-activemq-5.15.2-bin).
- Click on the bin folder and select the windows bit version you are running.
Open and run the Command prompt as Administrator.
Put in the following lines of code depending on where you placed the Apache ActiveMQ folder.
CMDC:\windows:\system32\cd\ C:\>cd Programs C:\>cd Programs:\apache-activemq-5.15.2-bin C:\>cd Programs:\apache-activemq-5.15.2-bin\cd bin C:\>cd Programs:\apache-activemq-5.15.2-bin\bin\cd win64 C:\>cd Programs:\apache-activemq-5.15.2-bin\bin\win64\InstallService.bat
- (Optional) Download and install postgresSQL 10.2 or above for OpenSRP reporting module and ETL processes.
Create and initialize the quartz database in MySQL as follows
Download this file tables_quartz_mysql.sql
- Create the quartz database by running: CREATE DATABASE motechquartz; Ensure that the user you created has permission to this database.
- (Optional) Create a user for quartz that only has access to the motechquartz database
We changed the way we build the server after our refactor and clean up work
After Server Refactor and Cleanup (Recommended)
Checkout Server Web Build on how to build the generic web application
- Checkout OpenSRP Server Refactor and Clean up for more information
- Before Server Refactor and Cleanup
- Clone the appropriate OpenSRP Server git repository from https://github.com/OpenSRP/opensrp-server and checkout the correct branch,this can be done through your respective IDEs.
- Update the following files with password credentials of MySQL, CouchDB, PostgreSQL and ActiveMQ respectively:
- comment out the CURL command in the pom.xml file for windows installation.
- assets/config/opensrp.properties for CouchDB and MySQL credentials
- opensrp-web/src/main/resources/quartz.properties for MySQL credentials
- assets/config/couchdb.properties CouchDB credentials
- opensrp-web/src/main/webapp/META-INF/context.xml PostgreSQL credentials
- assets/migrations/environments/development.properties PostgreSQL credentials
- Run and build the OpenSRP WAR file in your respective IDE by running the following command;
In the IDE's command line terminal, type in the following command:
codemvn clean install
If the code generates multiples errors, type in the command bellow to build and install all the different modules.
code Blockmvn clean install -Dmaven.test.skip=true
- Generate the OpenSRP war file from the project directory under the webapps target folder.
- Place the downloaded war file into the tomcat folder directory.
- Start tomcat server.
- Once tomcat is up and running, place http://localhost:8080/openmrs in your respective browsers depending on the port numbers you specified while installing tomcat
- follow up the installation initial setup of openmrs to run it according to your desire as well as setting up its MySQL databaseDownload the Openmrs.war file version 1.11.9 from here and follow the installation procedures bellow.
- Once openmrs is installed, place the generated opensrp.war into the same tomcat folder as that of openmrs.war and start tomcat once again
- Open up the openMRS once again and add the following modules to enable you create users for the openSRP mobile application:
- Team module-1.2.2.omod
- reporting-1.15.0.omod
- UI framework-3.13.0.omod
- serialisation.xstream-0.2.12.omod
- Create a team indicating its location and other required credentials. With in the created team, add members who will be granted access to the opensrp App.
- To test whether the user created is authenticated, write http://localhost:8080/opensrp/security/authenticate into your browser and place in the created user credentials. For verification, a JSON file should be returned indicating the user's details.
Mac Installation
For mac installation more or less will be similar with linux
You will need to Install jdk1.8 to run the application.
Download archive jdk1.8 from https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
- Chose Mac OS X x64 to download
- After download finished, double click the dmg file and continue with the installation
If you have multiple jdk installed you can configure your ~/.bash_profile to use jdk1.8. Edit your ~/.bash_profile and add these lines:
export JAVA_7_HOME=$(/usr/libexec/java_home -v1.7) export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8) export JAVA_9_HOME=$(/usr/libexec/java_home -v9) alias java7='export JAVA_HOME=$JAVA_7_HOME' alias java8='export JAVA_HOME=$JAVA_8_HOME' alias java9='export JAVA_HOME=$JAVA_9_HOME' export JAVA_HOME=$JAVA_9_HOME
- CouchDB v 1.6.1 is used for data storage. Your package manager may have a different version. In this case, we recommend installing a PPA for the development environment. Production setup may be different. CouchDB 2.x is not supported (v 2.x stopped supporting the PPA as well).
- Install erlang if you dont have erlang installed, download it from https://packages.erlang-solutions.com/os-x-installer/ErlangInstaller0.9.1.dmg
- Download CouchDB 1.6.1 from https://archive.apache.org/dist/couchdb/source/1.6.1/apache-couchdb-1.6.1.tar.gz
Extract apache-couchdb-1.6.1.tar.gz
Go into extraction folder
- Follow instruction on
INSTALL
file:- Run command line
./configure
- Run command line
make
- Run command line
make install
- Run command line
Load your couchdb on startup
sudo launchctl load /Library/LaunchDaemons/org.apache.couchdb.plist
Install PostgreSQL (source: https://postgresapp.com/)
- Download PostgreSQL app from https://postgresapp.com/ (exp: https://github.com/PostgresApp/PostgresApp/releases/download/v2.1.4/Postgres-2.1.4.dmg)
- Execute the dmg file
- Go to your launch pad and run Postgres App
- Run the server from Postgres App
Open your terminal and run
sudo mkdir -p /etc/paths.d && echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp
Manually access server through terminal command
psql
Then create user opensrp
CREATE USER opensrp_admin WITH LOGIN SUPERUSER INHERIT CREATEDB CREATEROLE ENCRYPTED PASSWORD 'admin' NOREPLICATION;
Then create database opensrp
CREATE DATABASE opensrp WITH OWNER = opensrp_admin ENCODING = 'UTF8' TABLESPACE = pg_default CONNECTION LIMIT = -1;
Restart PostgreSQL by stop and start from Postgres App
We use Apache ActiveMQ for scheduling activities on the server side (JMS, Quartz, Motech, etc.)
- To install Apache ActiveMQ download the latest stable release from http://activemq.apache.org/download.html
Open your terminal and create folder activemq.
cd /Applications/ && sudo mkdir ActiveMQ
Extract the download file to /Applications/ActiveMQ
- Open your
~/.bash_profile
then add linealias activemq="/Applications/ActiveMQ/apache-activemq-5.15.4/bin/activemq"
- Open new terminal and start your activemq server activemq start
- Verify it's running by checking the following url:
http://localhost:8161/
Install Maven 2 or above.
Download maven from http://maven.apache.org/download.cgi
Open your terminal and create folder Maven.
cd /Applications/ && sudo mkdir Maven
Extract the download file to /Applications/Maven
- Open your
~/.bash_profile
then add lineexport PATH=/Applications/Maven/apache-maven-3.5.3/bin:${PATH}
- Open new terminal and see if your maven installed
mvn -version
Install tomcat7
you can download it from http://tomcat.apache.org/. Let say you download Tomcat 8.0.53: https://tomcat.apache.org/download-80.cgi
Open your terminal and create folder Tomcat.
cd /Applications/ && sudo mkdir Tomcat
Extract the download file to /Applications/Tomcat
Open your
~/.bash_profile
then add linetomcat(){ if [ $1 ]; then /Applications/Tomcat/apache-tomcat-8.0.53/bin/$1.sh fi }
Open new terminal and start tomcat by using
tomcat startup
- You can run sh file inside /Applications/Tomcat/apache-tomcat-8.0.53/bin/ by using command
tomcat xxxxxxx
Install mysql
You can follow the instruction from https://dev.mysql.com/doc/refman/5.6/en/osx-installation-pkg.html
To make your work easier, you can install mysql workbench from https://dev.mysql.com/doc/workbench/en/wb-installing-mac.html
Create and initialize the quartz database in MySQL as follows
Download this file tables_quartz_mysql.sql
- Create the quartz database by running: CREATE DATABASE motechquartz; Ensure that the user you created has permission to this database.
- (Optional) Create a user for quartz that only has access to the motechquartz database
- To create the database tables for the motechquartz database: mysql -u root -p"$MYSQL_ROOT_PASSWORD" "motechquartz" < "$PATH_TO"/tables_quartz_mysql.sql
- Install CouchDB Lucene v1.1 (https://github.com/rnewson/couchdb-lucene)
Download the source code and unpack the tarball (https://github.com/rnewson/couchdb-lucene/releases/tag/v1.1.0)
tar -xzf couchdb-lucene-1.1.0.tar.gz -C ~/
Enter the directory
cd ~/couchdb-lucene-1.1.0/
Build the project with maven
mvn install
Run maven
mvn
Unzip the build file and install it in the /opt/ directory
sudo tar -xzf target/couchdb-lucene-1.1.0-dist.tar.gz -C /opt/
Rename the distribution folder
sudo mv /opt/couchdb-lucene-1.1.0 /opt/couchdb-lucene
- Configure CouchDB to work with Lucene
Edit the local.ini file
sudo nano ~/Library/Preferences/couchdb2-local.ini
Add the following line
[httpd_global_handlers] _fti = {couch_httpd_proxy, handle_proxy_req, <<"http://127.0.0.1:5985">>}
- Open your
~/.bash_profile
then add line aliascouchdb-lucene="/opt/couchdb-lucene/bin/run"
- If you have set your admin user in couchdb Navigate to /opt/couchdb-lucene/conf/ then Edit the couchdb-lucene.ini and edit the last code url = http://localhost:5984/ with url = http://youradminuser:youradminpass@localhost:5984/
Restart couchdb service to fall your change effect executing the command
sudo launchctl stop org.apache.couchdb && sudo launchctl start org.apache.couchdb
Open new terminal and run
couchdb-lucene
(Optional) For the development environment install your preferred Java editor Eclipse, STS, NetBeans IDE, IntelliJ IDEA, etc.
STS and IntelliJ IDEA is preferable.
You can download STS (Spring Tools Suite) here
You can download IntelliJ IDEA hereWe changed the way we build the server after our refactor and clean up work
After Server Refactor and Cleanup (Recommended)
Checkout Server Web Build on how to build the generic web application
- Checkout OpenSRP Server Refactor and Clean up for more information
- Before Server Refactor and Cleanup
Clone the appropriate OpenSRP Server git repository from https://github.com/OpenSRP/opensrp-server and checkout the correct branch.
git clone https://github.com/OpenSRP/opensrp-server.git git checkout BRANCH_NAME
Each implementation of OpenSRP is maintained in a distinct branch on the OpenSRP GitHub repository.
Below is a list of branches to clone:- Zambia Electronic Immunization - Branch Name: "path"
- TB Reach applicatoin - Branch Name: "tb-reach"
- mCare - Branch Name: "mcare-2"
- Bangladesh - Branch Name: "bd-family-planning"
- Indonesia - Branch Name: "indonesia-server-v2"
- (Optional) Import the git repository into your IDE
- Update the following files with password credentials (MySQL, PostgreSQL and CouchDB)
- assets/config/couchdb.properties
- assets/config/opensrp.properties
- opensrp-web/src/main/resources/quartz.properties
- opensrp-web/src/main/webapp/META-INF/context.xml PostgreSQL credentials
- assets/migrations/environments/development.properties PostgreSQL credentials
- Build the OpenSRP WAR file in your IDE or maven
- If using maven:
Enter the openrsrp-server folder and make sure you're on the correct branch
cd opensrp-server git status
Run
mvn clean install
from the root directory of opensrp-server. If there are test failures, you can run the mvn clean install -Dmaven.test.skip=true to build and install all the different modules.
- If using maven:
Once tomcat is running, you can install the opensrp.war file from opensrp-web into the webapps directory in order to run the application.
sudo cp opensrp-web/target/opensrp.war /Applications/Tomcat/apache-tomcat-x.x.xx/webapps/
Proceed to install OpenMRS using the OpenMRS Installation Guide
This site is no longer maintained. Please visit docs.opensrp.io for current documentation.