Python2.6+WSGI+web.py 构建WEB环境(CentOS5.4)

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  


      Server Admin [email protected]
     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

     Order deny,allow
            Allow from all



# 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.

你可能感兴趣的:(Linux,Python)