CentOS 8.2 搭建当前最新版本 LNMP 环境(Linux+Nginx+MariaDB+PHP)

概览

最近有些服务需要测试,想起近几年来腾讯云服务器还一直会有些优惠活动,所以就从腾讯云买了一台轻量应用服务器,系统选择搭载 CentOS 8.2 x64,以下即是在该基础上搭建 LNMP 环境的备忘录,方便自己后续以及有需要的同学用以参考。

更新系统

配置前先更新系统:yum update

yum update

安装 Nginx 服务

根据 Nginx 官网的配置手册,CentOS 的 “安装先决条件” 配置如下:

1. 安装 utils;

yum install yum-utils

2. 设置 yum 存储库;

切换到以下目录:

cd /etc/yum.repos.d

创建 nginx.repo 文件:

vi nginx.repo

并在 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

3. 执行安装 Nginx 命令;

yum install nginx
Invalid configuration value: failovermethod=priority in /etc/yum.repos.d/CentOS-Epel.repo; Configuration: OptionBinding with id "failovermethod" does not exist
nginx stable repo                                                                    36 kB/s |  35 kB     00:00    
Dependencies resolved.
====================================================================================================================
 Package               Architecture           Version                            Repository                    Size
====================================================================================================================
Installing:
 nginx                 x86_64                 1:1.20.2-1.el8.ngx                 nginx-stable                 820 k

Transaction Summary
====================================================================================================================
Install  1 Package

Total download size: 820 k
Installed size: 2.8 M
Is this ok [y/N]: y
Downloading Packages:
nginx-1.20.2-1.el8.ngx.x86_64.rpm                                                   143 kB/s | 820 kB     00:05    
--------------------------------------------------------------------------------------------------------------------
Total                                                                               143 kB/s | 820 kB     00:05     
nginx stable repo                                                                   2.2 kB/s | 1.5 kB     00:00    
Importing GPG key 0x7BD9BF62:
 Userid     : "nginx signing key <signing-key@nginx.com>"
 Fingerprint: 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62
 From       : https://nginx.org/keys/nginx_signing.key
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                            1/1 
  Running scriptlet: nginx-1:1.20.2-1.el8.ngx.x86_64                                                            1/1 
  Installing       : nginx-1:1.20.2-1.el8.ngx.x86_64                                                            1/1 
  Running scriptlet: nginx-1:1.20.2-1.el8.ngx.x86_64                                                            1/1 
----------------------------------------------------------------------

Thanks for using nginx!

Please find the official documentation for nginx here:
* https://nginx.org/en/docs/

Please subscribe to nginx-announce mailing list to get
the most important news about nginx:
* https://nginx.org/en/support.html

Commercial subscriptions for nginx are available on:
* https://nginx.com/products/

----------------------------------------------------------------------

  Verifying        : nginx-1:1.20.2-1.el8.ngx.x86_64                                                            1/1 

Installed:
  nginx-1:1.20.2-1.el8.ngx.x86_64                                                                                   

Complete!

4. 启动 Nginx 服务;

service nginx start
Redirecting to /bin/systemctl start nginx.service

5.Nginx 的 WEB 服务文件在以下路径:

pwd
/usr/share/nginx/html

6. 访问服务器的 IP 或绑定的域名即可打开 Nginx 的欢迎页面;

Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

7. 配置 Nginx 开机启动;

查询当前配置状态:

当前开机启动状态为禁用

systemctl list-unit-files | grep nginx
nginx-debug.service                         disabled       
nginx.service                               disabled   

设置 Nginx 及相关服务为开机启动:

systemctl enable nginx nginx-debug
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
Created symlink /etc/systemd/system/multi-user.target.wants/nginx-debug.service → /usr/lib/systemd/system/nginx-debug.service.

确认开启状态:

当前开机启动状态为启用

systemctl list-unit-files | grep nginx
nginx-debug.service                         enabled        
nginx.service                               enabled  

待更新中 …

0 条评论

昵称

沙发空缺中,还不快抢~