zl程序教程

您现在的位置是:首页 >  其他

当前栏目

如何在centos环境中安装php7x ?php-fpm 7 ? php插件?

2023-04-18 15:52:05 时间

如果你需要搭建一个LNMP的环境,来运行你的应用,如何来部署php的环境?

 

通过下面的部分,你将看到在centos 7环境中,部署php环境的过程:

 

1、安装epepl和remi库

yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

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

 

 

可以看到php有很多的版本,每个版本一个repo文件

[root@centos7 ~]# cd /etc/yum.repos.d/
[root@centos7 yum.repos.d]# ls -ltr
total 60
-rw-r--r-- 1 root root 1457 Sep  4  2021 epel-testing.repo
-rw-r--r-- 1 root root 1358 Sep  4  2021 epel.repo
-rw-r--r-- 1 root root 2523 Aug  4  2022 CentOS-Base.repo
-rw-r--r-- 1 root root  750 Jan  5 08:43 remi-safe.repo
-rw-r--r-- 1 root root 2605 Jan  5 08:43 remi.repo
-rw-r--r-- 1 root root 1314 Jan  5 08:43 remi-php82.repo
-rw-r--r-- 1 root root 1314 Jan  5 08:43 remi-php81.repo
-rw-r--r-- 1 root root 1314 Jan  5 08:43 remi-php80.repo
-rw-r--r-- 1 root root 1314 Jan  5 08:43 remi-php74.repo
-rw-r--r-- 1 root root 1314 Jan  5 08:43 remi-php73.repo
-rw-r--r-- 1 root root 1314 Jan  5 08:43 remi-php72.repo
-rw-r--r-- 1 root root 1314 Jan  5 08:43 remi-php71.repo
-rw-r--r-- 1 root root 1314 Jan  5 08:43 remi-php70.repo
-rw-r--r-- 1 root root  456 Jan  5 08:43 remi-php54.repo
-rw-r--r-- 1 root root  855 Jan  5 08:43 remi-modular.repo
[root@centos7 yum.repos.d]# 

 

 

2、安装yum-utils包

 

注意:这个包需要基础的数据源

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

yum install -y yum-utils

 

 

3、安装php和php-fpm、php插件

 

确定要安装的php的版本

# 禁止php54版本
yum-config-manager --disable remi-php54

# 启用php73版本
yum-config-manager --enable remi-php73

 

 

你可以根据你的需要,选择你的版本,只需要

--enable remi-phpxx

 

 

安装软件包

yum -y install php php-fpm php-mysqlnd php-zip php-devel 
  php-gd php-mcrypt php-mbstring php-curl php-xml php-pear 
  php-bcmath php-json php-pdo php-pecl-apcu 
  php-pecl-apcu-devel

 

 

安装完成后,查看php的版本

[root@centos7 yum.repos.d]# php --version
PHP 7.3.33 (cli) (built: Feb 14 2023 14:41:46) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.33, Copyright (c) 1998-2018 Zend Technologies
[root@centos7 yum.repos.d]# 

 

 

正如你看到的,php已经安装完成,版本是7.3版本

 

注意:php-fpm是一个单独的服务,php-gd等都是php的插件