alienhelpdesk.com
projects
Project London
The latest movie directed by Ian Hubert! And I get to help!
usefull sites
blenderartists.org
Home of the blender artist community

python on xampp

I spent most of today (Dec 14 2009) messing around trying to get xampp to interpret python scripts. Usually xampp only works with php, at least on my windows system (windows 32 bit vista). But since I'm developing something for a python server I needed to get it to work.

I read a lot, found a heap of documentation about mod_python (mod_python.so), and only after half a day found out that that's really not a very nice solution. And I already had python 2.5 installed as well. mod_python seems nice, and has a lot of links to it on google, but it's overkill/weird and rarely needed.

So, if you're like me, and have python & xampp installed on your system (and your pythonpath set in the environment variables), and need .py files to work... just do this.

Configuring the server

In the httpd.conf file for your apache installation (part of xampp) add the following all the way at the bottom. In my case the httpd.conf can be found here: C:\xampp\apache\conf

  1. #
  2. # For Python
  3. #
  4. AddHandler cgi-script .py
  5. ScriptInterpreterSource Registry-Strict
Display clean text code for copying
#
# For Python
#
AddHandler cgi-script .py
ScriptInterpreterSource Registry-Strict

Configuring the python script

Then in the top of the python script on your server, it already knows it should be python, but it doesn't know yet where the python program is. So as the very first line in your python scripts on the server you have to say where python is installed. In my case that looks like this

  1. #!C:/Python25/python.exe
Display clean python code for copying
#!C:/Python25/python.exe

Enabling index.py

Of course it's nice to have index.py files work just like index.php ones as well. So I added index.py to the following bit in the httpd.conf

  1. #
  2. # DirectoryIndex: sets the file that Apache will serve if a directory
  3. # is requested.
  4. #
  5. <IfModule dir_module>
  6.     DirectoryIndex index.php index.php4 index.php3 index.cgi index.pl index.html index.htm index.shtml index.phtml index.py
  7. </IfModule>
  8.  
Display clean text code for copying
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
DirectoryIndex index.php index.php4 index.php3 index.cgi index.pl index.html index.htm index.shtml index.phtml index.py
</IfModule>

That's it

Now .py files are also interpreted by python on a xampp installed apache server, just like .php. I hope that helps you as much as it dit me, and maybe saves you some time.

Dolf

Russian proverb
Druzhba druzhboy, a sluzhba sluzhboy
Friendship is friendship and service is service
Introducing character animation with Blender
Introducing character animation with Blender
The classic by Tony Mullen
Bounce tumble and splash
Bounce tumble and splash
Another masterpiece by Tony Mullen