Configuring Apache for Python

Paul Boddie paulb at infercor.no
Tue Nov 7 08:06:55 EST 2000


Thomas Weholt wrote:
> 
> You could look at mod_snake or mod_python. They speed up execution of python
> scripts among other things. A better way to get Python into Apache than just
> configuring Apache to use Pythonscripts as old-fashioned cgi.
> 
> <kevinh25 at my-deja.com> wrote in message news:8u88t8$qeg$1 at nnrp1.deja.com...
> > I know this is simple and easy, but I cannot figure out how to
> > configure Apache to run Python scripts.
> >
> > I've edited httpd.conf every which way I know how to no avail.

I think it would be better to make his life easier rather than harder, though,
in that setting up a plug-in might be even more of an ordeal. ;-)

For me, running a fairly standard Red Hat 6.1 distribution, I get my Python
scripts working using the ScriptAlias directive in the srm.conf file, such as
the default one (which I don't use any more):

  ScriptAlias /cgi-bin/ /home/httpd/cgi-bin/

This makes anything in the /home/httpd/cgi-bin/ directory appear on your "Web
site" under /cgi-bin/, and I think you may need to make sure that the scripts in
that directory are executable by the user who runs Apache. Usually, making the
scripts readable and executable by everyone will do the trick, although some may
disapprove of this for security reasons.

In my script files I have the standard first line:

  #!/usr/bin/env python

This assumes that your Python interpreter can be found in the environment of the
user who runs Apache. If you find that this doesn't work, you could either refer
to the exact location of your Python interpreter in your script file, or you
might be able to use a directive in Apache - I think it is called Env or
Environment.

I don't see anything else in my httpd.conf or srm.conf files which will
explicitly make Python scripts work. I don't use the directive which makes .cgi
files work as CGI scripts - it's commented out in my srm.conf file.

  #AddHandler cgi-script .cgi

So, there's no magical benefit to adding such a suffix to any of my script
files. Moreover, there isn't anything in my /etc/mime.types file which tells
Apache about Python, so that can't influence my good fortune either. ;-)

I hope this helps!

Regards,

Paul



More information about the Python-list mailing list