-
Notifications
You must be signed in to change notification settings - Fork 0
Installation
Bezider Rest API depends mainly on Django (with REST Framework) connected to a Postgres database:
- Django (1.11.1)
- Django REST Framework (3.6.3)
- Postgres (9.6)
- Postgis (2.3)
- Psycopg2 (2.7)
Please keep calm and follow the next steps to set up all propertly before run the server:
- Clone Bezider Rest API repository
- Install a virtual environment
- Install Django and Python Dependecies
- Install and set up a Postgres Database and a User
- Install and Enable Postgis Extension
- Create Superuser and Migrations
- Run the Server
Clone the repository in your home directory or any folder of your preference:
(Falta agregar como instalar la ssh key)
$ cd ~
$ git clone https://github.com/dinostroza/bezider-rest-api.git
$ cd bezider-rest-api
$ git fetch --all
$ git checkout -b develop origin/develop (not develop branch yet)
Install virtualenv and create a virtual environment with python3 as default python version (you might need to install pip):
$ sudo apt-get install python-pip
$ pip install virtualenv
$ virtualenv -p python3 bezider-rest-api
Activate the virtual enviroment and install all requirement packages given in requirements.txt file.
$ cd ~/bezider-rest-api
$ source bin/activate
$ pip install -r requirements.txt
Ubuntu users can follow next steps. If you use a diferent distribution please follow the instructions from oficial web site postgres installation.
- Start adding the PostgreSQL apt repository to access last postgres package. Create the file /etc/apt/sources.list.d/pgdg.list, and add a line for the repository
deb http://apt.postgresql.org/pub/repos/apt/ YOUR_UBUNTU_VERSION_HERE-pgdg main
where YOUR_UBUNTU_VERSION_HERE must be replaced by your ubuntu version, xenial, trusty or precise (16.04, 14.04 or 12.04).
- Import the repository signing key, and update the package list:
$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
$ sudo apt-get update
- Install the postgresql package version 9.6:
$ sudo apt-get install postgresql-9.6
if you have problem with the previous step, check this link.
- Init and check the status of postgresql service to be sure that everything is ok:
$ service postgresql start
$ service postgresql status
9.6/main (port 5432): online
- Log into postgres user to use postgres shell:
$ sudo su postgres
$ psql
- Create the database and user that Bezider Rest Api will use, so time to use SQL commands :
CREATE DATABASE beziderDB;
CREATE USER beziderAdmin WITH PASSWORD 'beziderpass';
Note: the names beziderDB, beziderAdmin and beziderpass can be changed by whatever you want but if you do, change it in database section in ~/bezider-rest-api/api/setting.py in your clone project.
- (Optional) List the databases and users to check they were created as you expected
\l #list databases
\du #list users
- Django expect the database user has some special setting, for detail see the oficial django documentation. Let's do it:
ALTER ROLE beziderAdmin SET client_encoding TO 'utf8';
ALTER ROLE beziderAdmin SET default_transaction_isolation TO 'read committed';
ALTER ROLE beziderAdmin SET timezone TO 'UTC';
- Also the user need to have all privilegies to write and read the database:
GRANT ALL PRIVILEGES ON DATABASE beziderDB TO beziderAdmin;
- Quit! and order a pizza :P
\q
Postgis is an extension to enable some geography, spatial and geometry feactures in Postgres databases.
- Install postgis package 2.3 compatible with the postgres 9.6 version (this package is also provided by the PostgreSQL apt repository added in previous step 4)
$ sudo apt-get install postgresql-9.6-postgis-2.3
- Access beziderDB database and enable postgis:
$ sudo su postgres
$ psql -d beziderdb
CREATE EXTENSION postgis;
- (Optional) Check it with the next command:
\dx
which should show a table with a line as this:
...
postgis | 2.3.2 | public | PostGIS geometry, geography, and raster spatial types and functions
...
- Quit!, and go to sleep.. ZzZz.. continue tomorrow ;)
\q
Now Bezider Rest API can start to use the database and create the necesary tables in it to work correctly. Remember to activate your virtual environment created in the step 2 in these step.
$ cd ~/bezider-rest-api
$ python manage.py makemigrations
$ python manage.py migrate
then create a super user to administrate the project:
$ python manage.py createsuperuser
Finally, run the server. Again, remember to activate your virtual environment created in step 2.
$ python manage.py runserver
and log into django admin website http://127.0.0.1:8000/admin/ to check everything work and start to add data.
Congratulations!!