Skip to content

Latest commit

 

History

History
77 lines (69 loc) · 3.51 KB

INSTALL.md

File metadata and controls

77 lines (69 loc) · 3.51 KB

Deployment Setup

Needed linux packages

  • apache2
  • python3
  • vitrtualenv
  • postgresql
  • uwsgi
  • uwsgi-plugin-python3

Step-by-step guide

General

  1. Log into your system with a sudo user
  2. Install the above packages

Installing postgresql

  1. Change user to the postgresql user and start PostgreSQL CLI sudo -u postgres psql
  2. Create a database for the project CREATE DATABASE [DB-NAME];
  3. Create a user to log into that database CREATE USER [USER-NAME] WITH PASSWORD '[SECRET]';
  4. Give that user all privileges to your created database GRANT ALL PRIVILEGES ON DATABASE [DB-NAME] TO [USER-NAME];
  5. Exit the CLI by typing \q

Setting up the project

  1. Create a folder, like mkdir /srv/ppsv/
  2. Enter that directory cd /srv/ppsv/
  3. Clone this repository git clone [URL] .
  4. Set up a virtual environment and use the proper python version virtualenv venv -p python3.9 (Python3.9 as of writing this)
  5. Activate that environment source venv/bin/activate
  6. Update python tools pip install --upgrade setuptools pip wheel
  7. Install the python requirements pip install requirements.txt
  8. Create the file ppsv/ppsv/settings_secrets.py (you can copy it from settings_secrets.py.sample) and fill it the all necessary secrets (e.g. generated by tr -dc 'a-z0-9!@#$%^&*(-_=+)' < /dev/urandom | head -c50) (it is a good idea to restrict read permissions from others).
    Set the host as HOSTS = ['*']
  9. If necessary enable uwsgi plugin proxy plugin for Apache like a2enmod proxy_uwsgi and follow the shown instructions
  10. Edit the Apache config to serve the application and the static files, e.g. in /etc/apache2/sites-enabled/000-default.conf within the VirtualHost tag add:
Alias /static /srv/ppsv/ppsv/static
<Directory /srv/ppsv/ppsv/static>
Require all granted
</Directory>

ProxyPassMatch ^/static/ !
ProxyPass / uwsgi://127.0.0.1:3035/

Or create in that directory a new file e.g. apache-ppsv.conf and symlink that via ln -s /etc/apache2/sites-available/apache-ppsv.conf /etc/apache2/sites-enabled/apache-ppsv.conf

<VirtualHost *:80>
        ServerName [INSERT DOMAIN HERE]
        ServerAdmin webmaster@localhost

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        Alias /static /srv/ppsv/ppsv/static
        <Directory /srv/ppsv/ppsv/static>
        Require all granted
        </Directory>

        ProxyPassMatch ^/static/ !
        ProxyPass / uwsgi://127.0.0.1:3035/
</VirtualHost>
  1. Restart Apache via sudo systemctl restart apache2.service
  2. Create a dedicated system user, e.g. useradd -r django
  3. Transfer ownership of the folger to that new user chown -R django:django /srv/ppsv
  4. Check paths in /srv/ppsv/uwsgi-seminarplatzvergabe.ini and symlink that to /etc/uwsgi/apps-available/ and /etc/uwsgi/apps-enabled/
  5. Start uwsgi using the config file uwsgi --ini uwsgi-seminarplatzvergabe.ini to make sure everything runs without errors
  6. Restart uwsgi sudo systemctl restart uwsgi
  7. Make manage.py executable chmod +x /srv/ppsv/ppsv/manage.py
  8. Execute the update scripts in /srv/ppsv: bash update_prod.sh

P.S.

If you need to run the application without HTTPS, you might need to set SESSION_COOKIE_SECURE = False and CSRF_COOKIE_SECURE = False in ppsv/ppsv/settings_production.py.
But if you want to use HTTPS and need a certificate, you can check out Let's Encrypt