diff --git a/.gitignore b/.gitignore index 414d9fce79bf1d30073dec93e796fd4ff82ca396..0b9a9af353ca41afc083ce688566c3c9e612f864 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,9 @@ # Secrets for production AKPlanning/settings_secrets.py +# static files generated by django +static/ + # Created by https://www.gitignore.io/api/python,django,virtualenv,pycharm+all # Edit at https://www.gitignore.io/?templates=python,django,virtualenv,pycharm+all @@ -277,4 +280,3 @@ venv.bak/ pip-selfcheck.json # End of https://www.gitignore.io/api/python,django,virtualenv,pycharm+all - diff --git a/AKPlanning/settings.py b/AKPlanning/settings.py index bba79595149c418deff1ac753db748e242d4f64c..3f636a889b905b7727b2d9f0acb19c73fb7ffedb 100644 --- a/AKPlanning/settings.py +++ b/AKPlanning/settings.py @@ -113,3 +113,4 @@ USE_TZ = True # https://docs.djangoproject.com/en/2.2/howto/static-files/ STATIC_URL = '/static/' +STATIC_ROOT = os.path.join(BASE_DIR, 'static') diff --git a/README.md b/README.md index 21a8214f918de355a91be1419a6624692217a11b..2319e89523d4da65e0c14551773f118762782240 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,13 @@ AKPlanning has two types of requirements: System requirements are dependent on o #### System Requirements -* Python 3.7 +* Python 3.7 incl. development tools * Virtualenv +* for production using uwsgi: + * C compiler e.g. gcc + * uwsgi Python3 plugin +* for production using Apache (in addition to uwsgi) + * the mod proxy uwsgi plugin for apache2 #### Python Requirements @@ -58,6 +63,73 @@ To start the application for development use ``python manage.py runserver 0:8000 In your browser, access ``http://127.0.0.1:8000/`` and continue from there. +### Deployment Setup + +This application can be deployed using a web server as any other Django application. +Remember to use a secret key that is not stored in any repository or similar, and disable DEBUG mode (``settings.py``). + +**Step-by-Step Instructions** + +1. log into your system with a sudo user +1. install system requirements +1. create a folder, e.g. ``mkdir /srv/AKPlanning/`` +1. change to the new directory ``cd /srv/AKPlanning/`` +1. clone this repository ``git clone URL .`` +1. setup a virtual environment using the proper python version ``virtualenv env -p python3.7`` +1. activate virtualenv ``source env/bin/activate`` +1. update tools ``pip install --upgrade setuptools pip wheel`` +1. install python requirements ``pip install -r requirements.txt`` +1. install uwsgi ``pip install uwsgi`` +1. create the file ``AKPlanning/settings_secrets.py`` (copy from ``settings_secrets.py.sample``) and fill it with the 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) +1. if necessary enable uwsgi proxy plugin for Apache e.g.``a2enmod proxy_uwsgi`` +1. edit the apache config to serve the application and the static files, e.g. on a dedicated system in ``/etc/apache2/sites-enabled/000-default.conf`` within the ``VirtualHost`` tag add: + + ``` + Alias /static /srv/AKPlanning/static + <Directory /srv/AKPlanning/static> + Require all granted + </Directory> + + ProxyPassMatch ^/static/ ! + ProxyPass / uwsgi://127.0.0.1:3035/ + ``` + + or create a new config (.conf) file under ``/etc/apache2/sites-available``, fill it with something like: + + ```` + <VirtualHost *:80> + + ServerName $SUBDOMAIN + + ServerAdmin $MAILADDRESS + + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + + Alias /static /srv/AKPlanning/static + <Directory /srv/AKPlanning/static> + Require all granted + </Directory> + + ProxyPassMatch ^/static/ ! + ProxyPass / uwsgi://127.0.0.1:3035/ + + RewriteEngine on + RewriteCond %{SERVER_NAME} =$SUBDOMAIN + RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent] + </VirtualHost> + ```` + + replacing $SUBDOMAIN with the subdomain the system should be available under, and $MAILADDRESS with the e-mail address of your administrator. Then symlink it to ``sites-enabled`` e.g. by using ``ln -s /etc/apache2/sites-available/akplanning.conf /etc/apache2/sites-enabled/akplanning.conf``. +1. restart Apache ``sudo systemctl restart apache2.service`` +1. create a dedicated user, e.g. ``adduser django`` +1. transfer ownership of the folder to the new user ``chown -R django:django /srv/WannaDB`` +1. change to the new user ``sudo su django`` +1. change into the Django project folder ``cd WannaDB`` +1. start uwsgi using the configuration file ``uwsgi --ini uwsgi-akplanning.ini`` +1. execute the update script ``./Utils/update.sh --prod`` + + ### Updates To update the setup to the current version on the main branch of the repository use the update script ``Utils/update.sh`` or ``Utils/update.sh --prod`` in production. diff --git a/uwsgi-akplanning.ini b/uwsgi-akplanning.ini index 810d984abee2c7ff3080b1c5174a488e2b63158f..d0f7339645ff02037fe54fa303f2db85d9faffcd 100644 --- a/uwsgi-akplanning.ini +++ b/uwsgi-akplanning.ini @@ -1,6 +1,6 @@ [uwsgi] plugin = python3 -socket = 127.0.0.1:8080 +socket = 127.0.0.1:3035 chdir = /srv/AKPlanning wsgi-file = AKPlanning/wsgi.py touch-reload = %(wsgi-file) @@ -10,4 +10,3 @@ processes = 4 threads = 2 uid = django gid = django -