-
Notifications
You must be signed in to change notification settings - Fork 2
Development Installation
-
Create a DEVELOPMENT DIRECTORY
- this doc will assume Unix formatted addresses:
- if running Windows, you will use
\
instead of/
- if running Windows, you will use
- Put this somewhere where your user has full privileges, like one of the following examples:
- Linux: /home/YOUR_USER_NAME/projects
- Max: /Users/YOUR_USER_NAME/projects
- Windows would looks something like
C:\Users\YOUR_USER_NAME\projects
- this doc will assume Unix formatted addresses:
-
Clone repository into your DEVELOPMENT DIRECTORY
cd /YOUR/DEVELOPMENT/DIRECTORY/ git clone https://github.com/Ecotrust/TEKDB.git
-
Deploy base box with Vagrant
cd /YOUR/DEVELOPMENT/DIRECTORY/TEKDB/ vagrant up
- Wait while your new VM installs all of the required dependencies
- if you see an error like:
default: cannot touch '/home/ubuntu/.bash_aliases' default: : Permission denied default: /vagrant/scripts/vagrant_provision_ubuntu.sh: line 43: /home/ubuntu/.bash_aliases: Permission denied The SSH command responded with a non-zero exit status. Vagrant assumes that this means the command failed. The output for this command should be in the log above. Please read the output to determine what went wrong.
- this likely means your vagrant VM is using 'vagrant' for the default user, but all of the code assumes 'ubuntu' as the default user. Fix this by:
vagrant halt
vagrant destroy
- Comment out the line in Vagrantfile that reads:
config.ssh.username = "ubuntu"
- vagrant assumes a user of 'vagrant' - the box assigns all passwords and public keys to this user, so we need to log in with this user, create the 'ubuntu' user that we need to finish up, and re-provision from there.
vagrant up
vagrant ssh
sudo cp /home/vagrant/.ssh/authorized_keys /home/ubuntu/.ssh/
exit
- Then edit Vagrantfile to include:
config.ssh.username = "ubuntu"
vagrant halt
vagrant up --provision
- this likely means your vagrant VM is using 'vagrant' for the default user, but all of the code assumes 'ubuntu' as the default user. Fix this by:
-
Log in to your new VM and run updates
vagrant ssh sudo apt-get update sudo apt-get upgrade
-
Grant Write Access to Apps Directory
sudo chown vagrant:vagrant /usr/local/apps
-
Update Local Settings
- Copy local_settings.py.template to local_settings.py in one of the two locations below
- On Host server:
/YOUR/DEVELOPMENT/DIRECTORY/TEKDB/TEKDB/TEKDB/local_settings.py
- On Vagrant VM:
/usr/local/apps/TEKDB/TEKDB/local_settings.py
- On Host server:
- Things to change:
- DEBUG: add a line that reads
DEBUG=True
- this is only to be used for development environments, not live servers. - DEBUG: add a line that reads
ALLOWED_HOSTS = [ 'localhost', u'tekdb.domain.com', ]
-
# SECRET_KEY='fixthisdjango' # DATABASES = { # 'default': { # 'ENGINE': 'django.contrib.gis.db.backends.postgis', # 'NAME': 'DB Name', # 'USER': 'add user', # 'PASSWORD': 'add password', # 'HOST': 'add host', # 'PORT': add number, # } # } # TIME_ZONE = 'America/Los_Angeles' # To see all Timezone options, see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List # DEBUG = True - this is only to be used for development environments, not live servers.
- DEBUG: add a line that reads
- Copy local_settings.py.template to local_settings.py in one of the two locations below
-
SECRET_KEY: change to a long string of gibberish - you never need to type this in, so the longer and more complex the better
-
DATABASE_GEOGRAPHY: basic geo settings so the maps know where to focus by default in the admin
- For example:
DATABASE_GEOGRAPHY = { 'default_lon': -124.2, 'default_lat': 41.9, 'default_zoom': 10, 'map_template': 'gis/admin/ol2osm.html', }
- NOTES:
- LAT/LON: the lon and lat presented here are Coordinates (EPSG:4326) for the Northern CA coast. At the time of this writing, the tool only supports coordinates in Web Mercator (EPSG:3857), so the longitude would actually be
-13825880.7546
and the latitude is5146011.678566459
. - ZOOM: The higher the number, the more closely zoomed in the map will be by default.
- TEMPLATE: The location of the html template for displaying the map in the admin tool for geometry fields.
- LAT/LON: the lon and lat presented here are Coordinates (EPSG:4326) for the Northern CA coast. At the time of this writing, the tool only supports coordinates in Web Mercator (EPSG:3857), so the longitude would actually be
- For example:
-
Install dependencies
sudo apt-get install git python3 python3-pip python3-virtualenv virtualenv gcc make uwsgi uwsgi-plugin-python3 gdal-bin python3-gdal python3-dev build-essential -y sudo apt install postgresql-14 postgresql-contrib postgresql-server-dev-14 postgis postgresql-14-postgis-3 -y
-
Create Postgres Database
sudo -u postgres createdb tekdb
-
Virtual Environment Setup
cd /usr/local/apps sudo apt install python3-virtualenv virtualenv virtualenv env --python=python3
-
Activate your python virtual environment
source /usr/local/apps/env/bin/activate
-
Install requirements
pip3 install -r /usr/local/apps/TEKDB/TEKDB/requirements.txt
-
Enable External Access to Postgres Enable authentication from remote access
sudo vim /etc/postgresql/14/main/pg_hba.conf
Find the section of uncommented lines near the bottom. Change for the user postgres to:
local all postgres trust
Restart Postgresql service
sudo service postgresql restart
-
Uncomment
DATABASE
inlocal_settings.py
DATABASES = { 'default': { 'ENGINE': 'django.contrib.gis.db.backends.postgis', 'NAME': 'tekdb', 'USER': 'postgres', #'PASSWORD': '<PASSWORD>', #'HOST': 'localhost', #'PORT': 5432, }
-
Run migration
python /usr/local/apps/TEKDB/TEKDB/manage.py migrate
-
Run static file collection
python /usr/local/apps/TEKDB/TEKDB/manage.py collectstatic
-
Load in data
python /usr/local/apps/TEKDB/TEKDB/manage.py loaddata /usr/local/apps/TEKDB/TEKDB/TEKDB/fixtures/default_users_fixture.json python /usr/local/apps/TEKDB/TEKDB/manage.py loaddata /usr/local/apps/TEKDB/TEKDB/TEKDB/fixtures/default_lookups_fixture.json
-
Test your installation with Django’s Dev Server
python /usr/local/apps/TEKDB/TEKDB/manage.py runserver 0.0.0.0:8000
- DJ Shortcut
Many of the commands below assume an activated virtual environment and explicitly call the manage.py script. You can save yourself some typing in the future by replaceing these commands with the alias 'dj' for 'manage.py':
Then add the following to the bottom of the file:
sudo vim /etc/bash.bashrc
Then refresh your session by dropping out and reconnecting to your server:alias dj="/usr/local/apps/env/bin/python /usr/local/apps/TEKDB/TEKDB/manage.py" alias djrun="dj runserver 0.0.0.0:8000"
exit vagrant ssh