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
sudo apt install libapache2-mod-wsgi-py3
sudo a2enmod wsgi
Configurer le VirtualHost 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 :
sudo systemctl restart apache2
Un premier script Python
sudo nano /var/www/html/app.wsgi
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 :
http://your_server_ip/