I am trying to make the apache to run python scripts. I have MOD_WSGI , Apache , Python installed on RHEL6. I even edited httpd.conf file to include these lines.
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews ExecCGI
AddHandler cgi-script .cgi
AddHandler wsgi-script .wsgi
AllowOverride None
Order allow,deny
allow from all
</Directory>
I restarted the apache server also. But when i try to execute the python scripts , its just getting printed as plain text in the browser. Its not at all getting executed. Please somebody help.
See if the module was loaded properly by issuing
apache2ctl -t -D DUMP_MODULES
orapachectl -t -D DUMP_MODULES
. If it wasn't, edit yourhttpd.conf
or an included file to include the following (replacelib
withlib64
if needed):LoadModule wsgi_module /usr/lib/httpd/modules/mod_wsgi.so
Do note that you can't execute any python script with WSGI - it has to support an interface with the WSGI handler, if I remember correctly. If you want to execute any python script perhaps you should use plain old CGI, which is slow (don't use it in production if you have more users than yourself) but easy. If your scripts are in
cgi-bin
and they have the right shebang at the top they should pretty much just work already.If you want to use mod_python to have Apache execute regular python scripts first make sure you're loading the module:
And then add this to your configuration, for example inside a Directory block, removing your other changes first:
Both mod_python and mod_wsgi require special code to work with those respective handlers. If your goal is to simply execute plain python scripts, use cgi. In Redhat, the default location is
/var/www/cgi-bin/
, and is already mapped to the path/cgi-bin/
in apache.