下面的是参考https://typecodes.com/过了一遍,和前面的nginx连接测试没有问题。与mysql连接的时候,注意参数--with-mysql-sock=/var/run/mysql/mysql.sock,需要和mysql里面设置的是一样。yum-yinstalllibxml2libxml2-developensslopenssl-develcurl-devellibjpeg-devellibpng-develfreetype-devellibmcrypt-develgroupadd-rphp&&useradd-r-gphp-s/bin/false-d/usr/local/php7-Mphpcd/usr/local/srcwgethttp://au1.php.net/distributions/php-7.1.1.tar.gz

tarzxvfphp-7.1.1.tar.gzcdphp-7.1.1./configure\--prefix=/usr/local/php7\--exec-prefix=/usr/local/php7\--bindir=/usr/local/php7/bin\--sbindir=/usr/local/php7/sbin\--includedir=/usr/local/php7/include\--libdir=/usr/local/php7/lib/php\--mandir=/usr/local/php7/php/man\--with-config-file-path=/usr/local/php7/etc\--with-mysql-sock=/var/run/mysql/mysql.sock\--with-mcrypt=/usr/include\--with-mhash\--with-openssl\--with-mysql=shared,mysqlnd\--with-mysqli=shared,mysqlnd\--with-pdo-mysql=shared,mysqlnd\--with-gd\--with-iconv\--with-zlib\--enable-zip\--enable-inline-optimization\--disable-debug\--disable-rpath\--enable-shared\--enable-xml\--enable-bcmath\--enable-shmop\--enable-sysvsem\--enable-mbregex\--enable-mbstring\--enable-ftp\--enable-gd-native-ttf\--enable-pcntl\--enable-sockets\--with-xmlrpc\--enable-soap\--without-pear\--with-gettext\--enable-session\--with-curl\--with-jpeg-dir\--with-freetype-dir\--enable-opcache\--enable-fpm\--enable-fastcgi\--with-fpm-user=nginx\--with-fpm-group=nginx\--without-gdbm\--disable-fileinfomake&&makeinstallmaketest##不是必须ll/usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303/

直接使用编译后未经优化处理的配置cpphp.ini-production/usr/local/php7/etc/php.inicpsapi/fpm/init.d.php-fpm/etc/init.d/php-fpmcp/usr/local/php7/etc/php-fpm.conf.default/usr/local/php7/etc/php-fpm.confcp/usr/local/php7/etc/php-fpm.d/www.conf.default/usr/local/php7/etc/php-fpm.d/www.conf

修改配置文件vim/usr/local/php7/etc/php.ini######避免PHP信息暴露在http头中expose_php=Off######避免暴露php调用mysql的错误信息display_errors=Off######在关闭display_errors后开启PHP错误日志(路径在php-fpm.conf中配置)log_errors=On######设置PHP的扩展库路径extension_dir="/usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303/"######设置PHP的opcache和mysql动态库zend_extension=opcache.soextension=mysqli.soextension=pdo_mysql.so######设置PHP的时区date.timezone=PRC######开启opcache[opcache]opcache.enable=1######设置PHP脚本允许访问的目录(需要根据实际情况配置)open_basedir=/etc/nginx/html;

vim/usr/local/php7/etc/php-fpm.conf######设置错误日志的路径error_log=/var/log/php-fpm/error.log######引入www.conf文件中的配置include=/usr/local/php7/etc/php-fpm.d/*.conf

vim/usr/local/php7/etc/php-fpm.d/######设置用户和用户组user=nginxgroup=nginx######根据nginx.conf中的配置fastcgi_passunix:/var/run/php-fpm/php-fpm.sock;设置PHP监听;listen=127.0.0.1:9000#####不建议使用(看自己设置情况)listen=/var/run/php-fpm/php-fpm.sock######开启慢日志slowlog=/var/log/php-fpm/$pool-slow.logrequest_slowlog_timeout=10s######设置php的session目录(所属用户和用户组都是nginx)php_value[session.save_handler]=filesphp_value[session.save_path]=/var/lib/php/session

echo-e'\nexportPATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH\n'>>/etc/profile&&source/etc/profilemkdir-p/var/log/php-fpm/&&mkdir-p/var/run/php-fpm&&cd/var/run/&&chown-Rnginx:nginxphp-fpmmkdir-p/var/lib/php/sessionchown-Rnginx:nginx/var/lib/phpchmod+x/etc/init.d/php-fpmchkconfig--addphp-fpmchkconfigphp-fpmonphp-fpm-tservicephp-fpmstartps-aux|grepphp##php-fpm进程数和进程用户nginx都是由www.conf中pm.start_servers和user的值分别决定的root260070.00.01820166324?Ss13:360:00php-fpm:masterprocess(/usr/local/php7/etc/php-fpm.conf)nginx260080.00.01820165884?S13:360:00php-fpm:poolwwwnginx260090.00.01820165884?S13:360:00php-fpm:poolwww

测试<?phpphpinfo();?>