PHP团队已经发布了升级版本7.2。与 5.X 版本相比,它有许多变化和改进。本文将帮助您在 CentOS/RHEL 7 & 6 操作系统上安装 PHP 7 Apache 2.4 和 MySQL 5.6。本教程已在CentOS 7.4上进行测试,因此所有服务命令均与systemctl一起使用。 CentOS 6 用户全部改变系统控制命令对应关系service命令。
推荐文章:
适用于 Linux 的 LAMP 堆栈 (Apache-MySQL-PHP) 的 15 个最佳安全提示
第 1 步 – 设置 Yum 存储库
第一步,在系统中安装所有必需的 yum 存储库,这些存储库将在剩余教程中用于各种安装。您正在系统中添加 REMI、EPEL、Webtatic 和 MySQL 社区服务器存储库。
CentOS/RHEL 7
yum install epel-release
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
rpm -Uvh http://repo.mysql.com/mysql-community-release-el7-7.noarch.rpm
CentOS/RHEL 6
yum install epel-release
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
rpm -Uvh http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
步骤 2 – 安装 PHP 7.2
现在使用以下命令从 webtatic rpm 存储库安装 php 7 软件包。
yum --enablerepo=remi-php72 install php
现在安装所需的 php 模块。使用以下命令列出 yum 存储库中的可用模块。
yum --enablerepo=remi-php72 search php
现在检查上面命令中列出的所有模块并安装所需的模块,如下所示。
yum --enablerepo=remi-php72 install php-mysql php-xml \
php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
步骤 3 – 安装 Apache 2.4
Apache (HTTPD) 是 Linux 系统上最流行的 Web 服务器。让我们使用以下命令安装 Apache Web 服务器并启用 epel 和 remi yum 存储库。
yum --enablerepo=epel,remi install httpd
现在启动 httpd 服务并使用以下命令在启动时启动。
systemctl start httpd.service
systemctl enable httpd.service
步骤 4 – 安装 MySQL 5.6
在步骤 1 中,我们已经在您的系统中安装了所需的 yum 存储库。让我们使用以下命令在您的系统上安装 MySQL 服务器。如果你想安装MySQL 5.7访问本教程.
yum install mysql-server
在 mysql 上应用安全性并设置 root 用户密码。
systemctl start mysqld.service
mysql_secure_installation
现在重新启动 MySQL 服务并启用在系统启动时启动。
systemctl restart mysqld.service
systemctl enable mysqld.service
第 5 步 – 在防火墙中打开端口
最后使用以下命令打开 HTTP (80) 和 https (443) 服务的防火墙端口。
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
第 6 步 – 检查安装的版本
让我们使用以下命令一一检查系统上已安装的软件包版本。
php -v
PHP 7.2.0 (cli) (built: Nov 28 2017 20:22:21) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies
httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: Nov 19 2015 21:43:13
mysql -V
mysql Ver 14.14 Distrib 5.6.28, for Linux (x86_64) using EditLine wrapper
现在您已在 CentOS / RHEL 7.4 和 6.9 系统上成功配置了 LAMP 设置。
推荐文章:
适用于 Linux 的 LAMP 堆栈 (Apache-MySQL-PHP) 的 15 个最佳安全提示