在Debian 5 VPS下编译php-fpm

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

php-fpm和spawn-fcgi一样,是一个php的fastcgi进程管理器。 spawn-fcgi是个独立的程序,而php-fpm是和php集成在一起的。一般的Linux都不带php-fpm,本文介绍在debian 5 VPS下怎样编译php-fpm。

编译环境准备

首先查看debian的apt软件库的配置,确保/etc/apt/sources.list这个文件里面至少有:

deb http://ftp.us.debian.org/debian lenny main
deb http://security.debian.org/ lenny/updates main

然后同步一下:

apt-get update

安装编译所需要的工具:

apt-get install build-essential vim

安装编译所需要的库:

apt-get install libxml2-dev libmcrypt-dev libssl-dev libldap2-dev libmhash-dev libmysqlclient15-dev libcurl4-openssl-dev libpng-dev libjpeg-dev libsasl2-dev

编译

下载php 5.2.10和相应的php-fpm补丁,然后开始编译:

tar zxf php-5.2.10.tar.gz
cd php-5.2.10
cat ../php-5.2.10-fpm-0.5.13.diff | patch -p1
./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 install
cp php.ini-dist /opt/php/lib/php.ini
ln -s /opt/php/sbin/php-fpm /etc/init.d/php-fpm
update-rc.d -f php-fpm defaults

编译后的php安装在/opt/php下面,php的配置文件是/opt/php/lib/php.ini

和其他Linux下不同,在Debian下这时候启动php-fpm会失败,原因是在Debian下php-fpm的配置文件中必须指定运行时的用户才行。

优化php-fpm

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

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

安装php加速器eAccelerator

tar jxf eaccelerator-0.9.5.3.tar.bz2
cd eaccelerator-0.9.5.3
apt-get install -y autoconf
/opt/php/bin/phpize
./configure --enable-eaccelerator --with-php-config=/opt/php/bin/php-config
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目录打包为php-fpm-5.2.10-amd64.tar.gz,放到http://dl.rashost.com/下面,供客户下载使用。

标签:

Leave a Comment

Back to Top

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