Skip to content

Instantly share code, notes, and snippets.

@Mirindi
Forked from hallahan/onadata-installation.md
Last active February 3, 2016 13:06
Show Gist options
  • Save Mirindi/7bf893827817bcdb92ce to your computer and use it in GitHub Desktop.
Save Mirindi/7bf893827817bcdb92ce to your computer and use it in GitHub Desktop.

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 postgresql-server-dev-*
$ 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

If the step above ends with permission errors, you could grant sudo to fhuser... temporarily:

#as a root user
$ gpasswd -a fhuser sudo

and then...:

$ sudo pip install -r /home/fhuser/onadata/requirements/base.pip

Setup onadata on Mac OS dev environment


## step 1: install dependencies using brew [Install brew](http://brew.sh/) and run the following commands: ```sh brew install mongo brew install postgis brew install gdal brew install rabbitmq ``` Since rabbitmq is not automatically added to your path, add `PATH=$PATH:/usr/local/sbin` to your `.bash_profile` You might want to [run mongo in the background on startup](https://alicoding.com/how-to-start-mongodb-automatically-when-starting-your-mac-os-x/) or manually using `mongod` command on your terminal each time you run the onadata app.

step 2: pip and virtualenv

Install pip using easy_install pip if you don't have it already.

Install virtualenvwrapper and then create a virtual environment.

step 3: clone

Clone onadata in your directory of choice

step 4: install app requirements

Before you install dependencies from the requirements directory files, ensure you have activated your virtual environment and if not, use the workon <your-virtual-env> to activate it. Then, run the following command:

    pip install fabric
    pip install numpy  --use-mirrors
    pip install -r requirements/base.pip --allow-all-external
    pip install -r requirements/dev.pip

There is a known bug that prevents numpy from installing correctly when in requirements.pip file

step 5: install postgres and create your database

Install postgres and access postgres in your termnial using the command psql and use the following commands to create your user and database:

    CREATE USER <username> WITH PASSWORD '<password>' SUPERUSER CREATEDB LOGIN;
    CREATE DATABASE <database-name> WITH ENCODING='UTF8' LC_CTYPE='en_US.UTF-8' LC_COLLATE='en_US.UTF-8' OWNER=<username> TEMPLATE=template0;

You will also need to create some extensions in your newly created database. Enter the command \c <database-name> to connect to your database then run the following commands to install the extensions:

    CREATE EXTENSION IF NOT EXISTS postgis;`
    CREATE EXTENSION IF NOT EXISTS postgis_topology;

Create local_settings.py file in the root of you cloned app if you don't have one already and update the DATABASE property with the details above.

step 6: install java

At the time of writing this documentation, this link was used to download Java for Mac OS. Install it and run java -version on your terminal to ensure that it has been correctly installed.

step 7: test installation using development server

Run python manage.py runserver

step 8: using celery

Start rabbitmq with the command rabbitmq-server in a different terminal window. Add CELERY_ALWAYS_EAGER = False to your local_settings if doesn't exist already. Run python manage.py celeryd -l debug on the root the app directory in a different terminal window.

step 9: deployment

Use the format fab deploy:<environment>,branch=<branch-name> to make deployments. It's important to note that you will need the appopriate .pem file in order to deploy to AWS. You will need to edit fabfile.py if you want to customize the deployments. e.g. fab deploy:dev,branch=branch

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