---
title: Module Python
source: https://synapx.fr/blog/module-python/
date: 2026-06-26
category: Modules
site: SynapxLab
---

# Python avec Apache : `mod_wsgi` (à la place de `mod_python`)

Python est souvent privilégié pour des applications nécessitant des capacités de calcul scientifique ou de machine learning. `mod_python` est aujourd'hui obsolète ; sur un Apache moderne, on utilise plutôt **`mod_wsgi`** pour servir une application Python.

## Installer le module

```bash
sudo apt install libapache2-mod-wsgi-py3
sudo a2enmod wsgi
```

## Configurer le VirtualHost Apache

```apache
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    <Directory /var/www/html>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    WSGIDaemonProcess monapp python-home=/var/www/html/venv python-path=/var/www/html
    WSGIProcessGroup monapp
    WSGIScriptAlias / /var/www/html/app.wsgi
</VirtualHost>
```

Recharger Apache :

```bash
sudo systemctl restart apache2
```

## Un premier script Python

```bash
sudo nano /var/www/html/app.wsgi
```

```python
def application(environ, start_response):
    status = '200 OK'
    headers = [('Content-Type', 'text/plain; charset=utf-8')]
    start_response(status, headers)
    return [b'Hello World from Python using mod_wsgi!']
```

Tester dans le navigateur :

```text
http://your_server_ip/
```
