标签:apache centos python web.py mod_wsgi
1. 安装apache:
yum install -y httpd httpd-devel
修改/etc/httpd/conf/httpd.conf中的servername等配置,使http://*:*/ 能正常访问
2. 安装python:
wget https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz
tar -xzvf Python-2.7.8.tgz
cd Python-2.7.8
./configure --enable-shared=enable
make && make install
3. 修复yum:
yum 发现报错,因为centos6.5的Python默认版本为2.6.*,而yum是基于python的。
解决方案:
cp /usr/bin/python /usr/bin/python_bak
rm -f /usr/bin/python
ln -s /usr/local/bin/python2.7 /usr/bin/python
vi /usr/bin/yum 将/usr/bin/python 改为: /usr/bin/python2.6
4.安装mod_wsgi:
wget https://github.com/GrahamDumpleton/mod_wsgi/archive/3.5.tar.gz
tar -xzvf 3.5.gz
cd mod_wsgi-3.5
./configure --with-apxs=/usr/sbin/apxs --with-python=/usr/local/bin/python2.7 #注意这里apxs、python的路径通过whereis来决定
LD_RUN_PATH=/usr/local/lib make #注意LD_RUN_PATH=/usr/local/lib,用来设置环境变量,获取libpython.so的位置。如果没有,开启apache时,会提示找不到libpython2.7.so.1.0
make install
5. apache中加载wsgi:
vi /etc/httpd/conf/httpd.conf
在一堆的module加载后加入: LoadModule wsgi_module modules/mod_wsgi.so
6. 安装web.py:
http://webpy.org/static/web.py-0.37.tar.gz
python setup.py install
7. 部署基于web.py框架开发的python的web程序:
在httpd.conf中加入:
WSGIScriptAlias /smushit /var/www/smushit/code.py/
Alias /smushit/static /var/www/smushit/static/
AddType text/html .py
<Directory /var/www/smushit/>
Order deny,allow
Allow from all
</Directory>
其中,smushit为web系统的目录。
code.py的代码为:
import web
urls = (‘/.*‘, ‘code‘)
class code:
def GET(self):
return "Hello, world."
application = web.application(urls, globals()).wsgifunc()
测试发现:http://192.168.178.147/smushit/ 访问正常,即说明配置ok。
参考:http://webpy.org/cookbook/mod_wsgi-apache
本文出自 “心如止水,浴火重生” 博客,请务必保留此出处http://itisforyou.blog.51cto.com/9778869/1597024
CentOS6.5环境中配置Python + Web.py + Apache部署环境
标签:apache centos python web.py mod_wsgi
原文地址:http://itisforyou.blog.51cto.com/9778869/1597024