MENU

Centos7编译安装php7.4

December 15, 2019 • linux相关

下载&解压

https://www.php.net/downloads.php

wget https://www.php.net/distributions/php-7.4.0.tar.gz
tar -zxvf php-7.4.0.tar.gz
cd php-7.4.0

生成配置

./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-zlib-dir \
--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-openssl \
--enable-ftp \
--with-kerberos \
--with-gettext \
--with-xmlrpc \
--with-xsl \
--enable-fpm \
--with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-fpm-systemd \
--disable-fileinfo

期间会报各种依赖错误,需要补上缺少的库。

编译&安装

make && make install

配置php-fpm.conf

cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf

修改用户/组

user = www
group = www

添加用户/组

groupadd www
useradd -g www www

启动php-fpm

/usr/local/php/sbin/php-fpm

开机自启动

加入启动服务项:

vim /lib/systemd/system/php-fpm.service

保存以下内容:

[Unit]
Description=php-fpm
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/php/sbin/php-fpm
PrivateTmp=true
[Install]
WantedBy=multi-user.target

激活&启动:

systemctl enable php-fpm
systemctl start php-fpm

依赖包

No package 'libsystemd' found
No package 'libxml-2.0' found
No package 'sqlite3' found
No package 'libcurl' found
No package 'libpng' found
No package 'oniguruma' found
No package 'libxslt' found

安装:

yum -y install systemd-devel
yum -y install libxml2 libxml2-devel
yum -y install sqlite-devel
yum -y install bzip2 bzip2-devel
yum -y install curl curl-devel
yum -y install libpng libpng-devel
yum -y install http://rpms.remirepo.net/enterprise/7/remi/x86_64//oniguruma5-6.9.4-1.el7.remi.x86_64.rpm
yum -y install http://rpms.remirepo.net/enterprise/7/remi/x86_64//oniguruma5-devel-6.9.4-1.el7.remi.x86_64.rpm
yum -y install libxslt libxslt-devel
Last Modified: November 19, 2021