如何在 RHEL、CentOS、Rocky 和 AlmaLinux 上安装 LAMP 堆栈如何在 RHEL、CentOS、Rocky 和 AlmaLinux 上安装 LAMP 堆栈如何在 RHEL、CentOS、Rocky 和 AlmaLinux 上安装 LAMP 堆栈如何在 RHEL、CentOS、Rocky 和 AlmaLinux 上安装 LAMP 堆栈
  • 文章
  • 正则表达式
    • 工具
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容
发表 admin at 2025年2月28日
类别
  • 未分类
标签

如何在 RHEL、CentOS、Rocky 和 AlmaLinux 上安装 LAMP 堆栈

LAMP 堆栈是四种不同软件(Linux、Apache、MySQL 和 PHP)的集合) 程序员或网络开发人员用来创建和部署网站或应用程序。

本教程将重点介绍如何使用 PhpMyAdmin 在 RHEL 和基于 RHEL 的发行版(例如CentOS、Oracle Linux、Rocky 和 AlmaLinux。

要求

根据使用的发行版,使用以下链接执行最小系统安装,使用静态 IP 地址进行网络配置。

  • 如何免费下载和安装 RHEL 9
  • 如何免费下载和安装 RHEL 8
  • 安装 CentOS Stream 9 Linux
  • 安装 CentOS 7 Linux
  • 如何逐步安装 Rocky Linux 9
  • 如何逐步安装 AlmaLinux 9

第 1 步:安装 Apache Web 服务器

1. 在执行最小系统安装并使用 yum 命令配置服务器网络接口之后。

# yum install httpd

2. Apache 安装完成后,由于RHEL 和CentOS 都迁移了它们的init 从 SysV 到 Systemd 的脚本——为什么 Linux 中的 init 被 Systemd 取代了?

# systemctl start httpd
# systemctl enable httpd
# systemctl status httpd

3. 在下一步中,确保使用 firewall-cmd 在防火墙上打开端口 80 和 443 以允许访问 Apache,这是通过守护进程管理 Firewalld 的默认命令。

# firewall-cmd --add-service=http
# firewall-cmd --add-service=https
# systemctl restart firewalld

使用 --permanent 选项在防火墙上应用一致性 iptables 规则并重启 firewalld 服务使其生效。

# firewall-cmd --permanent --add-service=http
# firewall-cmd --permanent --add-service=https
# systemctl restart firewalld

一些重要的 Firewalld 命令用于管理防火墙,如下所示:

# firewall-cmd --state
# firewall-cmd --list-all
# firewall-cmd --list-interfaces
# firewall-cmd --get-service
# firewall-cmd --query-service service_name
# firewall-cmd --add-port=80/tcp

4. 要验证 Apache 功能,请打开远程浏览器并在 URL 上使用 HTTP 协议键入您的服务器 IP 地址,然后应显示默认页面就像下面的截图一样。

http://server_IP

5. 目前,Apache DocumentRoot 路径设置为 /var/www/html 系统路径,默认情况下不提供任何索引文件。如果您想查看您的 DocumentRoot 路径的目录列表。

打开 Apache welcome 配置文件,在 LocationMatchIndexes 语句从 – 设置为 + 指令,以下面的屏幕截图为例。

# vi /etc/httpd/conf.d/welcome.conf

6. 进行更改后,关闭文件,重新启动 Apache 服务以反映更改,然后重新加载浏览器页面以查看最终结果。

# systemctl restart httpd

第 2 步:为 Apache 安装 PHP 支持

7. 在为 Apache 安装 PHP 动态语言支持之前,使用以下命令获取可用 PHP 模块和扩展的完整列表。

# yum search php

8. 根据您要使用的应用程序类型,从上面的列表中安装所需的 PHP 模块,但对于基本的 MySQL/MariaDB 支持 PHP 和 PhpMyAdmin 您需要安装以下模块。

# yum install php php-mysql php-pdo php-gd php-mbstring

9. 要从浏览器获取有关 PHP 的完整信息列表,请使用以下命令在 Apache Document Root 上创建一个 info.php 文件,重新启动 httpd 服务,并将浏览器定向到 http://server_IP/info.php 地址。

# echo "<?php phpinfo(); ?>" > /var/www/html/info.php
# systemctl restart httpd

10. 如果您在 PHP 日期和时区方面遇到错误,请打开 php.ini 配置文件,搜索并取消注释 date.timezone 语句,附加您的物理位置,然后重新启动 Apache 守护程序。

# vi /etc/php.ini

使用 PHP 支持的时区列表找到并更改 date.timezone 行,使其看起来像这样。

date.timezone = Continent/City

第 3 步:安装和配置 MariaDB 数据库

11. RHEL 发行版的默认数据库管理系统从 MySQL 切换到 MariaDB。要安装 MariaDB 数据库,请使用以下命令。

# yum install mariadb-server mariadb

12. 安装MariaDB包后,启动数据库守护进程并使用mysql_secure_installation脚本来保护数据库(设置root密码,禁用从 root 远程登录,删除测试数据库,并删除匿名用户)。

# systemctl start mariadb
# systemctl enable mariadb
# systemctl status mariadb
# mysql_secure_installation

13. 要测试数据库功能,请使用其根帐户登录到 MariaDB,然后使用 quit 语句退出。

mysql -u root -p
MariaDB > show databases;
MariaDB > quit

第 4 步:安装 PhpMyAdmin 来管理 MySQL

14. 默认情况下,官方存储库不为 PhpMyAdmin Web 界面提供任何二进制包。如果您不习惯使用 MySQL 命令行来管理您的数据库,您可以通过使用以下命令启用 remi 存储库来安装 PhpMyAdmin 包。

# yum install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm  [On CentOS/RHEL 8]
# yum install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm  [On CentOS/RHEL 8]
# yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm  [On CentOS/RHEL 7]

启用remi 存储库后,接下来安装PhpMyAdmin。

# yum install phpmyadmin

15. 接下来通过编辑位于 Apache conf.d< 上的 phpmyadmin.conf 文件配置 PhpMyAdmin 以允许来自远程主机的连接/b> 目录,注释以下行。

# vi /etc/httpd/conf.d/phpMyAdmin.conf

如图所示,在“Require local”行下添加“Require all granted”行。

<Directory /usr/share/phpMyAdmin/>
   AddDefaultCharset UTF-8
   Require local
   Require all granted
</Directory>

16. 为了能够登录到PhpMyAdmin Web 界面,重新启动Apache Web 服务并将浏览器定向到URL 地址。

# systemctl restart httpd

http://server_IP/phpmyadmin/

第 5 步:在 Linux 中启用 LAMP 系统范围

17. 如果您需要在重新启动后自动启动 MariaDB 和 Apache 服务,请发出以下命令以在系统范围内启用它们。

# systemctl enable mariadb
# systemctl enable httpd

这就是在基于 RHEL 的发行版上安装基本 LAMP 所需的全部。下一个与 LAMP 堆栈相关的系列文章将讨论如何创建虚拟主机、生成 SSL 证书和密钥,以及为 Apache HTTP 服务器添加 SSL 事务支持。

©2015-2025 艾丽卡 support@alaica.com