Apache2 : Use Python Scripts2019/01/25 |
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 Perl Scripts to put under the directory. All files under it is processed as CGI, though. |
# the settings below is the one for CGI www:~ # grep -n "^ *ScriptAlias" /etc/apache2/default-server.conf 72: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> systemctl restart apache2 |
[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>" chmod 705 /srv/www/htdocs/cgi-enabled/index.py |
Sponsored Link |
|