在RHEL4上搭建Python/Lighttpd/FastCGI环境

在一台赤裸裸的RHEL4上部署web.py程序,一切从几乎是从零开始。以下操作均以root用户操作。

1. 安装MySQL数据库

下载安装MySQL
wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.41-linux-i686-glibc23.tar.gz/from/http://mirror.services.wisc.edu/mysql/
解压,按照INSTALL文件说明进行安装,不多赘述

2. 安装Python环境

下载Python源码

wget http://www.python.org/ftp/python/2.6.4/Python-2.6.4.tar.bz2
解压,编译安装,不需要特殊操作。

下载Easy_install

wget http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c11-py2.6.egg
安装
sh setuptools-0.6c11-py2.6.egg

安装相关Packages

easy_install DBUtils
easy_install flup
easy_install web.py

安装mysql-python

mysql-python包不能用easy_install安装,手动下载
wget http://downloads.sourceforge.net/project/mysql-python/mysql-python-test/1.2.3b1/MySQL-python-1.2.3b1.tar.gz?use_mirror=softlayer
加压,编辑site.cfg
指定mysql_config的路径,注意是新安装的mysql路径
mysql_config=/usr/local/mysql/bin/mysql_config
编译、安装
python setup.py build
python setup.py install

声明libmysqlclient路径
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mysql/lib

3. 安装服务器环境

下载安装fastcgi头文件

wget http://www.fastcgi.com/dist/fcgi.tar.gz
解压,默认编译安装

下载安装PCRE

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.00.tar.bz2
解压,默认编译安装

下载lighttpd

wget http://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.25.tar.bz2
configure时指定–prefix=/usr/local/lighttpd
编译,安装

4. 配置

lighttpd fastcgi运行web.py程序请参考
http://www.classicning.com/blog/2009/11/lighttpd%e9%80%9a%e8%bf%87fastcgi%e8%bf%90%e8%a1%8cweb-py%e7%a8%8b%e5%ba%8f/

非常重要的几点注意:

  • 通过fastcgi运行的python脚本必须具有可执行权限, chmod u+x web/main.py
  • 重启fastcgi程序需要删除/tmp/fastcgi.socket*

任何Python程序出错、权限错误都会导致lighttpd这样的报错:
2009-11-27 18:12:02: (mod_fastcgi.c.1108) child exited with status 13 /home/admin/web/main.py
2009-11-27 18:12:02: (mod_fastcgi.c.1111) If you’re trying to run your app as a FastCGI backend, make sure you’re using the FastCGI-enabled version.
If this is PHP on Gentoo, add ‘fastcgi’ to the USE flags.
2009-11-27 18:12:02: (mod_fastcgi.c.1399) [ERROR]: spawning fcgi failed.
2009-11-27 18:12:02: (server.c.931) Configuration of plugins failed. Going down.

报错会提示fastcgi未正确安装,而实际上仅仅是程序错误或权限问题而已。

This entry was written by Sunng , posted on Friday November 27 2009at 06:11 pm , filed under 手艺 and tagged , , , . Bookmark the permalink . Post a comment below or leave a trackback: Trackback URL.

7 Responses to “在RHEL4上搭建Python/Lighttpd/FastCGI环境”

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word