Python+wsgi环境配置及其安装

时间:2022-10-27 17:17:43
1.安装基本依懒的包
  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.安装python2.6.4

  1. wget http://www.python.org/ftp/python/2.6.4/Python-2.6.4.tgz
  2. tar xvfz Python-2.6.4.tgz
  3. cd Python-2.6.4
  4. ./configure --prefix=/usr/local/python2.6 --with-threads --enable-shared
  5. make && make install
复制代码


添加alias
  1. vi ~/.bash_profile
  2. alias python='/usr/local/python2.6/bin/python'
  3. source ~/.bash_profile
复制代码


建立软链接
  1. ln -s /opt/python2.6/bin/python /usr/bin/python2.6
复制代码


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

保存后执行:
ldconfig

3.安装setuptools
  1. wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
  2. tar zxvf setuptools-0.6c11.tar.gz 
  3. cd setuptools-0.6c11
  4. python setup.py install
复制代码


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


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

5.安装配置mod_wsgi
  1. cd /usr/local/python2.6/lib/python2.6/config
  2. ln -s ../../libpython2.6.so .
复制代码


  1. wget http://modwsgi.googlecode.com/files/mod_wsgi-3.2.tar.gz
  2. cd mod_wsgi-3.2
  3. ./configure --with-apxs=/usr/local/apache2/bin/apxs --with-python=/usr/local/python2.6/bin/python
  4. make && make install
复制代码


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

重启apache后查看看模块是否正常加载:
  1. /usr/local/apache2/bin/httpd -M
复制代码


6.安装web.py
  1. wget http://webpy.org/static/web.py-0.33.tar.gz
  2. cd web.py-0.33
  3. python setup.py installl
复制代码


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

  1. <VirtualHost *:80>
  2.     ServerAdmin system@linuxtone.org
  3.     DocumentRoot /data/www/wwwroot/webpy-app
  4.     ServerName py.linuxtone.org
  5.     AddDefaultCharset UTF-8    
  6.     ErrorLog /data/logs/py.linuxtone.org-error_log
  7.     WSGIScriptAlias /linuxtone /data/www/wwwroot/webpy-app/linuxtone.py/
  8.     Alias /lt/static /data/www/wwwroot/webpy-app/static/
  9.     AddType text/html .py
  10. <Directory /data/www/wwwroot/webpy-app/>
  11.     Order deny,allow
  12.            Allow from all
  13. </Directory>
  14. </VirtualHost>
复制代码


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

  1. #!/usr/bin/env python
  2. import web
  3. urls = (
  4.     '/.*', 'hello',
  5.     )
  6. class hello:
  7.     def GET(self):
  8.         return "Hello, linuxtone."
  9. application = web.application(urls, globals()).wsgifunc()
复制代码