Tuesday, October 6, 2015

Configure Apache to run Python Scripts in Windows

This is a simple writeup to fill a gap in various "HOWTO"'s that I read when trying to setup my Apache web server to run python scripts as CGI and it will apply to any cgi scripts (perl, c, c++). 

[1] Install python for Windows: 

 https://www.python.org/downloads/ 

[2] Install Apache: 

 http://httpd.apache.org/download.cgi 

 (or) 

[2] Install XAMP or WAMP: 

 [2.1] XAMP: 

  https://www.apachefriends.org/download.html 

 (or) 

 [2.1] WAMP:  

  http://www.wampserver.com/en/ 


[3] Configure httpd.conf: 

 httpd.conf can be located %apache_install_dir%\conf\httpd.conf 

 [3.1] Add ExecCGI to "options". The line should now look similar to the following (NOTE: there may be more options listed): 

Options Indexes FollowSymLinks ExecCGI 

 [3.2] Add a .py to AddHandler:

 AddHandler cgi-script .cgi .py 

 [3.3] Add Registry-Strict to ScriptInterpreterSource: 

 ScriptInterpreterSource Registry-Strict 

 [4] Register python interpreter in Windows registry to handle python scripts Create a .reg file and execute it
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.py\Shell\ExecCGI\Command] @="c:\\python27\\python.exe"

Restart apache web server. You are all set now :-)

No comments: