Question
How to run Python scripts using WSGI module?
How to configure domain root directory for WSGI scripts?
Answer
Warning: WSGI module is not compatible with the Python module and Apache will crash if installed together.
-
Connect to the server via SSH
-
Install
mod_wsgi
Apache module:For Red Hat based OS:
# yum install mod_wsgi
For Debian based OS:
# apt-get install libapache2-mod-wsgi
Note: for some versions of Ubuntu the package name is
libapache2-mod-wsgi-py3
For AlmaLinux:
# yum install python3-mod_wsgi
-
Restart Apache service:
For Red Hat based OS:
# systemctl restart httpd
For Debian based OS:
# systemctl restart apache2
-
Log in to Plesk
-
Under Domains > example.com > Apache & nginx Settings > Additional directives for HTTP specify the following:
Note: Duplicate it to the field Additional directives for HTTPS if necessary:
WSGIScriptAlias /python /var/www/vhosts/example.com/httpdocs/python/
-
After that, the file
*.py
will be served on the URL_**http://example.com/python/<file_name>**_
.
Note: path /var/www/vhosts/example.com/httpdocs/python
may vary, depending on where the script is located.