Skip to content

Development Installation

Anna Cho edited this page Sep 18, 2024 · 28 revisions

Development Installation:

  1. Create a DEVELOPMENT DIRECTORY

    1. this doc will assume Unix formatted addresses:
      1. if running Windows, you will use \ instead of /
    2. Put this somewhere where your user has full privileges, like one of the following examples:
      1. Linux: /home/YOUR_USER_NAME/projects
      2. Max: /Users/YOUR_USER_NAME/projects
      3. Windows would looks something like C:\Users\YOUR_USER_NAME\projects
  2. Install Git

  3. Clone repository into your DEVELOPMENT DIRECTORY

    cd /YOUR/DEVELOPMENT/DIRECTORY/
    git clone https://github.com/Ecotrust/TEKDB.git
    
  4. Install Vagrant

  5. Deploy base box with Vagrant

    cd /YOUR/DEVELOPMENT/DIRECTORY/TEKDB/
    vagrant up
    
    1. Wait while your new VM installs all of the required dependencies
    2. 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.
      
      1. 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:
        1. vagrant halt
        2. vagrant destroy
        3. 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.
        4. vagrant up
        5. vagrant ssh
        6. sudo cp /home/vagrant/.ssh/authorized_keys /home/ubuntu/.ssh/
        7. exit
        8. Then edit Vagrantfile to include: config.ssh.username = "ubuntu"
        9. vagrant halt
        10. vagrant up --provision
  6. Log in to your new VM and run updates

    vagrant ssh
    sudo apt-get update
    sudo apt-get upgrade
    
  7. Grant Write Access to Apps Directory

    sudo chown vagrant:vagrant /usr/local/apps
    
  8. Update Local Settings

    1. Copy local_settings.py.template to local_settings.py in one of the two locations below
      1. On Host server: /YOUR/DEVELOPMENT/DIRECTORY/TEKDB/TEKDB/TEKDB/local_settings.py
      2. On Vagrant VM: /usr/local/apps/TEKDB/TEKDB/local_settings.py
    2. Things to change:
      1. DEBUG: add a line that reads DEBUG=True - this is only to be used for development environments, not live servers.
      2. DEBUG: add a line that reads `DEBUALLOWED_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 = FalseG=True` - this is only to be used for development environments, not live servers. 
  1. SECRET_KEY: change to a long string of gibberish - you never need to type this in, so the longer and more complex the better
  2. DATABASE_GEOGRAPHY: basic geo settings so the maps know where to focus by default in the admin
    1. For example: DATABASE_GEOGRAPHY = { 'default_lon': -124.2, 'default_lat': 41.9, 'default_zoom': 10, 'map_template': 'gis/admin/ol2osm.html', }
    2. NOTES:
      1. 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 is 5146011.678566459.
      2. ZOOM: The higher the number, the more closely zoomed in the map will be by default.
      3. TEMPLATE: The location of the html template for displaying the map in the admin tool for geometry fields.
  3. Virtual Environment Setup
    cd /usr/local/apps
    sudo apt install python3-virtualenv virtualenv
    virtualenv env --python=python3
    
  4. Activate your python virtual environment
    source /usr/local/apps/env/bin/activate
    
  5. Install requirements
    pip3 install -r /usr/local/apps/TEKDB/TEKDB/requirements.txt
    
  6. 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
    
  7. Create Database and User. You will be prompted to enter a password of your choice.
    sudo -u postgres createuser -s -P USERNAME
    sudo -u postgres createdb -O USERNAME tekdb
    
  8. 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
    
    Log out and log back into your VM
    ctrl+D
    vagrant ssh
    
  9. Uncomment DATABASE in local_settings.py
    DATABASES = {
     'default': {
         'ENGINE': 'django.contrib.gis.db.backends.postgis',
         'NAME': 'tekdb',
         'USER': '<USERNAME>',
         'PASSWORD': '<PASSWORD>',
         'HOST': 'localhost',
         'PORT': 5432,
     }
    
  10. Run migration
    python /usr/local/apps/TEKDB/TEKDB/manage.py migrate
    
  11. Run static file collection
    python /usr/local/apps/TEKDB/TEKDB/manage.py collectstatic
    
  12. 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
    
  13. Test your installation with Django’s Dev Server
    python /usr/local/apps/TEKDB/TEKDB/manage.py runserver 0.0.0.0:8000
    
    1. Open http://localhost:8111

Clone this wiki locally