安装环境依赖
YUM源配置
配置yum源: https://lolicp.com/linux/2021155.html
Yum_Install_List=(libxml2-devel oniguruma-devel php-devel sqlite-devel openssl openssl-devel bzip2-devel libcurl-devel curl gmp-devel libxslt-devel libjpeg-turbo libjpeg-turbo-devel libpng libpng-devel freetype freetype-devel readline readline-devel gcc gcc-c++ wget)
Park_Check=`rpm -q "${Yum_Install_List[@]}" |awk '/is not/ {print $2}'`
if [ ! -z "${Park_Check}" ];then
yum -y install ${Park_Check[@]}
fi
安装php
下载并配置PHP
[root@master ~]# Php_Path='/usr/local/php74'
[root@master ~]# Php_Path_Src="${Php_Path}/src"
[root@master ~]# mkdir -p "${Php_Path_Src}"
[root@master ~]# Php_User='nginx'
[root@master ~]# cd "${Php_Path_Src}"
[root@master src]# wget https://www.php.net/distributions/php-7.4.3.tar.gz
[root@master src]# tar xf php-7.4.3.tar.gz
[root@master src]# cd php-7.3.32/
编译安装
[root@master php-7.3.32]# ./configure --prefix="${Php_Path}" --with-config-file-path="${Php_Path}/etc" --enable-fpm --with-fpm-user="${Php_User}" --with-fpm-group="${Php_User}" --disable-debug --enable-opcache --enable-inline-optimization --disable-rpath --enable-shared --enable-soap --with-libxml-dir --with-xmlrpc --with-openssl --with-mhash --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --with-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-mysqlnd-compression-support --with-pear && make -j 4 && make install
拷贝配置文件
cp "${Php_Path}/etc/php-fpm.conf.default" "${Php_Path}/etc/php-fpm.conf"
useradd -M -s /sbin/nologin "${Php_User}"
ln -s "${Php_Path}/sbin/php-fpm" /usr/local/sbin/
编辑php-fpm配置文件
配置文件路径:/usr/local/php74/etc
[root@master etc]# vim php-fpm.conf
[520ym_bbw]
listen.owner = nginx
listen.group = nginx
; 开放范围及端口
listen = 0.0.0.0:9002
; 运行用户名
user = nginx
; 运行用户组
group = nginx
; 为accept处理的socket队列大小,-1 on FreeBSD and OpenBSD,其他平台默认65535,高并发时重要,合理设置会及时处理排队的请求;太大会积压太多,处理完后nginx在前面都等超时断开这个和fpm的socket连接了,就杯具了。不要用-1,建议1024以上,最好是2的幂值。
listen.backlog = 2048
; 进程管理模式,dynamic:动态;static:静态
pm = static
; 静态模式下开启的php-fpm进程数量
pm.max_children = 8
; 动态模式下初始php-fpm进程数量
pm.start_servers = 8
; 动态方式下最小php-fpm进程数量
pm.min_spare_servers = 5
; 动态方式下最大php-fpm进程数量
pm.max_spare_servers = 20
; 在进程空闲多少时间后结束进程
pm.process_idle_timeout = 10s;
; 每个子进程接收多少请求就被回收,可防止内存泄露。
pm.max_requests = 128
php启停脚本
#!/bin/bash
#PHP启动控制脚本,Docker
# Author: lolicp.com
`Php_Path='/usr/local/php74'
Php_Fpm_Path="${Php_Path}/sbin/php-fpm"
php_conf="${Php_Path}/php.ini"
Php_Start(){
Check_Php_Status=$(ps -C php-fpm |awk 'NR==2 {print $1}')
if [ -z "${Check_Php_Status}" ];then
${Php_Fpm_Path} -c ${php_conf}
Check_Php_Status=$(ps -C php-fpm |awk 'NR==2 {print $1}')
if [ ! -z "${Check_Php_Status}" ];then
echo -e "\033[32mphp-fpm Server is Running~\033[0m"
else
echo -e "\033[31m进程启动失败!\033[0m"
exit 1
fi
else
echo -e "\033[31mphp-fpm进程已运行!\033[0m"
fi
}
Php_Stop(){
Check_Php_Status=$(ps -C php-fpm |awk 'NR>1 {print $1}')
if [ ! -z "${Check_Php_Status}" ];then
kill -QUIT ${Check_Php_Status}
echo -e "\033[32mphp-fpm进程以杀死!\033[0m"
sleep 3
else
echo -e "\033[31mphp-fpm进程未运行!\033[0m"
fi
}
case $1 in
start)
Php_Start
;;
stop)
Php_Stop
;;
restart)
Php_Stop
Php_Start
;;
*)
echo -e '(start|stop|restart)'
esac`
启动服务
[root@master etc]# phpd start
[20-Mar-2020 20:06:13] WARNING: Nothing matches the include pattern '/usr/local/php74/etc/php-fpm.d/*.conf' from /usr/local/php74/etc/php-fpm.conf at line 143.
php-fpm Server is Running~