在第一次编译安装php5.6.30失败后,参考了http://www.phpworld.cn/system/php/11.html的一些内容,第二次编译安装成功,特此记录过程。

一、编译安装php5.6.30

安装环境:

#cat/etc/redhat-releaseCentOSrelease6.8(Final)

#/application/nginx/sbin/nginx-vnginxversion:nginx/1.6.3

下载php5.6.30安装包

wgethttp://cn2.php.net/distributions/php-5.6.30.tar.bz2

解压

tar-xjfphp-5.6.30.tar.bz2

安装所需依赖包

#rpm-qazlib-devellibxm12-devellibjpeg-devellibjpeg-turbo-devellibiconv-develfreetype-devellibpng-devellibpng-develgd-devellibcurl-devellibxslt-devel#yuminstallzlib-devellibxm12-devellibjpeg-devellibjpeg-turbo-devellibiconv-develfreetype-devellibpng-devellibpng-develgd-devellibcurl-devellibxslt-devel-y

安装libiconv库

wgettarzxflibiconv-1.14.tar.gzcdlibiconv-1.14./configure--prefix=/usr/local/libiconvmakemakeinstall

开始安装 php

[root@dariusphp-5.6.30]#./configure--prefix=/application/php5.6.30--with-mysql=mysqlnd--with-mysqli=mysqlnd--with-pdo-mysql=mysqlnd--with-iconv-dir=/usr/local/libiconv--with-freetype-dir--with-jpeg-dir--with-png-dir--with-zlib--with-libxml-dir=/usr--enable-xml--disable-rpath--enable-bcmath--enable-shmop--enable-sysvsem--enable-inline-optimization--with-curl--enable-mbregex--enable-fpm--enable-mbstring--with-mcrypt--with-gd--enable-gd-native-ttf--with-openssl--with-mhash--enable-pcntl--enable-sockets--with-xmlrpc--enable-zip--enable-soap--enable-short-tags--enable-static--with-xsl--with-fpm-user=nginx--with-fpm-group=nginx--enable-ftp--without-pear--disable-phar#因为本机没有pear包,所以选择暂时跳过(--without-pear--disable-phar),等php安装后再补装go-pear

make 编译

[root@dariusphp-5.6.30]#make.........Buildcomplete.Don'tforgettorun'maketest'.[root@dariusphp-5.6.30]#maketest

make test的结果报了一些问题,我没有理会,继续安装了

执行make install

[root@dariusphp-5.6.30]#makeinstallInstallingsharedextensions:/application/php5.6.30/lib/php/extensions/no-debug-non-zts-20131226/InstallingPHPCLIbinary:/application/php5.6.30/bin/InstallingPHPCLImanpage:/application/php5.6.30/php/man/man1/InstallingPHPFPMbinary:/application/php5.6.30/sbin/InstallingPHPFPMconfig:/application/php5.6.30/etc/InstallingPHPFPMmanpage:/application/php5.6.30/php/man/man8/InstallingPHPFPMstatuspage:/application/php5.6.30/php/php/fpm/InstallingPHPCGIbinary:/application/php5.6.30/bin/InstallingPHPCGImanpage:/application/php5.6.30/php/man/man1/Installingbuildenvironment:/application/php5.6.30/lib/php/build/Installingheaderfiles:/application/php5.6.30/include/php/Installinghelperprograms:/application/php5.6.30/bin/program:phpizeprogram:php-configInstallingmanpages:/application/php5.6.30/php/man/man1/page:phpize.1page:php-config.1InstallingPDOheaders:/application/php5.6.30/include/php/ext/pdo/


二、配置php

cpphp.ini-production/usr/local/php/etc/php.ini#复制php配置文件到安装目录rm-rf/etc/php.ini#删除系统自带配置文件

ln-s/usr/local/php/etc/php.ini/etc/php.ini#添加软链接到/etc目录

cp/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf#拷贝模板文件为php-fpm配置文件

ln-s/usr/local/php/etc/php-fpm.conf/etc/php-fpm.conf#添加软连接到/etc目录

修改php-fpm.conf

pid=run/php-fpm.pid #取消前面的分号

修改php-ini.conf

找到:disable_functions=

修改为:

disable_functions=passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname

#列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。

找到:;date.timezone =

修改为:

date.timezone=PRC#设置时区

找到:expose_php = On

修改为:

expose_php=Off#禁止显示php版本的信息

找到:short_open_tag = Off

修改为:

short_open_tag=ON#支持php短标签

注意:short_open_tag 必须打开.开启以后可以使用PHP的段标签:()。同时,只有开启这个才可以使用 <?= 以代替 <? echo 。有一些开源系统里会使用短标签,如果不打开的话会报错。

找到opcache.enable=0

修改为

opcache.enable=1#php支持opcode缓存

找到:;opcache.enable_cli=1 #php支持opcode缓存

修改为:

opcache.enable_cli=0

在最后一行添加:

zend_extension=opcache.so#开启opcode缓存功能

:wq #保存退出

配置nginx.conf

location~\.php${roothtml/bbs;#你网页根目录fastcgi_pass127.0.0.1:9000;fastcgi_indexindex.php;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;includefastcgi_params;}

创建测试文件:

[root@dariusbbs]#catindex.php<?phpphpinfo();?>[root@dariusbbs]#catindex.htmlbbs.html[root@dariusbbs]#pwd/application/nginx/html/bbs

启动php-fpm,重启nginx,并测试结果

/application/php/sbin/php-fpm-c/application/php/etc/php.ini-y/application/php/etc/php-fpm.conf

/application/nginx/sbin/nginx-sreload