CentOS7 编译安装php7.3.11
作者:互联网
下载并安装依赖
[root@blogs src]# wget https://www.php.net/distributions/php-7.3.11.tar.gz
[root@blogs src]# useradd -M -s /bin/false -U php
[root@blogs src]# yum install libzip-devel.x86_64 bzip2-devel curl-devel freetype-devel libjpeg-devel libpng-devel libxslt-devel libxml2-devel zlib.x86_64 zlib-devel.x86_64 pcre.x86_64 pcre-devel.x86_64 openssl.x86_64 openssl-devel.x86_64 -y
安装libzip1.x版本
在php7.3版本中,要求libzip版本要大于等于0.11,否则配置出错
[root@blogs src]# yum remove -y libzip.x86_64 libzip-devel.x86_64
[root@blogs src]# wget https://libzip.org/download/libzip-1.2.0.tar.gz
[root@blogs src]# tar xf libzip-1.2.0.tar.gz
[root@blogs src]# cd libzip-1.2.0
[root@blogs libzip-1.2.0]# ./configure && make && make install
添加libzip库路径到ld.so.conf中使其去加载
[root@blogs php-7.3.11]# cat >> /etc/ld.so.conf << EOF
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64
EOF
[root@blogs php-7.3.11]# ldconfig -v
[root@blogs php-7.3.11]# cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
编译安装php7.3
[root@blogs src]# tar xf php-7.3.11.tar.gz
[root@blogs src]# cd php-7.3.11
[root@blogs php-7.3.11]# ./configure --prefix=/usr/local/php \
--with-fpm-user=php
--with-fpm-group=php
--with-curl
--with-freetype-dir
--with-gd
--with-gettext
--with-iconv-dir
--with-kerberos
--with-libdir=lib64
--with-libxml-dir
--with-mysqli
--with-openssl
--with-pcre-regex
--with-pdo-mysql
--with-pdo-sqlite
--with-pear
--with-png-dir
--with-jpeg-dir
--with-xmlrpc
--with-xsl
--with-zlib
--with-bz2
--with-mhash
--enable-fpm
--enable-bcmath
--enable-libxml
--enable-inline-optimization
--enable-mbregex
--enable-mbstring
--enable-opcache
--enable-pcntl
--enable-shmop
--enable-soap
--enable-sockets
--enable-sysvsem
--enable-sysvshm
--enable-xml
--enable-zip
--enable-fpm
[root@blogs php-7.3.11]# make && make install
建立配置文件
[root@blogs php-7.3.11]# cp /usr/local/src/php-7.3.11/php.ini-production /usr/local/php/lib/php.ini
[root@blogs php-7.3.11]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@blogs php-7.3.11]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
[root@blogs php-7.3.11]# cp /usr/local/src/php-7.3.11/sapi/fpm/php-fpm.service /usr/lib/systemd/system
[root@blogs php-7.3.11]# ln -s /usr/local/php/sbin/php-fpm /usr/local/bin/
优化php配置
php-fpm.conf
[root@blogs /]# grep -Ev ";|^$" /usr/local/php/etc/php-fpm.conf
[global]
pid = run/php-fpm.pid #pid文件位置
error_log = log/php-fpm.log #日志路径
log_level = notice #日志级别 {alert, error, warning, notice, debug}
include=/usr/local/php/etc/php-fpm.d/*.conf
www.conf
[root@blogs /]# grep -Ev ";|^\(" /usr/local/php/etc/php-fpm.d/www.conf
[www]
user = php
group = php
listen = 127.0.0.1:9000
pm = dynamic
pm.max_children = 20
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.max_requests = 2000
slowlog = log/\)pool.log.slow
rlimit_files = 65536
参赛解释:
pm = dynamic
php-fpm分为两种模式,静态和动态,当pm = static是为静态模式,pm = dynamic时为动态模式。
php-fpm可以根据所处于的模式对进程数量进行减少或增加,在静态模式下,无法增加或减少进程,在动态模式下可以根据配置的参数进行自动调整进程数量,在繁忙的时候可以多打开几个进程数,在请求少时使用较少的进程数量,从而合理的使用资源。
pm.max_children
静态方式下开启的php-fpm进程数量,此参数指定了php-fpm的进程数量,只有在 pm = static的状态下生效
pm.start_servers
动态方式下的起始php-fpm进程数量,在pm = dynamic下,刚开始启动的php-fpm进程数量,只有在 pm = dynamic的状态下生效
pm.min_spare_servers
动态方式下的最小php-fpm进程数量,随机调整到最小的php-fpm进程数量,只有在 pm = dynamic的状态下生效
pm.max_spare_servers
动态方式下的最大php-fpm进程数量,随机调整到最大的php-fpm进程数量,只有在 pm = dynamic的状态下生效
注:pm.max_spare_servers指定的进程数量必须等于或小于pm.max_children进程数量,否则启动失败
pm.max_requests
设置每个子进程重生之前服务的请求数。对于可能存在内存泄漏的第三方模块来说是非常有用的。如果设置为 ‘0’ 则一直接受请求,等同于 PHP_FCGI_MAX_REQUESTS 环境变量。默认值:0
rlimit_files
php-fpm进程的文件打开数,此数量需要php-fpm运行用户php具备这个打开数
启动php-fpm
可以看到php-fpm的进程数量与我们配置文件中设定的一致
[root@blogs log]# systemctl start php-fpm
[root@blogs log]# systemctl status php-fpm
● php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor preset: disabled)
Active: active (running) since Fri 2019-11-08 16:09:43 CST; 2min 22s ago
Main PID: 4263 (php-fpm)
CGroup: /system.slice/php-fpm.service
├─4263 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
├─4264 php-fpm: pool www
├─4265 php-fpm: pool www
├─4266 php-fpm: pool www
├─4267 php-fpm: pool www
└─4268 php-fpm: pool www
Nov 08 16:09:43 blogs systemd[1]: Started The PHP FastCGI Process Manager.
Nov 08 16:09:43 blogs systemd[1]: Starting The PHP FastCGI Process Manager...
Nginx代理PHP进行访问
以下内容加入nginx.conf的server中
location ~* \.php$ {
root /usr/local/nginx/html;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
[root@blogs log]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@blogs log]# /usr/local/nginx/sbin/nginx -s reload
cat >> /usr/local/nginx/html/index.php << EOF
EOF
访问测试
http://IP/index.php
标签:11,fpm,blogs,php7.3,CentOS7,--,usr,php,root 来源: https://www.cnblogs.com/beijifs/p/14622003.html