一.安裝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都沒有對應包(libmcrypt-devel)下載,epel可以很好的解決這一難題,參考鏈接: http://www.cnblogs.com/SunnyZhu/p/5420549.html http://www.linuxidc.com/Linux/2015-08/121079.htm yum install epel-release -y #除了rpm安裝,也可yum安裝epel yum install libmctypt-devel -y yum install openldap openldap-devel -y cp -frp /usr/lib64/libldap* /usr/lib/
三.修改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 /usr/local/php/etc/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進程數量。
mkdir /data/php_log
嘗試訪問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執行用戶
user = deamon group = deamon 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; }
啟動php
#/usr/local/php/sbin/php-fpm