郁闷的外星猫·1992年

A New Beginning.

January 10th, 2011

CentOS+Nginx+PHP(FastCGI)安装小记

Tech, by renqing.

鉴于IIS6跑WordPress,对ReWrite支持不佳,还有一些新应用,需要在Linux平台下运行,这几天就安装了一台CentOS跑PHP的网站。
选择CentOS主要是因为在服务器领域比较流行,之前自己也用过一段时间。另外,本来Ubuntu也是候选操作系统,但是鉴于印象中Ubuntu适合桌面用户而不适合服务器的原因,就没有选用。
CentOS可以从官方网站上面下载得到,如果仅做服务器用,只需要下载前3张光盘。
安装的时候推荐使用命令提示符安装,操作比较便捷。分区没有用它的自动分区,手工分了2个ext3(在这里说一下,CentOS5.5不支持ext4,要是想用ext4的话可以用Ubuntu Server 10.04 LTS)加上一个swap。
操作系统安装不是今天我们主要来讨论的,下面说一下Nginx+PHP部分:
这里介绍一下,Nginx是一个由俄罗斯人开发Web+反向代理服务器,效率在高负载的情况下,比Apache高很多,据说Nginx开发者是一个牛X级的C++开发者。国内外,已经有很多大型的站点开始采用Nginx来构架,足以说明他的优势。
Nginx这里我们采用0.8.54 稳定版,可以从http://nginx.org/download/nginx-0.8.54.tar.gz来获取。
安装编译命令
tar zxvf nginx-0.8.54.tar.gz
cd nginx-0.8.54
./configure –prefix=/usr/local/nginx/ –with-http_ssl_module
make
make install
其中prefix后面为Nginx安装到的目录,此选项可以忽略,忽略后默认安装到/usr/local/nginx目录下
–with-http_ssl_module 是安装ssl模块

Nginx的配置文件默认为/usr/local/nginx/conf/nginx.conf
里面可以对Nginx进行配置。
修改配置后,可以运行 sbin/nginx -t来测试配置文件是否合法
重新运行Nginx可以支持killall nginx && ./nginx命令

之后便是安装PHP,我们需要借用到php-frm来帮助Nginx以FastCGI模式运行PHP

需要下载PHP5 php-frm libiconv这几个包
安装libiconv
tar zxvf libiconv-1.13.tar.gz
cd libiconv-1.13/
./configure –prefix=/usr/local
make
make install

编译安装命令:
./configure –prefix=/usr/local/php –with-config-file-path=/usr/local/php/etc –with-mysql –with-mysqli –with-iconv-dir –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir=/usr –enable-xml –disable-rpath –enable-discard-path –enable-safe-mode –enable-bcmath –enable-shmop –enable-sysvsem –enable-inline-optimization –with-curl –with-curlwrappers –enable-mbregex –enable-fastcgi –enable-fpm –enable-force-cgi-redirect –enable-mbstring –with-mcrypt –with-gd –enable-gd-native-ttf –with-openssl –with-mhash –enable-pcntl –enable-sockets –with-ldap –with-ldap-sasl
make ZEND_EXTRA_LIBS=’-liconv’
make test
make install
cp php.ini-dist /usr/local/php/etc/php.ini
之后修改php.ini中extension_dir为/usr/lib/php/modules/

下面附上一些安装上常见的错误
遇到configure: error: XML configuration could not be found
解决方案yum -y install libxml2 libxml2-devel

遇到configure: error: Please reinstall the libcurl distribution -
easy.h should be in /include/curl/
解决方案yum -y install curl-devel

遇到configure: error: libjpeg.(a|so) not found.
解决方案yum -y install libjpeg-devel

基本还会遇到Configure: error: libpng.(also) not found.
解决方法yum -y install libpng libpng-devel
缺少freetype的话:yum install freetype-devel

遇到configure: error: Cannot find ldap.h
解决方法yum -y install openldap openldap-devel

遇到configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决方法yum -y install libmcrypt libmcrypt-devel

遇到configure: error: Please reinstall libmhash – I cannot find mhash.h
解决方法yum -y install mhash-devel

遇到configure: error: Cannot find MySQL header files under yes.
一般是没有安装MySQL,可以yum -y install mysql-devel

在make test的时候error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory
解决办法如下:
1.在/etc/ld.so.conf中加一行/usr/local/lib,
2.然后运行/sbin/ldconfig,文件解决,没有报错了

[ERROR] fpm_unix_conf_wp(), line 124: please specify user and group other than root, pool ‘default’

vi php-fpm.conf 去掉< ! -- nobody – - >的注释符号

[第一版|本文章以后会不断扩充,具体化。对于文章中没有提及的操作,可以Google查询]

最近新安装了一台服务器,用的如下配置
yum install gcc gcc-c++ gzip libxml2 libxml2-devel zlib zlib-devel
glib2-devel openssl-devel pcre-devel bzip2-devel gzip-devel

./configure –prefix=/usr/local/nginx –with-http_ssl_module –with-http_stub_status_module

Back Top

Responses to “CentOS+Nginx+PHP(FastCGI)安装小记”

  1. 完全看不懂的路过。
    祝贺狗仔拿到Offer。

  2. @Raellen: 谢谢Raellen~

  3. Ubuntu飘过

  4. @bruce55: 我客户端也用Ubuntu = =只不过服务器不用

  5. REQING前辈,你好。
    我是学网站建设的,最近忙于用PHP建设一套Online Judge 系统来完成老师布置的课题。
    然而,始终无法解决的是:不知道如何对用户提交的程序代码进行编译连接并对运算结果校验。对GCC 所知甚少,还不清楚它有多少接口可以使用。
    前辈高明,望不吝赐教,指点一二!

  6. @冯兴杰: 直接g++编译运行就可以

  7. 如果直接用G++编译运行,如何把测试数据输入程序,并且如何获得程序运行结果呢?
    还有程序运行时间以及内存占用等,都一无头绪。

  8. @冯兴杰: 最简单的办法可以用文件输入输出。时间、内存可以用API函数控制

  9. to 冯兴杰:
    你可以去code.google.com/p/orzoj去查看OrzOJ源码,包含全部server, judge和web部分,www.orzoj.org有演示,还未正式运行

  10. …Orz

    Sion Ouro Twist at March 19, 2011 13:30
  11. R猥Q活起来啊 ..!!! ..你的背景音乐呢.. 其实我是来听歌的 …

    hbmhalley at June 9, 2011 16:02
  12. @hbmhalley: WSMAN~~~

    Sion Ouro Twist at June 20, 2011 14:10
  13. 为什么不用Debian?

  14. @samhjn: 个人喜好吧,我Linux服务器一般用CentOS

  15. 给我改下友情链接啊啊

  16. 就用我现在的地址吧。。。。

  17. @Weijian: I have done it

  1. No trackbacks yet.

Leave a Reply

Your email address will not be published. Required fields are marked *

*