I'm trying to get Python working with Apache, however I'm failing to have success with either CGI or mod_python.
Does anyone know a good tutorial or something?
Thanks.
Apache2python
I'm trying to get Python working with Apache, however I'm failing to have success with either CGI or mod_python.
Does anyone know a good tutorial or something?
Thanks.
Best Answer
mod_python
is basically non-maintained - you should look intomod_wsgi
. Install the packagelibapache2-mod-wsgi
, then issuesudo a2enmod wsgi
to enable it.Just as a quick example to get it running, stuff something like this in your
/etc/apache2/sites-enabled/default
:And in the file
/path/to/python/file.py
:After re-starting Apache2, any request to
/test
will turn into a call ofapplication()
in your python file.For further reading, look into WSGI (WebServer Gateway Interface), the way Python integrates with web-servers.
Bonus / Update:
Python (unsurprisingly) has a small WSGI server in the standard library for testing. If you add this in the bottom of your file, you can run it as any old executable for testing purposes, and then let Apache take over for production: