ÈçºÎÔÚApacheÏÂÉèÖÃPython(WIN,CGI·½·¨)
¹ØÓÚPython£¬±¾È˲»Ïë¶à˵ÁË£¬Èç¹û²»ÖªµÀʲôÊÇPython£¬¿ÉÒÔ¿´¡¶Ê²Ã´ÊÇPython
£¿¡·Ò»ÎÄ¡£Python¿ÉÒÔ¿ª·¢CGI³ÌÐò£¬ÄÇôÔÚApacheÏÂÓ¦ÈçºÎÅäÖÃÄØ£¿±¾ÎÄÖ»½²ÊöÁËÈçºÎ
ÒÔCGI·½Ê½ÅäÖÃApache£¬Ê¹ÆäÖ§³ÖPython³ÌÐò¡£ÆäËü·½Ê½£¬Èçmod_pythonÔò²»ÔÚÌÖÂÛ·¶Î§
(ÆäʵÊÇûÅä³É¹¦:-)¡£ÎÒËùʹÓõÄϵͳ»·¾³ÎªWindows 2000, Apache 1.3.19£¬Python
2.1°æ¡£
×¼±¸
¡¡¡¡Ê×Ïȼì²éÒÔÏÂÒªÇóÊÇ·ñÒѾ´ïµ½£º
ApacheÒѾ°²×°£¬²¢ÇÒ¿ÉÒÔÕý³£Ê¹ÓÃ
PythonÒѾ°²×°£¬²¢ÇÒ¿ÉÒÔÕý³£Ê¹ÓÃ(ÔÚÎҵĻ·¾³Ï£¬Python°²×°Ä¿Â¼Îªc:\servers\py
thon)
¡¡¡¡ºÃ£¬Èç¹ûÒ»ÇÐÕý³££¬ÏÂÃæ¾Í¿ªÊ¼ÁË¡£
ÅäÖÃ
¡¡¡¡ÐÞ¸ÄDocumentRoot
´ò¿ªApache°²×°Ä¿Â¼ÏµÄconf×ÓĿ¼µÄhttpd.confÎļþ¡£¿ÉÒÔÐÞ¸ÄDocumentRootΪ"C:/
Inetpub/wwwroot"¡£µ±È»Äã¿ÉÒÔ°´ÐèÒª¸Ä³ÉÆäËüÖµ¡£
¡¡¡¡ÔÊÐíÈÎÒâĿ¼ִÐÐCGI
¡¡¡¡Õâ¸öÉèÖÃÊÇÔÊÐí±»ÉèĿ¼¼°Æä×ÓĿ¼ÏµÄCGI³ÌÐò¿ÉÒÔCGI·½Ê½ÔËÐС£ÔÚApacheÖУ¬
¾¡¹ÜÄã¿ÉÄÜÒѾÉèÖÃÁËCGIÎļþºó׺£¬µ«ÊÇÈç¹ûδÉèÖÃÔÊÐíCGI³ÌÐòÔËÐÐÑ¡ÏÔòÎÞ·¨ÔË
ÐÐCGI³ÌÐò¡£
¡¡¡¡ÉèÖÃC:/Inetpub/wwwrootĿ¼ÊôÐÔ£º
<Directory "C:/Inetpub/wwwroot">
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride None
Order allow,deny
Allow from all
</Directory>
¡¡¡¡ÆäʵÎÒ²¢Î´ÖØÐÂÉèÖÃеÄĿ¼ÊôÐÔ£¬¶øÊǽ«DocumentRootµÄĿ¼ÊôÐÔ(ÔÀ´Ö¸ÏòApa
che°²×°Ä¿Â¼ÏµÄhtdocsĿ¼£¬ÎҸijÉΪC:/Inetpub/wwwrootÁË)Ôö¼ÓÁËExecCGIÒ»Ïî¡£
¡¡¡¡Ö»ÔÊÐíÌرðĿ¼ִÐÐCGI
¡¡¡¡Ò²¿ÉÒÔÖ»ÔÊÐíÌرðĿ¼Ï¿ÉÒÔÖ´ÐÐCGI³ÌÐò¡£ÓëÉÏÒ»²½¿ÉÒÔͬʱִÐУ¬Ò²¿ÉÁ½ÖÖÈÎÑ¡
ÆäÒ»¡£Ö»ÒªÉèÖãº
ScriptAlias /cgi-bin/ "C:/Inetpub/wwwroot"
¡¡¡¡¼´¿É¡£
¡¡¡¡Ôö¼ÓCGIÎļþÃûºó׺
¡¡¡¡ÐÞ¸Ä AddHandler cgi-script Ò»¾äΪ AddHandler cgi-script .cgi .py¡£¼´ÈÃAp
acheÖªµÀ.pyµÄÎļþΪCGI³ÌÐò
¡¡¡¡ºÃÁË£¬µ½´ËApache¾ÍÅäÖúÃÁË£¬ÏÈÆô¶¯Apache£¬È»ºó½øÐвâÊÔ¡£
²âÊÔ
¡¡¡¡Python±¾Éí²»ÏóPHP£¬²»ÊÇÒ»ÖÖǶÈëʽ½Å±¾(ÕâÖֽű¾±È½ÏÊʺÏ×öWebºó¶Ë³ÌÐò)£¬Ëù
ÒÔËùÓÐÊä³öÒª×ÔÒÑ×ö¡£
1 #!c:/servers/python/python.exe
2 print "Content-type: text/html"
3 print
4 print "<h1>hello,world!</h1>"
¡¡¡¡µÚ1ÐÐÊÇÈýű¾ÒÔCGI·½Ê½ÔËÐбØÐèµÄ(ÕâÀïÊÇÎҵĻ·¾³£¬¼ÇµÃÂð£¿ÎÒÇ°Ãæ˵ÁËPytho
Ïà¹ØÎĵµ£º
С°×ÊǸö΢ÈíÃÔ£¬ËûµÄżÏñÊDZȶû´óÊ壬ÔÒòµ±È»ÊǵØÇòÈ˶¼ÖªµÀÀ²¡£´ó¶þµÄʱºò£¬ËûµÄ“ê¡Ñ§¼Æ»®”ÔøÒ»¶ÈµÃ³Ñ£¬ÔÒòÊÇËû¹Ò¿ÆÌ«¶à¡£µ±È»£¬´óÈýÐÂѧÆÚ¿ªÊ¼µÄʱºò£¬Ãæ¶Ô¹«ÖÚÖÊÒÉ£¬Ð¡°×Õ¾ÔÚÒÎ×ÓÉÏ£¬Ïñ¼«ÁË¡¶´óÄÚÃÜ̽ÁãÁã·¢¡·ÀïµÄÎ÷ÃÅ´µÑ©£º“ÊÀ½çÊ׸»±È²»Ò»¶¨Óжà³öÉ«£¬ÕâÖ»²»¹ýÊÇÄãÃÇÕâЩÐǶ·ÊÐÃñÒ»ÏáÇéÔ¸µÄÏë·¨° ......
ubuntu10.05³öÀ´ÁËÕâÁ½ÌìÒ»Ö±ÔÚÕÛÌÚ£¬ÏÔʾwubiÎÞ·´Ó¦£¬È»ºó´ÓÓ²ÅÌ°²×°ÆÚ¼äÓÖÓöµ½grub´íÎóµÈÎÊÌâ¡£°²×°³É¹¦ºó¸ã¸öÖÐÎÄÊäÈë·¨¾ÍÀÏ°ëÌ죬×îºóʹÓÃPinyinÕâ¸ö»¹ËãºÃÓã¬ÓеãÏëËѹ·¾ÍÊÇûʲô´Ê¿â¡£×î¶ñÐĵĻ¹ÊÇvimµÄÎÊÌ⣬ÓÃapt-get install vim×°µÄvim²»Ö§³Öϵͳ¼ôÇа壬ֻºÃ´ÓÔ´´úÂë±àÒ룬¿ÉÊÇÎÒ³¢ÊÔÁ˺ܶà´Î×ÜÊÇûÓÐpythonÖ§ ......
ÕýÔò±í´ïʽÊǸöħ¹í£¬Ò²ÊǸöÌìʹ¡£ÔÚÄãûÓÐÕÆÎÕËü֮ǰ£¬ËüÊÇħ¹í£¬ÔÚÄãÕÆÎÕËüºó£¬ËüÊÇÌìʹ£¬µ«ÊÇ£¬Ê±
²»Ê±»¹ÊÇÒªÌø³öÀ´£¬¸øÄãµ÷Ƥµ·µ°Ò»·¬¡£
Ò»¸öÕýÔò±í´ïʽ¾ÍÊÇÓÉÆÕͨ×Ö·ûÒÔ¼°ÌØÊâ×Ö·û×é³ÉµÄÎÄ×Öģʽ£¬¸ÃģʽÃèÊöÔÚ²éÕÒÎÄ×ÖÖ÷Ìåʱ´ý
Æ¥ÅäµÄÒ»¸ö»ò¶à¸ö×Ö·û´®¡£ÕýÔò±í´ïʽ×÷Ϊһ¸öÄ£°å£¬½«Ä³¸ö×Ö·ûģʽÓëËùËÑË÷µÄ ......
ºÜ³¤µÄÒ»¶Î´úÂ룬µ«ºÜÇå³þ¡£¹þ¹þ¡£
import os
from time import strftime
stamp=strftime("%Y-%m-%d %H:%M:%S")
logfile = 'F:\\test\\m-php-framework\\tmp\logs\\error_report.log'
path = 'F:\\test\\'
files = os.listdir(path)
bytes = 0
numfiles = 0
for f in files:
if f.startswith('t'): ......