略过以下两步工作:
1.安装python2.7
2.写好web.py程序
3.安装apache2.2
windows版本 下载地址:http://www.apachehaus.com/cgi-bin/download.plx
32位的httpd-2.2.29-ssl-x86.zip
64位的httpd-2.2.29-ssl-x64.zip
linux版本很容易找到,官网
下好apache的压缩包后,解压.然后用cmd命令进入到apache的目录的/bin目录,
然后输入httpd.exe -k install
然后启动apache服务httpd.exe -k start
打开浏览器,输入localhost,如果看到it works!则安装成功
4.下在mod_wsgi模块 地址:http://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi
下载相应版本即可
笔者下的是这个版本 mod_wsgi‑3.5.ap22.win‑amd64‑py2.7.zip
下好后解压得到mod_wsgi.so文件
5.配置apache服务器
笔者配置的是方法是虚拟主机(配置一台主机也是类似)
1.将上面解压得到的mod_wsgi.so文件放入apache的modules\文件夹下
2.打开\conf\httpd.conf,在loadModule相应地方加入以下配置,载入mod_wsgi.so模块
LoadModule wsgi_module modules/mod_wsgi.so
3.继续在本文件中找到Include conf/extra/httpd-vhosts.conf,将前面的#号删去,如下
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
4.打开 conf/extra/httpd-vhosts.conf文件 加入以下配置:
listen 8080
<VirtualHost *:8080>
DocumentRoot "F:/httpd-2.2-x64/htdocs/webapp/"
WSGIScriptAlias / F:/httpd-2.2-x64/htdocs/webapp/webapp_v2_2.py/
Alias /static/ F:/httpd-2.2-x64/htdocs/webapp/static/
Alias /templates/ F:/httpd-2.2-x64/htdocs/webapp/templates/
AddType text/html .py
ServerName localhost
ErrorLog "F:/httpd-2.2-x64/htdocs/webapp/webapp_error.log"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
按照以上配置,将相应的地方改掉,如DocumentRoot ,WSGIScriptAlias等,改成自己的文件目录
5.将自己的写的xxx.py文件(笔者的是webapp_v2_2.py)开头加上以下代码:
import os,sys
abspath = os.path.dirname(__file__)
sys.path.append(abspath)
os.chdir(abspath)
6.重启apache服务httpd.exe -k restart
卸载命令httpd.exe -k uninstall
7.在浏览器上打开localhost:8080,即可看到相应的网页
8.如果现实找不到网页,查看日志文件发现
mod_wsgi (pid=21452): Target WSGI script 'D:/Apache22/htdocs/webapp/webapp.py' does not contain WSGI application 'application'.
需将py文件中的app=web.application(urls,globals())改为
app=web.application(urls,globals())
application = app.wsgifunc() #这一句不加的话会报这个错误:mod_wsgi (pid=21452): Exception occurred processing WSGI script 'D:/Apache22/htdocs/webapp/webapp.py'.
9.如果没有加载css,js文件,可能是<link href="/static/css/main.css" rel="Stylesheet" type="text/css"/>中的static前面没加"/".
10.py文件中的一下代码,可有可无了.
if __name__ == '__main__':
application.run()
到此,部署完毕,如有不懂,可留言.