Ampps is
a WAMP, MAMP and LAMP stack of Apache, MySQL, MongoDB, PHP, Perl &
Python. Having said that you need to do couple of following steps to run
python scripts, but first make take a backup of the configuration file before you
make any changes.
1. Open your Ampps:
Open httpd.conf ( Apache > configuration )
a. Include the AddHandler with .py files to the .conf file so that apache will know that .py belongs to that group of file types that needs to be processed by special ‘handler’ Such as "AddHandler cgi-script .cgi .pl becomes AddHandler cgi-script .cgi .pl .py"
1. Open your Ampps:
Open httpd.conf ( Apache > configuration )
a. Include the AddHandler with .py files to the .conf file so that apache will know that .py belongs to that group of file types that needs to be processed by special ‘handler’ Such as "AddHandler cgi-script .cgi .pl becomes AddHandler cgi-script .cgi .pl .py"
b. Add ExecCGI to the “Options Indexes” line in the .conf. I added the
line inside block. ExecCGI (Execution of
CGI) is necessary for the apache server to assign .py file to its
handler. In our case, the python interpreter.
- eg. Options Indexes FollowSymLinks becomes Options Indexes FollowSymLinks ExecCGI
2. After steps 1-3, save the httpd.conf file, stop the apache server and restart again:
If the apache server restarts without a problem process you have
successfully setup ampps to run python, otherwise restore the conf file
from backup. In ampps there is an option to restore default
configuration.There are couple of things to consider before you run your first python script on apache.Add a shebang line
to the top of the python file to direct to the Python interpreter. The
path should be a direct link to the python executable. For example on
windows, it might be #!C:\Users\Laxman\Anaconda2\python.exe After shebang line, make sure the main python script has
print(“Content-type: text/html\n”). This is very important for a CGI
script. The test python file would be similar as below #!C:\Users\Laxman\Anaconda2\python.exe
print(“Content-type: text/html\n”)
print(‘Hi there!’
wsgi_module must be installed for apache to run python script via execCGI. On ampps this is installed and added to conf file by default.
No comments:
Post a Comment