Skip to content

Installation sur Debian 12

Prérequis

Serveur web

apt install apache2 libapache2-mod-wsgi-py3
systemctl enable apache2

Bases de données

apt install postgresql
systemctl enable postgresql
cat /etc/postgresql/15/main/pg_hba.conf
local all postgres peer
local db user md5

Création d'un utilisateur:

sudo -u postgres createuser --pwprompt user 
sudo -u postgres createdb --owner=user db

Accès à la socket Postgres:

adduser www-data postgres
systemctl restart postgresql

Application web

Pour l'installation, vous pouvez soit récupérer la dernière version disponible ou utiliser directement le dépôt git.

Utilisation d'une version

La liste des versions se trouve ici: https://framagit.org/bonnegent/pytournois

La dernière version git

cd /opt
git clone https://framagit.org/bonnegent/pytournois.git

Configuration

Toute la configuration doit être dans le fichier conf/local_settings.py (nouveau fichier). Cette configuration va remplacer la configuration se trouvant dans conf/settings.py. Voici un exemple de contenu:

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.postgresql_psycopg2",
        "NAME": "db",
        "USER": "user",
        "PASSWORD": "PASS",
        "HOST": "/var/run/postgresql",
    }
}
DEBUG = False
SECURE_SSL_REDIRECT = True
SECURE_HSTS_SECONDS = 31536000
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
CSRF_COOKIE_SECURE = True
SESSION_COOKIE_SECURE = True
SECURE_HSTS_PRELOAD = True
ALLOWED_HOSTS = ["tournois.example.com"]
SECRET_KEY = "django-insecure--9w@7o0@qn^o$fby#equd3&()qfzyean3ew75(+lytfr0(+n*7"

ADMINS = [
    ("Admin", "admin@example.com"),
]
EMAIL_HOST = "smtp.example.com"
EMAIL_PORT = 25
SERVER_EMAIL = "noreply@example.com"

Python

apt install python3-pip python3-poetry
cd /opt/pytournois
poetry config virtualenvs.in-project true
./oto.sh prod_up_2
chown -R www-data:www-data .

Activation d'un compte administrateur

cd /opt/pytournois
./oto.sh prod_sh
> user, flag = User.objects.get_or_create(username="votre_login")
> user.is_staff = True
> user.is_superuser = True
> user.save()

Configuration Apache

Référence: https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/modwsgi/

Exemple de configuration Apache (/etc/apache2/sites-available/tournois.conf):

ServerSignature off
ServerTokens prod
ServerAdmin admin@example.com

<VirtualHost tournois.example.com:80>
    Redirect permanent / https://tournois.example.com/
</VirtualHost>

<VirtualHost tournois.example.com:443>
    ServerName tournois.example.com
    SSLEngine on
    SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
    SSLCipherSuite ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
    SSLHonorCipherOrder off
    SSLSessionTickets off
    SSLOptions +StrictRequire
    SSLCertificateFile /etc/apache2/ssl/tournois.crt
    SSLCertificateKeyFile /etc/apache2/ssl/tournois.key
    SSLCertificateChainFile /etc/apache2/ssl/tournois.ac

    DocumentRoot /var/www/html/
    Alias /favicon.ico /opt/tournois/static/images/favicon.ico

    Alias /static/ /opt/tournois/static/
    <Directory /opt/tournois/static>
        Require all granted
    </Directory>

    Alias /media/ /opt/tournois/media/
    <Directory /opt/tournois/media>
        Require all granted
    </Directory>

    WSGIDaemonProcess tournois python-home=/opt/tournois/.venv python-path=/opt/tournois
    WSGIProcessGroup tournois
    WSGIScriptAlias / /opt/pytournois/conf/wsgi.py process-group=tournois

    <Directory /opt/tournois/conf>
        <Files wsgi.py>
            Require all granted
            </Files>
    </Directory>
</VirtualHost>
a2dissite 000-default
a2ensite tournois
a2enmod ssl
systemctl restart apache2