- apache2
- python3
- vitrtualenv
- postgresql
- uwsgi
- uwsgi-plugin-python3
- Log into your system with a sudo user
- Install the above packages
- Change user to the postgresql user and start PostgreSQL CLI
sudo -u postgres psql
- Create a database for the project
CREATE DATABASE [DB-NAME];
- Create a user to log into that database
CREATE USER [USER-NAME] WITH PASSWORD '[SECRET]';
- Give that user all privileges to your created database
GRANT ALL PRIVILEGES ON DATABASE [DB-NAME] TO [USER-NAME];
- Exit the CLI by typing
\q
- Create a folder, like
mkdir /srv/ppsv/
- Enter that directory
cd /srv/ppsv/
- Clone this repository
git clone [URL] .
- Set up a virtual environment and use the proper python version
virtualenv venv -p python3.9
(Python3.9 as of writing this) - Activate that environment
source venv/bin/activate
- Update python tools
pip install --upgrade setuptools pip wheel
- Install the python requirements
pip install requirements.txt
- Create the file
ppsv/ppsv/settings_secrets.py
(you can copy it fromsettings_secrets.py.sample
) and fill it the all necessary secrets (e.g. generated bytr -dc 'a-z0-9!@#$%^&*(-_=+)' < /dev/urandom | head -c50
) (it is a good idea to restrict read permissions from others).
Set the host asHOSTS = ['*']
- If necessary enable uwsgi plugin proxy plugin for Apache like
a2enmod proxy_uwsgi
and follow the shown instructions - Edit the Apache config to serve the application and the static files, e.g. in
/etc/apache2/sites-enabled/000-default.conf
within theVirtualHost
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>
- Restart Apache via
sudo systemctl restart apache2.service
- Create a dedicated system user, e.g.
useradd -r django
- Transfer ownership of the folger to that new user
chown -R django:django /srv/ppsv
- Check paths in
/srv/ppsv/uwsgi-seminarplatzvergabe.ini
and symlink that to/etc/uwsgi/apps-available/
and/etc/uwsgi/apps-enabled/
- Start uwsgi using the config file
uwsgi --ini uwsgi-seminarplatzvergabe.ini
to make sure everything runs without errors - Restart uwsgi
sudo systemctl restart uwsgi
- Make manage.py executable
chmod +x /srv/ppsv/ppsv/manage.py
- Execute the update scripts in
/srv/ppsv
:bash update_prod.sh
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