使用python實現(xiàn)CGI環(huán)境搭建過程解析
本文web服務器使用的為apache。
1. 安裝apache
yum install -y httpd
2. 配置apache
修改apache配置文件/etc/httpd/conf/httpd.conf將下面一行的注釋去掉,如果沒有則添加:
LoadModule cgid_module modules/mod_cgid.so
cgi腳本文件的默認路徑為/var/www/cgi-bin/
修改如下幾處內(nèi)容:
<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 .py
3.重啟apache
第一、啟動、終止、重啟
systemctl start httpd.service #啟動
systemctl stop httpd.service #停止
systemctl restart httpd.service #重啟
第二、設(shè)置開機啟動/關(guān)閉
systemctl enable httpd.service #開機啟動
systemctl disable httpd.service #開機不啟動
4.檢查httpd狀態(tài)
systemctl status httpd.service
● 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.
5編寫代碼
#!/usr/bin/python #coding=utf-8 print "Content-type:text/html" print #空行,告訴服務器結(jié)束頭部 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>'
6前臺測試
OK 可以。
但是有一個問題,這是引用的python2
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
詳解python statistics模塊及函數(shù)用法
本節(jié)介紹 Python 中的另一個常用模塊 —— statistics模塊,該模塊提供了用于計算數(shù)字數(shù)據(jù)的數(shù)理統(tǒng)計量的函數(shù)。這篇文章重點給大家介紹python statistics 模塊的一些用法,感興趣的朋友跟隨小編一起看看吧2019-10-10Python使用socket實現(xiàn)組播與發(fā)送二進制數(shù)據(jù)
在工作中經(jīng)常會用到socket傳輸數(shù)據(jù),例如客戶端給服務器發(fā)送數(shù)據(jù)(雙方約定了數(shù)據(jù)格式),本文主要介紹了Python使用socket實現(xiàn)組播與發(fā)送二進制數(shù)據(jù),感興趣的可以了解一下2021-06-06PyCharm專業(yè)最新版2019.1安裝步驟(含激活碼)
這篇文章主要介紹了PyCharm專業(yè)最新版2019.1安裝步驟(含激活碼),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-10-10Python使用Srapy框架爬蟲模擬登陸并抓取知乎內(nèi)容
這里我們來看如何通過Python使用Srapy框架爬蟲模擬登陸并抓取知乎內(nèi)容的實例,要實現(xiàn)持續(xù)的爬取需要利用到cookie的保存,我們首先還是來回顧一下cookie的相關(guān)知識點:2016-07-07pandas實現(xiàn)數(shù)據(jù)可視化的示例代碼
本文主要介紹了pandas實現(xiàn)數(shù)據(jù)可視化的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-05-05