CentOS 7 安装 PHP 7.4.0 正式版

时间:2022-07-24
本文章向大家介绍CentOS 7 安装 PHP 7.4.0 正式版,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

php 教程 centos 源码 编译

CentOS 7 源码安装 PHP 7.4 正式版教程

1、准备编译环境

yum -y install epel-release yum-utils
yum config-manager --set-enabled PowerTools
yum -y install gcc gcc-c++ make autoconf bzip2 bzip2-devel libpng libpng-devel freetype-devel gmp-devel readline-devel curl-devel libxml2-devel libjpeg-devel bison openssl-devel uw-imap-devel libc-client sqlite-devel libicu-devel libedit-devel libxslt-devel oniguruma oniguruma-devel
#yum -y install http://mirror.centos.org/centos-7/7.7.1908/cloud/x86_64/openstack-queens/oniguruma-6.7.0-1.el7.x86_64.rpm
#yum -y install http://mirror.centos.org/centos-7/7.7.1908/cloud/x86_64/openstack-queens/oniguruma-devel-6.7.0-1.el7.x86_64.rpm

以及 libzip

2、下载并解压

wget https://www.php.net/distributions/php-7.4.0.tar.bz2 tar -jxf php-7.4.0.tar.bz2 cd php-7.4.0 3、配置并构建 PHP。在此步骤您可以使用很多选项自定义 PHP,例如启用某些扩展等。 运行 ./configure –help 命令来获得完整的可用选项清单。 在本示例中,我们仅进行包含 PHP-FPM 和 MySQL 支持的简单配置。

./configure --prefix=/usr 
   --sysconfdir=/etc/php 
   --with-config-file-path=/etc/php 
   --with-config-file-scan-dir=/etc/php/php.d 
   --bindir=/usr/bin 
   --docdir=/usr/share/doc 
   --sbindir=/usr/sbin 
   --libdir=/usr/lib64/php 
   --with-libdir=/usr/lib64/php 
   --libexecdir=/usr/libexec 
   --localstatedir=/var 
   --includedir=/usr/include 
   --localedir=/usr/local 
   --datarootdir=/usr/share 
   --datadir=/usr/share/php 
   --mandir=/usr/share/man 
   --infodir=/usr/share/info 
   --enable-fpm 
   --with-fpm-user=www-data 
   --with-fpm-group=www-data 
   --enable-mysqlnd 
   --enable-mysqlnd-compression-support 
   --enable-json 
   --with-openssl-dir 
   --with-zlib-dir 
   --with-freetype 
   --enable-gd-jis-conv 
   --enable-ftp 
   --enable-filter 
   --enable-fileinfo 
   --with-curl 
   --with-iconv 
   --with-bz2 
   --with-zlib 
   --with-zip 
   --with-xsl 
   --with-jpeg 
   --with-webp 
   --with-xpm 
   --without-iconv 
   --with-kerberos 
   --with-imap-ssl 
   --with-openssl 
   --enable-dom 
   --with-gettext 
   --with-mysqli=mysqlnd 
   --enable-pdo 
   --with-pdo-mysql=mysqlnd 
   --enable-simplexml 
   --enable-session 
   --enable-sysvsem 
   --enable-sysvmsg 
   --enable-sockets 
   --with-pear 
   --with-xmlrpc 
   --with-mhash 
   --enable-bcmath 
   --with-cdb 
   --enable-exif 
   --with-gmp 
   --enable-mbstring 
   --enable-mbregex 
   --with-readline 
   --enable-shmop 
   --enable-soap 
   --enable-sockets 
   --enable-pcntl 
   --enable-intl 
   --enable-re2c-cgoto 
   --with-libedit
make
sudo make install

4、创建配置文件,并将其复制到正确的位置。

cp php.ini-production /etc/php/php.ini
cp sapi/fpm/php-fpm.conf /etc/php/php-fpm.conf
cp sapi/fpm/www.conf /etc/php/php-fpm.d/www.conf
cp sapi/fpm/php-fpm.service /etc/systemd/system/php-fpm.service

5、需要着重提醒的是,如果文件不存在,则阻止 Nginx 将请求发送到后端的 PHP-FPM 模块, 以避免遭受恶意脚本注入的攻击。 将 php.ini 文件中的配置项 cgi.fix_pathinfo 设置为 0 。 打开 php.ini:

vi /etc/php/php.ini 定位到 cgi.fix_pathinfo= 并将其修改为如下所示:

cgi.fix_pathinfo=0 6、配置 php-fpm 服务

sudo systemctl start php-fpm 检查是否启动成功

sudo systemctl status php-fpm

如果出现错误:ERROR: [pool www] cannot get uid for user 'www-data' 则新建www-data 用户组:

groupadd www-data
useradd -g www-data www-data

设置服务自启动

sudo systemctl enable php-fpm 本文档未涵盖对 php-fpm 进行进一步配置的信息,如果您需要更多信息,请查阅相关文档。

本文由 Alone88 创作,采用 知识共享署名4.0 国际许可协议进行许可 本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名 最后编辑时间为: Aug 31, 2020 at 11:03 pm