本文web服務器使用的爲apache。html
yum install -y httpdpython
修改apache配置文件/etc/httpd/conf/httpd.conf將下面一行的註釋去掉,若是沒有則添加:
LoadModule cgid_module modules/mod_cgid.soweb
cgi腳本文件的默認路徑爲/var/www/cgi-bin/
修改以下幾處內容:
<Directory />
AllowOverride none
Require all denied
</Directory>
爲:
<Directory "/var/www/cgi-bin">
AllowOverride None
Options +ExecCGI
Order allow,deny
Allow from all
</Directory>
去掉註釋並添加.py
AddHandler cgi-script .cgi .pyapache
systemctl start httpd.service #啓動
systemctl stop httpd.service #中止
systemctl restart httpd.service #重啓服務器
systemctl enable httpd.service #開機啓動
systemctl disable httpd.service #開機不啓動dom
systemctl status httpd.serviceide
● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since 四 2018-12-27 10:05:27 CST; 6min ago Docs: man:httpd(8) man:apachectl(8) Main PID: 4943 (httpd) Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec" CGroup: /system.slice/httpd.service ├─4943 /usr/sbin/httpd -DFOREGROUND ├─4946 /usr/libexec/nss_pcache 131074 off ├─4947 /usr/sbin/httpd -DFOREGROUND ├─4948 /usr/sbin/httpd -DFOREGROUND ├─4950 /usr/sbin/httpd -DFOREGROUND ├─4951 /usr/sbin/httpd -DFOREGROUND ├─4952 /usr/sbin/httpd -DFOREGROUND └─4955 /usr/sbin/httpd -DFOREGROUND 12月 27 10:05:26 master systemd[1]: Starting The Apache HTTP Server... 12月 27 10:05:26 master httpd[4943]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.1.200. Set the ...is message 12月 27 10:05:27 master systemd[1]: Started The Apache HTTP Server. Hint: Some lines were ellipsized, use -l to show in full.
#!/usr/bin/python #coding=utf-8 print "Content-type:text/html" print #空行,告訴服務器結束頭部 print '<html>' print '<head>' print '<meta charset="utf-8">' print '<title>Hello Word - 個人第一個CGI程序!</title>' print '</head>' print '<body>' print '<h2>嘿! 你最帥了 ~</h2>' print '</body>' print '</html>'
OK 能夠。學習
可是有一個問題,這是引用的python2測試
在使用python3 的時候,老是沒有成功。若是有成功的話,請留言,互相學習。ui