下面的是參考https://typecodes.com/ 過了一遍,和前面的nginx 連接 測試沒有問題。
與MySQL連接的時候,注意參數(shù) --with-mysql-sock=/var/run/mysql/mysql.sock,需要和mysql里面設置的是一樣。
yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel
groupadd -r php && useradd -r -g php -s /bin/false -d /usr/local/php7 -M php
cd /usr/local/src
wget http://au1.php.net/distributions/php-7.1.1.tar.gz
tar zxvf php-7.1.1.tar.gz
cd php-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-fileinfo
make && make install
make test ##不是必須
ll /usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303/
直接使用編譯后未經優(yōu)化處理的配置
cp php.ini-production /usr/local/php7/etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
cp /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動態(tài)庫
zend_extension=opcache.so
extension=mysqli.so
extension=pdo_mysql.so
######設置PHP的時區(qū)
date.timezone = PRC
######開啟opcache
[opcache]
opcache.enable=1
######設置PHP腳本允許訪問的目錄(需要根據(jù)實際情況配置)
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 = nginx
group = nginx
######根據(jù)nginx.conf中的配置fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;設置PHP監(jiān)聽
; listen = 127.0.0.1:9000 #####不建議使用(看自己設置情況)
listen = /var/run/php-fpm/php-fpm.sock
######開啟慢日志
slowlog = /var/log/php-fpm/$pool-slow.log
request_slowlog_timeout = 10s
######設置php的session目錄(所屬用戶和用戶組都是nginx)
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session
echo -e '\nexport PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH\n' >> /etc/profile && source /etc/profile
mkdir -p /var/log/php-fpm/ && mkdir -p /var/run/php-fpm && cd /var/run/ && chown -R nginx:nginx php-fpm
mkdir -p /var/lib/php/session
chown -R nginx:nginx /var/lib/php
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
php-fpm -t
service php-fpm start
ps -aux | grep php ##php-fpm進程數(shù)和進程用戶nginx都是由www.conf中pm.start_servers和user的值分別決定的
root 26007 0.0 0.0 182016 6324 ? Ss 13:36 0:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
nginx 26008 0.0 0.0 182016 5884 ? S 13:36 0:00 php-fpm: pool www
nginx 26009 0.0 0.0 182016 5884 ? S 13:36 0:00 php-fpm: pool www
測試
網(wǎng)頁題目:php7.1.1一鍵安裝/配置文件簡單優(yōu)化
分享網(wǎng)址:
http://weahome.cn/article/pchpde.html