PHP 安装

这里用的centos8.5 

1 首先更新centos

dnf -y install centos-release-stream
dnf -y swap centos-{linux,stream}-repos
dnf -y distro-sync
2 添加源
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-8.rpm

这里没有更新centos会提示如下信息:

- nothing provides (redhat-release >= 8.9 or centos-stream-release >= 8) needed by remi-release-8.9-3.el8.remi.noarch

这里操作步骤1即可解决问题。

3. 安装更新

dnf -y install dnf-utils
这个更新速度非常慢,需要耐心等待。

4 查看php相关模块

yum search php74* 
5. 然后开始安装php7.4
yum install -y php74 php74-php-devel  php74-php-fpm  php74-php-mbstring php74-php-memcache php74-php-memcached php74-php-redis  php74-php-mysqlnd  php74-php-pdo  php74-php-bcmath php74-php-xml php74-php-gd php74-php-gmp php74-php-igbinary php74-php-imagick   php74-php-mcrypt  php74-php-pdo_mysql php74-php-posix php74-php-simplexml  php74-php-opcache php74-php-xsl php74-php-xmlwriter php74-php-xmlreader php74-php-swoole php74-php-zip php74-php-phalcon  php74-php-yaml php74-php-yar php74-php-yaf php74-php-uuid 

可以使用命令按需安装模块 yum install php74-xxx

6 添加自启动

#重启命令php-fpm
systemctl restart php74-php-fpm
#添加自动启动
systemctl enable php74-php-fpm
7 查看php路径
whereis php 

该命令可能搜索不到,需要 用find命令查找

find / -name php

Centos 8 安装php7.4

8 链接php文件

根据上面的查找的路径创建软连接

ln -s /opt/remi/php74/root/usr/bin/php /usr/bin/php

报错:ls: cannot access '/usr/bin/php': No such file or directory

那创建硬链接

ln -s /opt/remi/php74/root/usr/bin/php /usr/bin/php 
9 查看php版本

php -version

Centos 8 安装php7.4