> Linux发行版 > Fedora >

如何在 Fedora 30 Server 上安装 LEMP(Linux、Nginx、MariaDB、PHP)

在这篇文章中,我们将看看如何在 Fedora 30 Server 上安装 LEMP 。LEMP 代表:

  • L -> Linux
  • E -> Nginx
  • M -> Maria DB
  • P -> PHP

我假设 Fedora 30 已经安装在你的电脑系统上。

LEMP 是一组强大的软件设置集合,它安装在一个 Linux 服务器上以帮助使用流行的开发平台来构建网站,LEMP 是 LAMP 的一个变种,在其中不是 Apache ,而是使用 EngineX(Nginx),此外,使用 MariaDB 代替 MySQL。这篇入门指南是一个安装 Nginx、Maria DB 和 PHP 的独立指南的作品集合。

在 Fedora 30 Server 上安装 Nginx、PHP 7.3 和 PHP-FPM

让我们看看如何在 Fedora 30 Server 上安装 Nginx 和 PHP 以及 PHP FPM。

步骤 1) 切换到 root 用户

在系统上安装 Nginx 的第一步是切换到 root 用户。使用下面的命令:


  1. root@linuxtechi ~]$ sudo -i
  2. [sudo] password for pkumar:
  3. [root@linuxtechi ~]#

步骤 2) 使用 dnf 命令安装 Nginx、PHP 7.3 和 PHP FPM

使用下面的 dnf 命令安装 Nginx:


  1. [root@linuxtechi ~]# dnf install nginx php php-fpm php-common -y

步骤 3) 安装额外的 PHP 模块

PHP 的默认安装仅自带基本模块和最需要的模块,如果你需要额外的模块,像 PHP 支持的 GD、XML、命令行接口、Zend OPCache 功能等等,你总是能够选择你的软件包,并一次性安装所有的东西。查看下面的示例命令:


  1. [root@linuxtechi ~]# sudo dnf install php-opcache php-pecl-apcu php-cli php-pear php-pdo php-pecl-mongodb php-pecl-redis php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml -y

步骤 4) 开始 & 启用 Nginx 和 PHP-fpm 服务

使用下面的命令来开始并启用 Nginx 服务:


  1. [root@linuxtechi ~]# systemctl start nginx && systemctl enable nginx
  2. Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
  3. [root@linuxtechi ~]#

使用下面的命令来开始并启用 PHP-FPM 服务:


  1. [root@linuxtechi ~]# systemctl start php-fpm && systemctl enable php-fpm
  2. Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
  3. [root@linuxtechi ~]#

步骤 5) 核实 Nginx (Web 服务) 和 PHP 安装

注意:假使操作系统防火墙是启用的,并运行在你的 Fedora 30 系统上,那么使用下面的命令来准许 80 和 443 端口:


  1. [root@linuxtechi ~]# firewall-cmd --permanent --add-service=http
  2. success
  3. [root@linuxtechi ~]#
  4. [root@linuxtechi ~]# firewall-cmd --permanent --add-service=https
  5. success
  6. [root@linuxtechi ~]# firewall-cmd --reload
  7. success
  8. [root@linuxtechi ~]#

打开网页浏览器,输入下面的 URL: http:// 。

Test-Page-HTTP-Server-Fedora-30

Test-Page-HTTP-Server-Fedora-30

上面的屏幕证实 Nginx 已经成功地安装。

现在,让我们核实 PHP 安装,使用下面的命令创建一个测试 php 页(info.php):


  1. [root@linuxtechi ~]# echo "<?php phpinfo(); ?>" > /usr/share/nginx/html/info.php
  2. [root@linuxtechi ~]#

在网页浏览器中输入下面的 URL, http:///info.php

Php-info-page-fedora30

Php-info-page-fedora30

上面的页面验证 PHP 7.3.5 已经被成功地安装。现在,让我们安装 MariaDB 数据库服务器。

在 Fedora 30 上安装 MariaDB

MariaDB 是 MySQL 数据库的一个极好的替代品,因为它的工作方式与 MySQL 非常类似,并且兼容性也与 MySQL 一致。让我们看看在 Fedora 30 Server 上安装 MariaDB 的步骤。

步骤 1) 切换到 root 用户

在系统上安装 MariaDB 的第一步是切换到 root 用户,或者你可以使用有 root 权限的本地用户。使用下面的命令:


  1. [root@linuxtechi ~]# sudo -i
  2. [root@linuxtechi ~]#

步骤 2) 使用 dnf 命令安装 MariaDB(10.3)的最新版本

在 Fedora 30 Server 上使用下面的命令来安装 MariaDB:


  1. [root@linuxtechi ~]# dnf install mariadb-server -y

步骤 3) 开启并启用 MariaDB 服务

在步骤 2 中成功地安装 MariaDB 后,接下来的步骤是开启 MariaDB 服务。使用下面的命令:


  1. [root@linuxtechi ~]# systemctl start mariadb.service ; systemctl enable mariadb.service

步骤 4) 保护安装好的 MariaDB

当我们安装 MariaDB 服务器时,因为默认情况下没有 root 密码,在数据库中也会创建匿名用户。因此,要保护安装好的 MariaDB,运行下面的 mysql_secure_installation 命令:


  1. [root@linuxtechi ~]# mysql_secure_installation

接下来你将被提示一些问题,仅回答下面展示的问题:

Secure-MariaDB-Installation-Part1

Secure-MariaDB-Installation-Part1

Secure-MariaDB-Installation-Part2

Secure-MariaDB-Installation-Part2

步骤 5) 测试 MariaDB 安装

在你安装后,你总是能够测试是否 MariaDB 被成功地安装在 Fedora 30 Server 上。使用下面的命令:


  1. [root@linuxtechi ~]# mysql -u root -p
  2. Enter password:

接下来,你将被提示一个密码。输入在保护安装好的 MariaDB 期间你设置的密码,接下来你可以看到 MariaDB 欢迎屏幕。


  1. Welcome to the MariaDB monitor. Commands end with ; or \g.
  2. Your MariaDB connection id is 17
  3. Server version: 10.3.12-MariaDB MariaDB Server
  4.  
  5. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
  6.  
  7. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  8.  
  9. MariaDB [(none)]>

最后,我们已经在你的 Fedora 30 Server 上成功地完成安装 LEMP(Linux、Nginx、MariaDB 和 PHP)的所有工作。请在下面的反馈部分发布你的评论和建议,我们将尽快在后面回应。

via: https://www.linuxtechi.com/install-lemp-stack-fedora-30-server/



(责任编辑:IT)