Python2.6+WSGI+web.py 构建WEB环境

1.安装基本依懒的包 

yum install gcc gdbm-devel readline-devel ncurses-devel zlib-devel bzip2-devel sqlite-devel db4-devel openssl-devel tk-devel bluez-libs-devel


2.安装python 2.6.4 

wget http://www.python.org/ftp/python/2.6.4/Python-2.6.4.tgz
tar xvfz Python-2.6.4.tgz
cd Python-2.6.4
./configure --prefix=/usr/local/python2.6 --with-threads --enable-shared
make && make install


添加alias
vi ~/.bash_profile
alias python='/usr/local/python2.6/bin/python'
source ~/.bash_profile


建立软链接
ln -s /opt/python2.6/bin/python /usr/bin/python2.6


配置ld相关共享库 文件 :
vi /etc/ld.so.conf.d/python2.6.conf
/usr/local/python2.6/lib/

保存后执行:
ldconfig

3.安装setuptools 
wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
tar zxvf setuptools-0.6c11.tar.gz  
cd setuptools-0.6c11
python setup.py install


4.安装python-mysql (注意先安装上mysql-devel相关的包) 
wget http://internap.dl.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.2.tar.gz
tar xvfz MySQL-python-1.2.2.tar.gz
cd MySQL-python-1.2.2
python setup.py build
python setup.py install


执行python
>>> import MySQLdb  //如果无报错,表明安装成功。
>>>  

5.安装配置mod _wsgi
cd /usr/local/python2.6/lib/python2.6/config
ln -s ../../libpython2.6.so .


wget http://modwsgi.googlecode.com/files/mod_wsgi-3.2.tar.gz
cd mod_wsgi-3.2
./configure --with-apxs=/usr/local/apache2/bin/apxs --with-python=/usr/local/python2.6/bin/python
make && make install


安装成功自动向apache添加mod_wsgi 模块 。
ls -Al /usr/local/apache2/modules/mod_wsgi.so

重启apache后查看看模块是否正常加载:
/usr/local/apache2/bin/httpd -M


6.安装web .py 
wget http://webpy.org/static/web.py-0.33.tar.gz
cd web.py-0.33
python setup.py installl


7.配置apache虚拟主机,测试web.py相关程序. 
# cat py. linux tone.org.conf  

<VirtualHost *:80>
      Server Admin system@linuxtone.org
     DocumentRoot /data/www/wwwroot/webpy-app
     ServerName py.linuxtone.org
     AddDefaultCharset UTF-8     
     ErrorLog /data/logs/py.linuxtone.org- error _log
     WSGIScriptAlias /linuxtone /data/www/wwwroot/webpy-app/linuxtone.py/
     Alias /lt/static /data/www/wwwroot/webpy-app/static/
     AddType text/html .py
<Directory /data/www/wwwroot/webpy-app/>
     Order deny,allow
            Allow from all
</Directory>
</VirtualHost>


# vi /data/www/wwwroot/webpy-app/linuxtone.py

#!/usr/bin/env python
import web
urls = (
     '/.*', 'hello',
     )
class hello:
     def GET(self):
         return "Hello, linuxtone."
application = web.application(urls, globals()).wsgifunc()


浏览器 输入 http://py.linuxtone.org/linuxtone   可以看到如下:
Hello, linuxtone.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值