I think one commonly known way of adding PHP to an Apache webserver is to configure it like this:
ScriptAlias /php5.3 /usr/local/php5.3/bin
Action application/php5.3 /php5.3/php-cgi
AddType application/php5.3 .php
Now I tried to write a similar configuration for Python:
ScriptAlias /python /usr/bin
Action application/python /python/python
AddType application/python .py
I have a small test script that looks like this:
print "Content-Type: text/html\n\n"
print "Test"
But something seems to be wrong since the apache error log says the following:
Premature end of script headers: python
So my first though was that my python response is not right. But there is the Content-Type and also both linebreaks. Also the output of a similar PHP script called with php-cgi gives exactly the same output.
Also I haven’t found a tutorial that shows how to get python working this way. So maybe it is not possible, but then I’m curious why this is the case? Or am I missing something?
” So maybe it is not possible, but then I’m curious why this is the case?”
Correct. It’s not possible. It was never intended, either.
Reason 1 – Python is not PHP. PHP — as a whole — expects to be a CGI. Python does not.
Reason 2 – Python is not inherently a CGI. It’s an interpreter that has (almost) no environmental expectations.
Reason 3 – Python was never designed to be a CGI. That’s why Python is generally embedded into small wrappers (mod_python, mod_wsgi, mod_fastcgi) which can encapsulate the CGI environment in a form that makes more sense to a running Python program.