在 CentOS 8 上安装 LNMP 环境

前言

众所周知,安装 LNMP 环境可谓是搭建网站的前提。

没有了它,人类无法生存,地球就要毁灭!

LNMP 环境指的是 Linux, Nginx, MariaDB, PHP。

本文使用 CentOS 8。

安装

Nginx

使用 Nginx 官方资源库进行安装。

安装 yum-utils

sudo dnf install -y dnf-utils

在目录 /etc/yum.repos.d/ 下创建名为 nginx.repo 的文件,并写入以下内容。

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

默认使用 Nginx 稳定包,若需要使用主线包,请执行以下命令

sudo yum-config-manager --enable nginx-mainline

安装 Nginx

sudo dnf install -y nginx

MariaDB

使用 MariaDB 官方资源库进行安装。

在目录 /etc/yum.repos.d/ 下创建名为 MariaDB.repo 的文件,并写入以下内容。

[mariadb]
name = MariaDB
baseurl = https://mirrors.aliyun.com/mariadb/yum/10.8/centos8-amd64
module_hotfixes=1
gpgkey=https://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1

安装 MariaDB

sudo dnf install -y mariadb-server

PHP

安装 EPEL 资源库

sudo dnf config-manager --set-enabled powertools
sudo dnf install epel-release

安装 Remi 资源库

sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm

替换默认的 PHP 安装源,可以将 “8.1” 改为你想安装的其他版本。

dnf module reset php
dnf module enable php:remi-8.1
dnf update php\*

下载 PHP 以及一些必要插件

sudo dnf install -y php php-common php-fpm php-xml php-zip php-pdo php-mysqlnd php-gd php-opcache

运行

运行以上软件并设置开机自启动

sudo systemctl start nginx mariadb php-fpm
sudo systemctl enable nginx mariadb php-fpm

参考

  1. nginx: Linux packages
  2. Download MariaDB Server – MariaDB.org
  3. Extra Packages for Enterprise Linux (EPEL) :: Fedora Docs
  4. English : Repository Configuration – Remi’s RPM repository – Blog

已发布

分类

,

作者:

评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注