PHP7编译及配置php-fpm开机启动

PHP 7+ 版本极大地改进了性能,在一些WordPress基准测试当中,性能可以达到PHP 5.6的3倍。目前很多用户已从php5升到php7.

1.下载php

首先在php官网下载php安装包。php官网下载为http://cn2.php.net/distributions. 解压到/usr/local目录

wget https://www.php.net/distributions/php-7.4.5.tar.gz
tar -zxvf php-7.4.5.tar.gz -C /usr/local

2.安装php依赖库

安装php需要用到的依赖库

yum -y install autoconf automake libtool libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel postgresql-devel aspell-devel readline-devel libxslt-devel net-snmp-devel unixODBC-devel libicu-devel libc-client-devel libXpm-devel libvpx-devel libxslt enchant-devel openldap openldap-devel db4-devel gmp-devel sqlite-devel mysql-devel

3.创建用户和组

groupadd www
useradd -g www www

4.php编译

cd /usr/local/php-7.4.5
#执行./configure
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-mysqlnd-compression-support --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --with-mcrypt --with-libmbfl --enable-ftp --with-gd --enable-gd-jis-conv --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-opcache --with-pear --enable-maintainer-zts --with-ldap=shared --without-gdbm
#编译与安装
make
make install

5.php.ini与php-fpm配置

进入/usr/local/etc目录

cp php-fpm.conf default php-fpm.conf
vim php-fpm.conf
#进行如下配置
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
log_level = notice

进入php-fpm.d目录

cp www.conf.default www.conf
vim www.conf
#进行如下配置
listen = /tmp/php-cgi.sock #和nginx fastcgi配置相同
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 20
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers = 20
pm.max_requests = 1024
pm.process_idle_timeout = 10s
request_terminate_timeout = 100
request_slowlog_timeout = 0
slowlog = var/log/slow.log

/usr/local/php/sbin/php-fpm执行

6.php-fpm开机启动配置

创建/usr/lib/systemd/system/php-fpm.service脚本文件。脚本下载:[download id=”17″],脚本如下:

[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=simple
PIDFile=/usr/local/php/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID

[Install]
WantedBy=multi-user.target

加入启动服务

systemctl enable php-fpm.service

留下评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据