CentOS 7 yum 安装 PHP7.3

  • Remi 软件源
    Remi 软件源 主要提供最新版的 PHP 软件包和其他一些 PHP 扩展工具包,它是针对 Fedora 和 RHEL 系分支变体 (包括:RHEL, CentOS, Oracle Linux 等等) 要安装 PHP,推荐使用 Remi 软件源。Remi 对 PHP 的支持和更新都很积极,可以在第一时间获得新版本的支持。

安装 EPEL 源及源管理工具:

1
yum install epel-release yum-utils

安装 REMI 源:

1
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

安装 PHP7.3 及扩展:

1
2
3
4
5
6
7
8
yum install -y php73-php-fpm php73-php-cli php73-php-bcmath php73-php-gd php73-php-json php73-php-mbstring php73-php-mcrypt php73-php-mysqlnd php73-php-opcache php73-php-pdo php73-php-pecl-crypto php73-php-pecl-mcrypt php73-php-pecl-geoip php73-php-pecl-swoole php73-php-recode php73-php-snmp php73-php-soap php73-php-xmll

php73 -v #查看版本
systemctl enable php73-php-fpm #开启开机自启
systemctl restart php73-php-fpm #重启
systemctl start php73-php-fpm #启动
systemctl stop php73-php-fpm #关闭
systemctl status php73-php-fpm #检查状态

配置文件路径:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#查找php.ini位置:
find /etc/opt/remi/php73 -name php.ini

# The current PHP memory limit is below the recommended value of 512MB.
vi /etc/opt/remi/php73/php.ini
memory_limit = 512M

#如果你运行的是 nginx 而不是 apache,修改
vi /etc/opt/remi/php73/php-fpm.d/www.conf
user = apache
group = apache
# Replace the values with
user = nginx
group = nginx

#查找 php 和扩展的安装包:
rpm -qa | grep 'php'

#查看 php73-php-pecl-swoole4-4.4.15-1.el7.remi.x86_64 的安装路径:
rpm -ql php73-php-pecl-swoole4-4.4.15-1.el7.remi.x86_64

设置php:

1
2
3
4
5
6
7
8
9
# 将php73链接到系统环境变量中,就可以使用 php -v
ln -s /opt/remi/php73/root/usr/bin/php /usr/bin/php

# 将 cgi.fix_pathinfo 设置为 0
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/' /etc/opt/remi/php73/php.ini

关于 cgi.fix_pathinfo 选项请查看(https://taobig.org/?p=650)

潜在的漏洞风险,关于安全隐患的问题可查看(http://www.laruence.com/2010/05/20/1495.html)

安装更多扩展:
目前只安装了部分 PHP 拓展,更多扩展可见:

1
yum search php73

更新 PHP:

1
yum update #更新可更新的所有软件,包括PHP

参考:https://linuxize.com/post/install-php-7-on-centos-7/

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×