Installation¶
Requirements¶
Ubuntu Linux 24.04.
1GB of RAM
10GB of disk space
At least 2 CPU cores.
Installation Instructions¶
Create a new user for the system using the following command:
sudo useradd -UM apptrax
Install dependencies:
sudo apt install python3-venv git postgresql
Create /var/www/apptrax and have it owned by the new user:
sudo mkdir -p /var/www/apptrax sudo chown apptrax /var/www/apptrax
Use sudo to login as the apptrax user and clone the repository:
sudo su - apptrax cd /var/www/apptrax git clone https://gitlab.com/nigelbabu/final-year-project.git
Create the python virtualenv for the project and install dependencies:
cd final-year-project/source python -m venv env pip install -r requirements.txt
Run the collectstatic command to collect all the static files:
cd apptrax DJANGO_SETTINGS_MODULE=apptrax.production ./manage.py collectstatic
Build the documentation into HTML files:
cd ../docs make html
Create a production settings file for the project with the following contents in final-year-project/src/apptrax/apptrax/production.py:
from apptrax.settings import * SECRET_KEY='<insert a random string here>' CSRF_COOKIE_SECURE=True SESSION_COOKIE_SECURE=True ALLOWED_HOSTS = ['<insert domain name>'] CSRF_TRUSTED_ORIGINS = ['<insert domain name>'] STATIC_ROOT='/var/www/apptrax/static' DEBUG = False EMAIL_HOST = "<insert email host>" EMAIL_PORT = 587 EMAIL_HOST_USER = "<insert email host user>" EMAIL_HOST_PORT = "<insert email host password>" DATABASES = { "default": { "ENGINE": "django.db.backends.postgresql", "NAME": "<db name>", "USER": "<db user>", "PASSWORD": "<db password>", "HOST": "127.0.0.1", "PORT": "5432", } }
Create the gunicorn file in final-year-project/src/apptrax/apptrax/production.py:
bind = "localhost:3000" workers = 4 keepalive = 5 wsgi_app = "apptrax.wsgi"
Create the service file for gunicorn in /etc/systemd/system/gunicorn.service:
[Install] WantedBy=multi-user.target [Unit] Description=Gunicorn service After=network.target [Service] Environment="DJANGO_SETTINGS_MODULE=apptrax.production" WorkingDirectory=/var/www/apptrax/final-year-project/src/apptrax ExecStart=/var/www/apptrax/final-year-project/src/env/bin/gunicorn ProtectSystem=strict
Create the Celery service file in /etc/systemd/system/celery.service:
[Unit] Description=Celery Service After=network.target,redis-server.service Requires=redis-server.service [Service] Environment="DJANGO_SETTINGS_MODULE=apptrax.production" WorkingDirectory=/home/nigelb/final-year-project/src/apptrax ExecStart=/home/nigelb/final-year-project/src/env/bin/celery -A apptrax multi start worker -l INFO ExecStop=/home/nigelb/final-year-project/src/env/bin/celery -A apptrax multi stopwait worker -l INFO ExecReload=/home/nigelb/final-year-project/src/env/bin/celery -A apptrax multi restart worker -l INFO Restart=always [Install] WantedBy=multi-user.target nigelb@apptrax:~/final-year-project/src/apptrax$ cat /etc/systemd/system/gunicorn.service
Setup the postgres database for the service:
# First login to Postgres sudo -u postgres psql # Enter into the PSQL shell create database apptrax; create user apptrax with encrypted password '<insert password>'; grant all privileges on database apptrax to apptrax; ALTER ROLE apptrax SET client_encoding TO 'utf8'; ALTER ROLE apptrax SET default_transaction_isolation TO 'read committed'; ALTER ROLE apptrax SET timezone TO 'UTC'; # Connect to DB as root \c apptrax; GRANT ALL ON schema public TO apptrax;
Setup the postgresql connection parameters in /etc/postgresql/16/main/pg_hba.conf. Ensure that IPv4 local connections do not use peer authentication:
host all all 127.0.0.1/32 scram-sha-256
Install Caddy following the instructions in https://caddyserver.com/docs/install#debian-ubuntu-raspbian.
Setup the Caddyfile in /etc/caddy/Caddyfile as follows:
{ debug } <enter-your-hostname> { encode zstd gzip handle_path /static/* { file_server { root "/var/www/apptrax/static" } } handle_path /docs/* { file_server { root "/var/www/apptrax/final-year-project/src/docs/build/html" } } handle { reverse_proxy localhost:3000 } }
Setup your DNS for the domain to point to this IP address before starting the server.
Start the gunicorn service, celery service, and postgresql services:
sudo systemctl start gunicorn sudo systemctl start celery sudo systemctl enable gunicorn sudo systemctl enable celery sudo systemctl enable caddy sudo systemctl start caddy