1。安装和下载python和web.py和lighttpd这个就不说了,可以apt-get(我用的ubuntu),也可以下载源自己编译。
2。web.py的官方网站上有code.py,注意格式,python是强缩进的。写好后,运行python code.py,就可以在http://127.0.0.1:8080访问了,如果达到了这步,就成功一小部分了。
付code.py:
#!/usr/bin/env python
import web
urls = (
'/(.*)','index'
)
app = web.application(urls, globals())
class index:
def GET(self, name=None):
if not name:
name = 'world'
return 'Hello, ' + name + '!'
if __name__ == "__main__":
app.run()
3。配置lighttpd。
server.modules = (
"mod_rewrite",
"mod_setenv",
"mod_secdownload",
"mod_access",
"mod_auth",
# "mod_httptls",
"mod_status",
"mod_expire",
"mod_simple_vhost",
"mod_redirect",
# "mod_evhost",
# "mod_localizer",
"mod_fastcgi",
"mod_cgi",
"mod_compress",
"mod_userdir",
"mod_ssi",
"mod_accesslog" )
fastcgi.server = (
#".php" => (( "host" => "127.0.0.1", "port" => 1026, "broken-scriptfilename" => "enable", "allow-x-send-file" => "enable" ) ),
#"/prefix.fcgi" => (( "host" => "127.0.0.1", "port" => 1026, "check-local" => "disable", "broken-scriptfilename" => "enable" ))
"/code" =>(("socket" => "/tmp/fastcgi.socket","bin-path" => "/var/www/pyweb/code.py","max-procs" => 10,"bin-environment" =>("REAL_SCRIPT_NAME" => ""),"check-local" => "disable"))
)
这些是我的配置文件的一部分,其它部分默认就可,当然server-root这些,就自己配置了。fastcgi.server里面已经有了,只需要把"/code"=>这段加上去就行了。注意,socket文件夹,一定要有写的属性,没有的话,可以用:sudo chmod 777 /xxx 来给权限,code.py也一样。
本文精选自:http://www.chen-long.net/?post=44