Why?


Search This Blog

Saturday, June 2, 2018

CentOS 7 Enable CGI executing for use of Python script

CentOS 7 Enable CGI executing for use of Python script

See the post "CentOS 7 install and setup for python3.6" at

http://glenewhittenberg.blogspot.com/2018/06/centos7-install-and-setup-for-python36_1.html

before continuing

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

[root@python /]# grep "^ *ScriptAlias" /etc/httpd/conf/httpd.conf
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
   
Create test page in /var/www/cgi-bin/ directory

[root@python /]# vi /var/www/cgi-bin/test.py

#!/usr/bin/python3.6
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>")
Now chmod so the file is executable to all (-rwx---r-x)

[root@python /]# chmod 705 /var/www/cgi-bin/test.py

Now run in web browser

http://your-ip-here/cgi-bin/test.py

No comments:

Post a Comment