Using Apache2 HTTP With Debian Based Systems (Debian / Ubuntu)

Introduction

Apache is a modular server, and many features are implemented by external modules that the main program loads during its initialization.

The default configuration only enables the most common modules, but enabling new modules is a simple matter of running:

a2enmod module

to disable a module, the command:

a2dismod module

These programs actually only create (or delete) symbolic links in /etc/apache2/mods-enabled/, pointing at the actual files (stored in /etc/apache2/mods-available/).

With its default configuration, the web server listens on port 80 (as configured in /etc/apache2/ports.conf), and serves pages from the /var/www/ directory (as configured in /etc/apache2/sites-enabled/000-default).

Le répertoire /usr/lib/apache2/modules dontient tous les modules Apache.

Note

On constate que le module ‘mod_wsgi.o’ n’apparait pas dans la liste des modules Apache.

service apache2 restart
* Restarting web server apache2
...done.

cd /etc/apache2 ; tree -L 2

6 directories, 182 files
root@f9edede86b83:/etc/apache2# tree -L 1
.
├── apache2.conf
├── conf-available
├── conf-enabled
├── envvars
├── magic
├── mods-available
├── mods-enabled
├── ports.conf
├── sites-available
└── sites-enabled

Dockerfile multi-stage building

 1# log_transaction/docker-django/Dockerfile
 2# Production environment (wsgi, mariadb)
 3#
 4# 2 stages:
 5#
 6# - first stage
 7#       building the Python virtual environment with mariadb
 8#       and **mod_wsgi** support
 9#       we need:
10#          - gcc
11#          - apache2-dev apache2-utils
12#          - default-libmysqlclient-dev
13# - second stage
14#       - copying the Python virtualenv environment under /opt/log_transaction/log_transaction/.venv
15#       - install the ldap libraries
16#       - copying the django project under /opt/log_transaction/log_transaction
17#
18##### Start stage 1 : building the Python virtual environment ##########
19# https://hub.docker.com/_/python
20FROM python:3.7.3-slim-stretch as builder
21
22# gcc because we need regex and mod_wsgi
23# pour la production
24RUN apt-get update \
25    && apt-get install -y gcc apache2-dev default-libmysqlclient-dev
26
27
28# we need the bash shell for the 'source' binary
29SHELL ["/bin/bash", "-c"]
30WORKDIR /opt/docker/
31COPY ./log_transaction/requirements.txt .
32RUN python -m venv .venv && \
33    source .venv/bin/activate && \
34    pip install -U pip wheel && \
35    pip install -r requirements.txt && \
36    pip install mod_wsgi wsgi-basic-auth
37
38#### Start stage 2 #########################################
39#
40#  volumes:
41#     - ./docker-django/log_transaction/:/opt/log_transaction/log_transaction # permet d'accéder au code du host
42FROM python:3.7.3-slim-stretch as deployer
43
44# ajout d'informations à l'image pour pouvoir l'identifier plus facilement
45LABEL maintainer "patrick.vergain@id3.eu"
46LABEL description "log_transaction Production Django 5.0.0 (NOT RELEASED)"
47
48WORKDIR /opt/log_transaction/log_transaction
49# installing the python virtual environment
50# mod_wsgi-py37.cpython-37m-x86_64-linux-gnu.so must be here:/opt/log_transaction/log_transaction/.venv/lib/python3.7/site-packages/mod_wsgi/server/mod_wsgi-py37.cpython-37m-x86_64-linux-gnu.so
51# see COPY ./log_transaction.conf /etc/apache2/sites-available/000-default.conf
52COPY --from=builder /opt/docker/.venv ./.venv
53
54# wee need the http apache2 server and mysql libraries
55RUN apt-get update \
56    && apt-get install -y tree apache2 apache2-utils default-libmysqlclient-dev \
57    && apt-get clean
58
59# =================================================
60COPY ./log_transaction /opt/log_transaction/log_transaction
61
62WORKDIR /opt/log_transaction/log_transaction
63RUN mkdir -p /opt/log_transaction/static
64# hack: creating /opt/log_transaction/logs/log_transaction.log
65RUN mkdir -p /opt/log_transaction/logs && \
66    touch /opt/log_transaction/logs/log_transaction.log && \
67    .venv/bin/python manage_prod.py collectstatic && \
68    rm /opt/log_transaction/logs/log_transaction.log
69
70# A faire pour la livraison finale
71#  .venv/bin/python manage_prod.py migrate && \
72
73
74### http apache2 server installation ###################################
75COPY htpasswd /etc/apache2/.htpasswd
76EXPOSE 80
77COPY ./log_transaction.conf /etc/apache2/sites-available/000-default.conf
78## Launching the HTTP server
79CMD ["apache2ctl", "-D", "FOREGROUND"]
80# Pour le debug : voir l'existence de /opt/log_transaction/log_transaction/.venv/lib/python3.7/site-packages/mod_wsgi/server/mod_wsgi-py37.cpython-37m-x86_64-linux-gnu.so
81# CMD ["sleep", "10000000000"]