Installation

Requirements

  • Ubuntu Linux 24.04.

  • 1GB of RAM

  • 10GB of disk space

  • At least 2 CPU cores.

Installation Instructions

  1. Create a new user for the system using the following command:

    sudo useradd -UM apptrax
    
  2. Install dependencies:

    sudo apt install python3-venv git postgresql
    
  3. Create /var/www/apptrax and have it owned by the new user:

    sudo mkdir -p /var/www/apptrax
    sudo chown apptrax /var/www/apptrax
    
  4. 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
    
  5. Create the python virtualenv for the project and install dependencies:

    cd final-year-project/source
    python -m venv env
    pip install -r requirements.txt
    
  6. Run the collectstatic command to collect all the static files:

    cd apptrax DJANGO_SETTINGS_MODULE=apptrax.production ./manage.py collectstatic

  7. Build the documentation into HTML files:

    cd ../docs
    make html
    
  8. 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",
        }
    }
    
  9. Create the gunicorn file in final-year-project/src/apptrax/apptrax/production.py:

    bind = "localhost:3000"
    workers = 4
    keepalive = 5
    
    wsgi_app = "apptrax.wsgi"
    
  10. 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
    
  11. 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
    
  12. 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;
    
  13. 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
    
  14. Install Caddy following the instructions in https://caddyserver.com/docs/install#debian-ubuntu-raspbian.

  15. 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
            }
    }
    
  16. Setup your DNS for the domain to point to this IP address before starting the server.

  17. 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