LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 961|回复: 0

lenny上php-fpm的安装小计

[复制链接]
发表于 2009-3-7 16:07:42 | 显示全部楼层 |阅读模式
因最近把lighttpd切到nginx,随之而来的便是fastcgi的问题,虽然使用spawn-fcgi可以使用,但多数的意见还是php-fpm ( http://php-fpm.anight.org/ ) 更实用些,但这就涉及了php的重新打包及冲突问题,为了简便起见,选用了以archlinux的aur上php-fpm为基础来打包的路线,至于debian上如何来安装archlinux的pacman就是另一个话题了,这里就不提了

1、下载php源码
这里选择了直接使用源里的php5,因为其久经考验,补丁众多,稳定度等都比较适合
  1. apt-get source php5-cgi
  2. apt-get build-dep php5-cgi
复制代码
完了之后,因缺省装安装的是apache2-prefork-dev,而后继打包中需要apxs只在apache2-threaded-dev中,所以要
  1. apt-get install apache2-threaded-dev
  2. cd /usr/bin
  3. ln -s apxs2 apxs
复制代码

2、下载php-fpm
  1. wget http://php-fpm.anight.org/downloads/archive/php-5.2/php-5.2.6-fpm-0.5.9.diff.gz
复制代码

3、为后继的pacman准备php-5.2.6.tar.bz2
  1. cd php5-5.2.6
  2. for i in debian/patches/*; do patch -p1 -i $i;done
  3. for i in debian/gentoo/*;do patch -p1 -i $i;done
  4. zcat patch-to-php-5.2.6-fpm-0.5.9.diff.gz | patch -p1
  5. rm -rf debian
  6. cd ..
  7. mv php5-5.2.6 php-5.2.6
  8. tar cjf php-5.2.6.tar.bz2 php-5.2.6/
复制代码
4、从archlinux的aur上下载php-fpm的pkgbuild和php.ini等(这些基本都要改的,用处不是很大)
  1. mkdir php-fpm
  2. cd php-fpm
  3. yaourt -G php-fpm
复制代码
修改pkgbuild为:
  1. pkgname=php-fpm
  2. _realname=php
  3. pkgver=5.2.6
  4. pkgrel=12
  5. _suhosinver=${pkgver}-0.9.6.3
  6. _fpmversion=0.5.09
  7. pkgdesc='A high-level scripting language with FastCGI Process Manager'
  8. arch=('i686' 'x86_64')
  9. license=('PHP' 'GPL')
  10. #conflicts=('php')
  11. url='http://www.php.net'
  12. backup=('etc/php/php.ini' 'etc/php/php-fpm.conf')
  13. install=php.install
  14.         
  15. source=("http://www.php.net/distributions/${_realname}-${pkgver}.tar.bz2" \
  16.         "php.ini" "php-fpm.conf" "php-fpm" "apache.conf")
  17. build() {
  18.         phpconfig="--prefix=/opt \
  19.         --sysconfdir=/opt/etc/php \
  20.         --with-layout=GNU \
  21.         --with-config-file-path=/opt/etc/php \
  22.         --with-config-file-scan-dir=/opt/etc/php/conf.d \
  23.     --with-fpm-conf=/opt/etc/php/php-fpm.conf \
  24.         --enable-inline-optimization \
  25.         --disable-debug \
  26.         --disable-rpath \
  27.         --disable-static \
  28.         --enable-shared \
  29.     --mandir=/opt/share/man \
  30.         "
  31.         phpextensions="--with-openssl=shared \
  32.         --with-zlib=shared \
  33.         --enable-bcmath=shared \
  34.         --with-bz2=shared \
  35.         --enable-calendar=shared \
  36.         --with-curl=shared \
  37.         --enable-dba=shared \
  38.         --with-db4=shared \
  39.         --with-gdbm=shared \
  40.         --enable-exif=shared \
  41.         --enable-ftp=shared \
  42.         --with-gd=shared \
  43.         --enable-gd-native-ttf \
  44.         --with-jpeg-dir=shared,/usr \
  45.         --with-png-dir=shared,/usr \
  46.         --with-gettext=shared \
  47.         --with-imap=shared \
  48.         --with-imap-ssl=shared \
  49.         --with-ldap=shared \
  50.         --enable-mbstring=shared \
  51.         --with-mcrypt=shared \
  52.         --with-kerberos \
  53.         --with-mysql=shared \
  54.         --with-mysql-sock=/tmp/mysql.sock \
  55.         --with-mysql=shared \
  56.         --with-mysqli=shared \
  57.         --with-ncurses=shared \
  58.         --with-unixODBC=shared,/usr \
  59.         --enable-pdo=shared \
  60.         --with-pdo-mysql=shared \
  61.         --with-pdo-sqlite=shared,/usr \
  62.         --with-pdo-odbc=shared,unixODBC,/usr \
  63.         --with-pdo-pgsql=shared \
  64.         --with-sqlite=shared \
  65.     --enable-sqlite-utf8 \
  66.         --with-pgsql=shared \
  67.         --enable-shmop=shared \
  68.         --with-snmp=shared \
  69.         --enable-soap=shared \
  70.         --enable-sysvmsg=shared \
  71.         --enable-sysvsem=shared \
  72.         --enable-sysvshm=shared \
  73.         --with-tidy=shared \
  74.         --with-xsl=shared \
  75.         --enable-zip=shared \
  76.         --enable-posix=shared \
  77.         --enable-sockets=shared \
  78.         --enable-xml \
  79.         --with-ttf=shared \
  80.         --enable-session=shared \
  81.         --with-regex=php \
  82.         --with-pcre-regex=/usr \
  83.         --enable-mbstring=all \
  84.         --enable-mbregex \
  85.         --enable-json=shared \
  86.         --with-iconv=shared \
  87.         --with-xmlrpc=shared \
  88.         --with-pspell=shared \
  89.         --with-freetype-dir=shared,/usr \
  90.         --with-mime-magic=shared \
  91.     --with-gmp=shared \
  92.     --with-mhash=shared \
  93.         "
  94.     PEAR_INSTALLDIR=/opt/share/pear
  95.     export PEAR_INSTALLDIR
  96.         cd ${srcdir}/${_realname}-${pkgver}
  97.     # avoid linking against old db version
  98. ##    patch -p0 -i ${srcdir}/db-configure.patch || return 1
  99.         # apply suhosin patch
  100. ##        patch -p1 -i ${srcdir}/suhosin-patch-${_suhosinver}.patch || return 1
  101.     # apply fpm patch
  102. ##    patch -p1 -i ${srcdir}/${_realname}-${pkgver}-fpm-${_fpmversion}.diff || return 1
  103.         # cli
  104.     ./configure ${phpconfig} \
  105.                 --disable-cgi \
  106.                 --with-readline \
  107.                 --enable-pcntl \
  108.                 --with-pear=/opt/share/pear \
  109.                 ${phpextensions} || return 1
  110.         make || return 1
  111.         # make test
  112.         make INSTALL_ROOT=${pkgdir} install || return 1
  113.         # cleanup
  114.         rm -f ${pkfdir}/`${pkgdir}/opt/bin/php-config --extension-dir`/*.a
  115.         # install php.ini
  116.         install -D -m644 ${srcdir}/php.ini ${pkgdir}/opt/etc/php/php.ini || return 1
  117.         install -d -m755 ${pkgdir}/opt/etc/php/conf.d/ || return 1
  118.     # install php-fpm.conf
  119.     install -D -m644 ${srcdir}/php-fpm.conf ${pkgdir}/opt/etc/php/php-fpm.conf || return 1
  120.     install -D -m755 ${srcdir}/php-fpm ${pkgdir}/opt/etc/rc.d/php-fpm || return 1
  121.         # cgi and fcgi
  122.         ./configure ${phpconfig} \
  123.                 --enable-fastcgi \
  124.                 --enable-cgi \
  125.                 --enable-discard-path \
  126.                 --enable-force-cgi-redirect \
  127.                 --disable-cli \
  128.         --enable-fpm \
  129.         --with-fpm-log=/var/log/php-fpm.log \
  130.         --with-fpm-pid=/var/run/php-fpm.pid \
  131.                 ${phpextensions} || return 1
  132.         make || return 1
  133.         install -D -m755 sapi/cgi/php-cgi ${pkgdir}/opt/bin/php-cgi || return 1
  134.         # mod_php
  135.         ./configure ${phpconfig} \
  136.                 --with-apxs2 \
  137.                 --disable-cli \
  138.                 ${phpextensions} || return 1
  139.         make || return 1
  140.         install -D -m644 libs/libphp5.so ${pkgdir}/opt/lib/apache/libphp5.so || return 1
  141.         install -D -m644 ${srcdir}/apache.conf ${pkgdir}/opt/etc/httpd/conf/extra/php5_module.conf || return 1
  142. }
复制代码
5、编译安装
  1. cd php-fpm
  2. makepkg
  3. pacman -U php-fpm-5.2.6-12-i686.pkg.tar.gz
复制代码
没有pacman的话,看着改下安装路径后make install
6、修改相应的设置
修改下/opt/etc/{php.ini,php-fpm.ini},其中php.ini中路径添加/opt下的路径等php-fpm.ini中的用户和组改为www-data,php-cgi可以放到启动脚本里,也可启动直接:
  1. /opt/bin/php-cgi -x
复制代码
修改nginx下的设置为php-fpm中的端口或者socks
  1. #             fastcgi_pass   127.0.0.1:9000;
  2.               fastcgi_pass   unix:/tmp/fastcgi-nginx.socks;
  3.               fastcgi_pass   unix:/tmp/php-fpm.socks;
  4.               fastcgi_index  index.php;
  5.               fastcgi_param  SCRIPT_FILENAME    $document_root$script;
复制代码

---
至于新的稳定版的nginx(0.6.35,deb)和这个php-fpm的二进制包(gz,解开移到/opt下就能用),目前我来留着,以后就难说了,如果有需要的,我可以找个共享点发过去
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表