实验环境:CentOS6.5

安装版本:php-5.2.17.tar.bz2、php-5.2.17-fpm-0.5.14.diff.gz(http://php-fpm.org/下载地址)

需要提前安装软件:libxml2-devel、libcurl-devel、libjpeg-turbo  libjpeg-turbo-devel、 libpng libpng-devel、

  freetype freetype-devel、openldap-devel、libmcrypt libmcrypt-devel、 libmhash libmhash-devel

 psiconv psiconv-devel、libiconv、openssl openssl-devel、

1.解压安装libiconv-1.14.tar.gz

tar xf libiconv-1.14.tar.gz

cd libiconv-1.14

./configure --prefix=/usr/local/libiconv

make && make install

2.解压PHP包

tar xf php-5.2.17.tar.bz2

gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1 (如下载补丁包则会没有--enable-fastcgi选项)

2.编译安装PHP(fastcgi模式)

./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-iconv-dir=/usr/local/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--with-mcrypt \
--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-mhash \
--enable-pcntl \
--enable-sockets \
--with-openssl \
--with-ldap \
--with-ldap-sasl \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--without-pear

{--prefix=/usr/local/php \ 指定PHP安装路径

--with-config-file-path=/usr/local/php/etc \ 指定php.ini文件路径

--with-mysql=/usr/local/mysql \MySQL安装路径,对MySQL的支持

--with-mysqli=/usr/local/mysql/bin/mysql_config \ 扩展技术不仅可以调用MySQL的存储过程、处理MySQL事务,而且还可以使访问数据库工作变得更加稳定。 

--with-iconv-dir=/usr/local/libiconv \

--with-freetype-dir \打开对free-type字体库的支持

--with-jpeg-dir \ 打开对jpeg图片的支持

--with-png-dir \ 打开对png图片的支持

--with-zlib \ 打开zlib的支持

--with-libxml-dir=/usr \打开对libxml2库的支持

--enable-xml \支持 James Clark's 写的 XML 解析程序库

--disable-rpath \

--enable-discard-path \

--enable-safe-mode \ 打开安全模式

--enable-bcmath \ 打开高精确度函数。必须要先安装本函数库,本选项方有效。

--enable-shmop \允许PHP读,写,创建和删除UNIX共享内存段

--enable-sysvsem \ 使用sysV的信号机制

--with-curl \ 打开url浏览器工具的支持

--with-curlwrappers \运用crl工具打开url流

--enable-mbregex \

--enable-fastcgi \支持fastcgi方式启动PHP

--enable-fpm \ 打上php-fpm补丁后才有这个参数,cgi方式安装的启动程序

--enable-force-cgi-redirect \重定向方式启动PHP

--enable-mbstring \支持ncurses屏幕绘制以及文本终端的图形互动功能的动态库

--with-mcrypt \mcrypt算法的扩展

--with-mhash \ mhash算法的扩展

--enable-inline-optimization \ 优化线程

--with-gd \ 打开gd库的支持

--enable-gd-native-ttf \

--enable-pcntl \

--enable-sockets \打开sockets支持

--with-openssl \opsenssl的支持,

--with-ldap \ 使用目录协议LDAP

--with-ldap-sasl \

--with-xmlrpc \

--enable-zip \ 打开对zip的支持

--enable-soap \

--without-pear

}

make 

(回出现make: *** [ext/openssl/openssl.lo] Error 1

网上搜索说#make ZEND_EXTRA_LIBS='-liconv' 可以解决问题)

make test

make install


错误一:缺少libmcrypt、安装libmcrypt-devel

错误二:缺少iconv,安装libiconv

错误三:各种其他问题,网上搜索没有解决掉,建议安装php-5.2.17.tar.bz2(本人实测可以安装成功)


启动php-fpm的时候出现

Starting php_fpm Dec 29 15:27:32.502790 [ERROR] fpm_unix_conf_wp(), line 124: please specify user and group other than root, pool 'default'

解决办法;

只需要修改php-fpm.conf

          Unix user of processes

 <!--     <value name="user">nobody</value>   -->

          Unix group of processes

 <!--     <value name="group">nobody</value>   -->

     

将<!– –>去掉即可。至于user/group根据实际情况修改(www)。

重新启动 /usr/local/webserver/php-fpm/sbin/php-fpm start 成功了!(php-fpm无法启动解决方法出处:http://lxsym.blog.51cto.com/1364623/754029)


编辑[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf  实现nginx使用FastCGI支持php

server {
        listen       80;
        server_name  www.htccms.com;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
            root   /var/www/htccms/;
            index   index.php index.html;
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location ~ ^/(p_w_picpaths|javascript|js|css|flash|media|static)/ {
                expires 30d;
        }
        location ~ \.php$ {
            root /var/www/htccms/;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }