惜风不起、唯有努力!
linux上编译php

linux上编译php

ps: tar包自行到官网下载

编译依赖安装

yum install -y epel-release && yum clean all

yum install -y gcc gcc-devel libxml2-devel  openssl openssl-devel bzip2 bzip2-devel libpng libpng-devel freetype freetype-devel epel-release libmcrypt-devel libcurl-devel sqlite-devel libicu-devel oniguruma oniguruma-deve libjpeg libjpeg-devel oniguruma* glibc-headers gcc-c++

编译部署

groupadd nginx

#创建一个用户,不允许登陆和不创主目录
useradd -s /sbin/nologin -g nginx -M nginx

tar -xf php-7.4.29.tar.gz -C /usr/local/

cd /usr/local/ && mv php-7.4.29 php && cd php

./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--enable-mbstring \
--enable-xmlreader \
--enable-xmlwriter \
--enable-soap \
--enable-calendar \
--with-curl \
--with-zlib \
--enable-gd \
--with-pdo-sqlite \
--with-pdo-mysql \
--with-mysqli \
--with-mysql-sock \
--enable-mysqlnd \
--disable-rpath \
--enable-inline-optimization \
--with-bz2 \
--with-zlib \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-pcntl \
--enable-mbregex \
--enable-exif \
--enable-bcmath \
--with-mhash \
--with-jpeg=/usr \
--with-openssl \
--enable-ftp \
--with-kerberos \
--with-gettext \
--with-xmlrpc \
--with-xsl \
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-fileinfo

make -j 2

make install

修改配置并制作软连接和启动

cd /usr/local/php/ && cp php.ini-production ./etc/php.ini

cd ./etc/ && cp  php-fpm.conf.default php-fpm.conf

vim php-fpm.conf
//加入修改如下配置
[global]
pid = /run/php-fpm.pid
error_log = /var/log/php-fpm/php-fpm.log
include=/usr/local/php/etc/php-fpm.d/*.conf
[www]
listen = 9000
listen.mode = 666
user = nginx
group = nginx
pm = dynamic
pm.max_children = 10
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 15
pm.max_requests = 50
rlimit_files = 512
ps: 配置根据自己情况而定,上面只是参考

ln -s /usr/local/php/sbin/php-fpm /sbin/php-fpm && php-fpm -c (配置文件路径)
ss -lnutp|grep 9000

systemd配置如下

cd /usr/lib/systemd/system && touch php-fpm.service

[Unit]
Description=php-fpm Server
After=network.target
After=network-online.target
Wants=network-online.target

[Service]
#模式
Type=forking   
WorkingDirectory=/usr/local/php
#EnvironmentFile=/usr/local/php/etc/php-fpm.conf
ExecStart=/sbin/php-fpm -c /usr/local/php/etc/php-fpm.conf
TimeoutStopSec=5
#只kill主进程
KillMode=process
KillSignal=SIGQUIT

[Install]
WantedBy=multi-user.target

发表回复

您的电子邮箱地址不会被公开。