Skip to content

Instantly share code, notes, and snippets.

@hallahan
Last active March 17, 2017 13:03
Show Gist options
  • Save hallahan/6b9de942f65d5f8c2c62 to your computer and use it in GitHub Desktop.
Save hallahan/6b9de942f65d5f8c2c62 to your computer and use it in GitHub Desktop.
onaio/onadata Installation Instructions

onadata Install Instructions

Ubuntu 14.04

1. Basic System Libraries and Packages

$ sudo apt-get update; sudo apt-get upgrade -y
$ sudo apt-get install -y git build-essential python-all-dev \
  python-pip python-lxml python-magic python-imaging default-jre \
  libjpeg-dev libfreetype6-dev zlib1g-dev rabbitmq-server libxslt1-dev

2. Define the formhub user account

Create fhuser, the user account which will own and run the formhub processes, and set its password:

$ sudo adduser fhuser

3. Install PostgreSQL

Install the required packages and libraries:

$ sudo apt-get install -y postgresql python-psycopg2 postgresql-contrib
$ sudo pip install south

Then configure the database for formhub. Create a data folder for the database to use:

$ sudo service postgresql stop
$ sudo mkdir -p /opt/data/formhub/pgsql
$ sudo chown postgres /opt/data/formhub/pgsql

Backup the original version of postgresql.conf as postgresql.conf.orig:

$ cd /etc/postgresql/9.3/main
$ sudo cp -ip postgresql.conf postgresql.conf.orig

Change the data_directory variable to point to the pgsql formhub data folder (i.e., /opt/data/formhub/pgsql).

Also, turn off the ssl option:

$ sudo vim postgresql.conf
# (edit lines 41 and 81 -- here is the before and after) 

$ diff postgresql.conf postgresql.conf.orig 
41c41
< data_directory = '/opt/data/formhub/pgsql'		# use data in another directory
---
> data_directory = '/var/lib/postgresql/9.3/main'		# use data in another directory
81c81
< ssl = false				# (change requires restart)
---
> ssl = true				# (change requires restart)

Switch to the postgres account and initialize the database and database user for access by the formhub django application.

$ sudo su - postgres 
$ /usr/lib/postgresql/9.3/bin/initdb -D /opt/data/formhub/pgsql
$ /usr/lib/postgresql/9.3/bin/pg_ctl -D /opt/data/formhub/pgsql -l logfile start
$ /usr/lib/postgresql/9.3/bin/createuser -P formhubDjangoApp

Enter a password for the formhubDjangoApp database user. You will need this later, for the in the django default_settings.py file.

Create the logical database FormhubDjangoDB for the formhub django application and enable uuid creation:

$ /usr/lib/postgresql/9.3/bin/createdb FormhubDjangoDB
$ /usr/lib/postgresql/9.3/bin/psql -d FormhubDjangoDB

You will be presented with the FormhubDjangoDB=# prompt. Enter the following command, then \q to exit the database shell:

FormhubDjangoDB=# CREATE EXTENSION "uuid-ossp";
FormhubDjangoDB=# \q

Finally, turn postgres off, and exit the postgres account:

$ /usr/lib/postgresql/9.3/bin/pg_ctl -D /opt/data/formhub/pgsql -l logfile stop
$ exit

Backup and edit the pg_hba.conf file for database access security. Change line 90 from peer to md5 (for more about these options, see the pg_hba.conf file documentation):

$ cd /etc/postgresql/9.3/main
$ sudo cp -ip pg_hba.conf pg_hba.conf.org
$ sudo vim pg_hba.conf
# (here is the before and after)
$ sudo diff pg_hba.conf.org pg_hba.conf
90c90
< local   all             all                                     peer
---
> local   all             all                                     md5

Restart the database, and test that it asks for a password for access:

$ sudo service postgresql restart
$ /usr/lib/postgresql/9.3/bin/psql -d FormhubDjangoDB -U formhubDjangoApp -h localhost

If your configurations are correct, you should be prompted for a password, like this:

Password for user formhubDjangoApp: 

You can either input the password you used to create the formhubDjangoApp user earlier, then type \q to exit, or just Control-C to quit.

Phew!

That was a lot of work, but your databases are ready, and you won't have to touch these settings again, even if you have to reboot or restart the server later.

4. Install formhub

Switch to the fhuser account and make sure you are in the home folder of the correct account:

$ sudo su - fhuser
$ pwd
$ whoami

You should see /home/fhuser as the result of the pwd command, and fhuser as the result of whoami.

Obtain the onadata source from github:

$ git clone https://github.com/onaio/onadata.git

If you are using this guide before this branch (osm) has been merged into the onadata master branch, then you will need to use git's checkout command first, as follows:

$ cd ~/onadata
$ git checkout osm

Then confirm you are on the correct branch, before continuing:

$ git branch

You should see ona marked with an asterisk, like this:

  master
* osm

Install the python packages required for onadata:

$ pip install -r /home/fhuser/onadata/requirements/base.pip
@allans254
Copy link

then how do you start the ona server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment