$ 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
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.
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
then how do you start the ona server