5、提供PHP.ini文件
PHP.ini-production /u01/data/server/
PHP/etc/
PHP.ini
PHP;">
# 在840行左右-设置
PHP的opcache和memcache扩展库
zend_extension=opcache.so
extension=memcache.so
# 722行左右-设置
PHP的扩展库路径
extension_dir = "/u01/data/server/
PHP7/lib/
PHP/extensions/no-debug-non-zts-20151012/"
# 避免
PHP信息暴露在http头中
expose_
PHP = Off
# 避免暴露
PHP调用MysqL的
错误信息
display_errors = Off
# 开启
PHP错误日志(路径在
PHP-fpm.conf中配置)
log_errors = On
# 设置
PHP的时区
date.timezone = PRC
# 开启opcache(1733行左右)
opcache.enable=1
# 设置
PHP脚本允许访问的目录
# open_basedir = /usr/share/
Nginx/html;
6、配置PHP-fpm
PHP-fpm.conf 进程服务主配置文件
PHP;">
# 设置
错误日志的路径
error_log = /var/log/
PHP-fpm/error.log
# 引入www.conf
文件中的配置
include=/usr/local/
PHP7/etc/
PHP-fpm.d/*.conf
# 设置主进程打开的最大
文件数
rlimit_files = 102400
www.conf 进程服务扩展
配置文件
# 设置
用户和
用户组
user = www
group = www
# 设置
PHP监听方式
# listen = 127.0.0.1:9000
# 注意这里要设置
PHP套接字
文件的权限,默认是root,
Nginx无法访问。
listen = /var/run/
PHP-fpm/
PHP-fpm.sock
# 开启慢日志
slowlog = /var/log/
PHP-fpm/
PHP-slow.log
request_slowlog_timeout = 10s
# 设置工作进程数(根据实际情况设置)
pm.max_children = 50
# 这里需要注意,pm.start_servers 不能小于 pm.min_spare_servers
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 10
pm.max_requests = 10240
# 设置
PHP的session目录(所属
用户和
用户组都是www)
PHP_value[session.save_handler] = files
PHP_value[session.save_path] = /var/tmp/
PHP/session
7、提供PHP-fpm启动脚本
PHP;">
#! /bin/sh
#
prefix=/u01/data/server/
PHP7
exec_prefix=${prefix}
PHP_fpm_BIN=${exec_prefix}/sbin/
PHP-fpm
PHP_fpm_CONF=${prefix}/etc/
PHP-fpm.conf
PHP_fpm_PID=${prefix}/var/run/
PHP-fpm.pid
PHP_opts="--fpm-config $
PHP_fpm_CONF --pid $
PHP_fpm_PID"
wait_for_pid () {
try=0
while test $try -lt 35 ; do
case "$1" in
'created')
if [ -f "$2" ] ; then
try=''
break
fi
;;
'removed')
if [ ! -f "$2" ] ; then
try=''
break
fi
;;
esac
echo -n .
try=`expr $try + 1`
sleep 1
done
}
case "$1" in
start)
echo -n "Starting
PHP-fpm "
$
PHP_fpm_BIN --daemonize $
PHP_opts
if [ "$?" != 0 ] ; then
echo "
Failed"
exit 1
fi
wait_for_pid created $
PHP_fpm_PID
if [ -n "$try" ] ; then
echo "
Failed"
exit 1
else
echo " done"
fi
;;
stop)
echo -n "Gracefully shutting down
PHP-fpm "
if [ ! -r $
PHP_fpm_PID ] ; then
echo "warning,no pid file found -
PHP-fpm is not running ?"
exit 1
fi
kill -QUIT `cat $
PHP_fpm_PID`
wait_for_pid removed $
PHP_fpm_PID
if [ -n "$try" ] ; then
echo "
Failed. Use force-quit"
exit 1
else
echo " done"
fi
;;
status)
if [ ! -r $
PHP_fpm_PID ] ; then
echo "
PHP-fpm is stopped"
exit 0
fi
PID=`cat $
PHP_fpm_PID`
if ps -p $PID | grep -q $PID; then
echo "
PHP-fpm (pid $PID) is running..."
else
echo "
PHP-fpm dead but pid file exists"
fi
;;
force-quit)
echo -n "Terminating
PHP-fpm "
if [ ! -r $
PHP_fpm_PID ] ; then
echo "warning,no pid file found -
PHP-fpm is not running ?"
exit 1
fi
kill -TERM `cat $
PHP_fpm_PID`
wait_for_pid removed $
PHP_fpm_PID
if [ -n "$try" ] ; then
echo "
Failed"
exit 1
else
echo " done"
fi
;;
restart)
$0 stop
$0 start
;;
reload)
echo -n "Reload service
PHP-fpm "
if [ ! -r $
PHP_fpm_PID ] ; then
echo "warning,no pid file found -
PHP-fpm is not running ?"
exit 1
fi
kill -USR2 `cat $
PHP_fpm_PID`
echo " done"
;;
*)
echo "Usage: $0 {start|stop|force-quit|restart|reload|status}"
exit 1
;;
esac
八、启动PHP-fpm程序
PHP;">
/etc/init.d/
PHP-fpm start
#
修改套接字
文件权限
chown -R /var/run/
PHP-fpm/
原文链接:https://www.f2er.com/php/19813.html