一.安装php依赖库
ftp://xmlsoft.org/libxml2/libxml2-2.9.3.tar.gz
yum install python-devel -y
cd /download/wget -c ftp://xmlsoft.org/libxml2/libxml2-2.9.3.tar.gz
tar xf libxml2-2.9.3.tar.gz -C tmp/
cd tmp/libxml2-2.9.3/
./configure --prefix=/usr/local/services/
make && make install
https://curl.haxx.se/download/curl-7.44.0.tar.gz
tar xf curl-7.44.0.tar.gz -C tmp/cd tmp/curl-7.44.0/
./configure --prefix=/usr/local/services/
make && make install
http://www.ijg.org/files/jpegsrc.v9a.tar.gz
tar xf jpegsrc.v9a.tar.gz -C tmp/cd tmp/jpeg-9a/
./configure --prefix=/usr/local/services/
make && make install
ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng16/libpng-1.6.28.tar.gz
http://download.sourceforge.net/libpng/libpng-1.6.2.tar.gz
tar xf libpng-1.6.2.tar.gz -C tmp/cd tmp/libpng-1.6.2/
./configure --prefix=/usr/local/services/
make && make install
http://download.savannah.gnu.org/releases/freetype/freetype-2.6.5.tar.gz
http://download.chinaunix.net/down.php?id=35028&ResourceID=3295&site=1
tar xf freetype-2.4.3.tar.bz2 -C tmp/cd tmp/freetype-2.4.3/
./configure --prefix=/usr/local/services/
make && make install
https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz
http://download.chinaunix.net/down.php?id=45065&ResourceID=5804&site=1
tar xf libevent-2.0.21-stable.tar.gz -C tmp/cd tmp/libevent-2.0.21-stable/
./configure --prefix=/usr/local/services/ --disable-debug-mode
make && make install
https://github.com/skvadrik/re2c/releases/download/0.16/re2c-0.16.tar.gz
http://download.chinaunix.net/down.php?id=45065&ResourceID=5804&site=1
tar xf re2c-0.16.tar.gz -C tmp/cd tmp/re2c-0.16/
./configure --prefix=/usr/local/services/
make && make install
ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
tar xf libmcrypt-2.5.7.tar.gz -C tmp/cd tmp/libmcrypt-2.5.7/
./configure --prefix=/usr/local/services/
make && make install
二.安装php
wget http://cn2.php.net/distributions/php-5.6.31.tar.gz
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --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-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --with-ldap --disable-fileinfo --enable-maintainer-zts
make && make install
configure过程中各种糟心,缺少各种xx.h文件或者各种xx未声明,一般都是缺少开发库
yum install libxml2-devel -y
yum install libcurl-devel -y
yum install libjpeg-devel -y
yum install libpng-devel -y
yum install freetype-devel -y
yum install libmcrypt* -y
libmcrypt明明已经安装但缺少devel包,centos自带yum和163yum都没有对应包下载,epel可以很好的解决这一难题,参考链接: http://www.cnblogs.com/SunnyZhu/p/5420549.html http://www.linuxidc.com/Linux/2015-08/121079.htm
三.修改php-fpm配置文件
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /download/tmp/php-5.6.31/php.ini-production php.ini
vi php-fpm.conf
;listen = 127.0.0.1:9000
listen = /tmp/php-cgi.sock #以socke的方式访问.注视掉.ip端口的方式.
; Default Value: log/php-fpm.log
error_log = /data/php_log/php.error #根据不同的项目名.定义不同的.sock 和日志.
# 调整进程数量
pm.max_children:p静态方式下开启的php-fpm进程数量。
pm.start_servers:动态方式下的起始php-fpm进程数量。
pm.min_spare_servers:动态方式下的最小php-fpm进程数量。
pm.max_spare_servers:动态方式下的最大php-fpm进程数量。
尝试访问php页面出错,查看错误日志:
var/log/nginx/error.log报错:
2017/08/04 04:55:58 [crit] 61807#61807: *6 connect() to unix:/tmp/php-cgi.sock failed (13: Permission denied) while connecting to upstream, client: 192.168.119.129, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-cgi.sock:", host: "192.168.119.130"
ll /tmp/php-cgi.sock发现属主属组都为root用户,因此错误原因就是:nginx的deamon用户无权限调用该socket与php-fpm通信
修改php-fpm配置文件/usr/local/php/etc/php-fpm.conf
使/tmp/php-cgi.sock属主属组为nginx执行用户
listen.owner = deamon
listen.group = deamon
修改nginx配置文件/usr/local/nginx/conf/nginx.conf
location ~ \.php$ {
root /www;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}