在CentOS 5 VPS上编译带php-fpm功能的php

Posted by zuzhihui in Linux技术 on 2009/09/05 with No Comments

本文记录了在CentOS 5 VPS上编译打了php-fpm补丁的php 5.2.10的过程。

安装库文件

安装编译php需要的一些库文件

yum install libxml2-devel libmcrypt-devel openssl-devel curl-devel libjpeg-devel  libpng-devel freetype-devel openldap-devel libmhash-devel mysql-devel  libtool-ltdl-devel

如果是64位的系统,然后需要调整一下mysql的库文件,否则在64位系统下老去找32位的mysql库:
cd /usr/lib
mv mysql mysql.i386
ln -sf /usr/lib64/mysql mysql

编译php-fpm

给php打php-fpm补丁:

cd php-5.2.10
patch -p1 < ../php-5.2.10-fpm-0.5.13.diff

开始编译php,注意:如果是64位的系统,建议去掉 –with-ldap-sasl,否则有可能编译不过

./configure --prefix=/opt/php --with-iconv --with-zlib --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 --with-xmlrpc --enable-zip --enable-soap  --without-pear --with-mysql --with-mysqli --enable-sqlite-utf8 --with-pdo-mysql --enable-ftp --with-jpeg-dir --with-freetype-dir --with-png-dir
make

当编译到php-5.2.10/ext/date/lib/parse_date.c的时候,挂了,好像不往下走了,这时候ctrl-c中断编译过程,把当前正在执行的语句复制粘贴到命令行单独执行,发现还是好像死循环一样不结束,再次ctrl-c中断,删除掉这个命令中的-O2参数,继续执行,这样这个命令很快就结束了,然后继续运行:

make
make install
cp php.ini-dist /opt/php/lib/php.ini

然后运行 /opt/php/sbin/php-fpm start 就可以启动php的fastcgi进程了,这些php fastcgi进程应该可以正常工作了。

优化php-fpm

编辑php-fpm的配置文件/opt/php/etc/php-fpm.conf,

  • 去掉display_errors参数的注释,修改参数值为1
  • 去掉sendmail_path参数的注释
  • 去掉user,group参数的注释,并设定值为nobody
  • 修改max_children参数的值为10

安装php加速器eAccelerator

tar jxf eaccelerator-0.9.5.3.tar.bz2
cd eaccelerator-0.9.5.3
yum install -y autoconf
/opt/php/bin/phpize
./configure --enable-eaccelerator --with-php-config=/opt/php/bin/php-config
make
make install
mkdir /opt/php/eaccelerator_cache

然后vim /opt/php/lib/php.ini,在文件末尾加入:

[eaccelerator]
zend_extension="/opt/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/opt/php/eaccelerator_cache"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="3600"
eaccelerator.shm_prune_period="3600"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"

然后重启php-fpm,在phpinfo()页面中应该能看到eaccelerator的信息了。

打包

我们把/opt/php目录打包放到 http://dl.rashost.com/ 下面,供客户下载使用。

最后,安装好之后,记着在/etc/rc.local文件中加入自动启动php-fpm的语句:

/opt/php/sbin/php-fpm start

标签:

Leave a Comment

Back to Top

2007-2017 © 北京瑞豪开源科技有限公司 京ICP备13004995号-2