Why does Apache with mod_wsgi force a download of .py files instead of executing them?
I'm trying to run Django, but the first issue I have is .py files not executing.
I'm following the docs here https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/modwsgi/
- I'm running Ubuntu 20.04.3 LTS
- libapache2-mod-wsgi-py3 installed and enabled
apachectl configtest
Syntax OK
- All files chowned to
www-data:www-data
- .py files are
chmod +x
/var/log/apache2/access.log
is empty
/var/log/apache2/error.log
contains:
Apache/2.4.41 (Ubuntu) mod_fcgid/2.3.9 OpenSSL/1.1.1k mod_wsgi/4.6.8
Python/3.8 configured -- resuming normal operations
The .htaccess file at root has
RewriteEngine on
ServerSignature Off
Directory of /var/www/html/example.com/public_html is this:
This is what I see; clicking on a .py file forces it to download.
/etc/apache2/sites-available/default-ssl.conf:
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
Alias /static /var/www/html/example.com/public_html/contact/static
Alias /media /var/www/html/example.com/public_html/contact/media
<Directory /var/www/html/example.com/public_html/contact/static>
Require all granted
</Directory>
<Directory /var/www/html/example.com/public_html/contact/media>
Require all granted
</Directory>
WSGIScriptAlias / /var/www/html/example.com/public_html/contact/contact/wsgi.py
WSGIDaemonProcess example.com python-home=/var/www/html/example.com/public_html/contact
WSGIProcessGroup example.com
WSGISocketPrefix run/wsgi
<Directory /var/www/html/example.com/public_html/contact/contact>
<Files wsgi.py>
Require all grantd
</Files>
</Directory>
<Directory /var/www/html/example.com/public_html>
AllowOverride None
Order allow,deny
Allow from all
Options +ExecCGI
AddHandler cgi-script .py
</Directory>
</VirtualHost>
</IfModule>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
/etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# Allow .htaccess files
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
Alias /static /var/www/html/example.com/public_html/contact/static
Alias /media /var/www/html/example.com/public_html/contact/media
<Directory /var/www/html/example.com/public_html/contact/static>
Require all granted
</Directory>
<Directory /var/www/html/example.com/public_html/contact/media>
Require all granted
</Directory>
WSGIScriptAlias / /var/www/html/example.com/public_html/contact/contact/wsgi.py
WSGIDaemonProcess example.com python-home=/var/www/html/example.com/public_html/contact
WSGIProcessGroup example.com
WSGISocketPrefix run/wsgi
<Directory /var/www/html/example.com/public_html/contact/contact>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
<Directory /var/www/html/example.com/public_html>
AllowOverride None
Order allow,deny
Allow from all
Options +ExecCGI
AddHandler cgi-script .py
</Directory>
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet