티스토리 뷰

OpenSUSE 11 Apache2 Use Python Scripts


Use Python Scripts

 

Enable CGI executing and use Python script.



1. Install Python.


www:~ # zypper -n install python



2. By default, CGI is allowed under the "/srv/www/cgi-bin" directory.

It's possible to use Python Scripts to put under the directory. All files under it are processed as CGI, though.


# the settings below is the one for CGI

www:~ # grep -n "^ *ScriptAlias" /etc/apache2/default-server.conf 

60:ScriptAlias /cgi-bin/ "/srv/www/cgi-bin/"




3. If you'd like to allow CGI in other directories, configure like follows.

For example, allow in "/srv/www/htdocs/cgi-enabled".


www:~ # vi /etc/apache2/conf.d/cgi-enabled.conf

# create new

# processes .py as CGI scripts

<Directory "/srv/www/htdocs/cgi-enabled">

    Options +ExecCGI

    AddHandler cgi-script .py

</Directory>

www:~ # /etc/init.d/apache2 restart 




4. Create a CGI test page and access to it from client PC with web browser. It's OK if following page is shown.


www:~ # vi /srv/www/htdocs/cgi-enabled/index.py

 #!/usr/bin/env python


print "Content-type: text/html\n\n"

print "<html>\n<body>"

print "<div style=\"width: 100%; font-size: 40px; font-weight: bold; text-align: center;\">"

print "Python Script Test Page"

print "</div>\n</body>\n</html>"


www:~ # chmod 705 /srv/www/htdocs/cgi-enabled/index.py 



5. Access to 'http://(your server's name or IP address)/cgi-enabled/index.py 



저작자 표시 비영리 변경 금지
신고
댓글