CentOS 8.1下搭建LEMP(Linux Nginx MySQL PHP)环境(教程详解)

发布时间:2023-11-21 点击:99
服务器
lemp是一个软件堆栈,包含一组免费的开源工具,这些工具用于为高流量和动态网站提供动力。 lemp是linux,nginx(发音为engine x),mariadb/mysql和php的首字母缩写。
nginx是一款开源,强大且高性能的web服务器,它还可以兼作反向代理。 mariadb是用于存储用户数据的数据库系统,而php是用于开发和支持动态网页的服务器端脚本语言。
相关:
centos 8.1下搭建lamp(linux apache mysql php)环境 https://www.linuxidc.com/linux/2020-02/162446.htm
在本文中,您将学习如何在centos 8 linux发行版上安装lemp服务器。
步骤1:在centos 8上更新软件包
首先,通过运行以下dnf命令在centos 8 linux上更新存储库和软件包。
[linuxidc@localhost ~/www.linuxidc.com]$sudo dnf update
更新centos 8软件包
步骤2:在centos 8上安装nginx web服务器
软件包更新完成后,使用简单命令安装nginx。
[linuxidc@localhost ~/www.linuxidc.com]$sudo dnf install nginx
在centos 8上安装nginx
该代码段显示nginx安装工作进展顺利,没有出现任何问题。
在centos 8上安装nginx
安装完成后,将nginx配置为在系统启动时自启动,并通过执行命令来验证nginx是否正在运行。
[linuxidc@localhost ~/www.linuxidc.com]$sudo systemctl enable nginx[linuxidc@localhost ~/www.linuxidc.com]$sudo systemctl start nginx
将nginx配置为在系统启动时自启动
[linuxidc@localhost ~/www.linuxidc.com]$sudo systemctl status nginx
验证nginx服务状态
要检查已安装的nginx版本,请运行命令。
[linuxidc@localhost ~/www.linuxidc.com]$nginx -vnginx version: nginx/1.14.1
检查nginx版本
如果您对nginx感到好奇,并且希望挖掘更多关于nginx的信息,请执行以下rpm命令。
[linuxidc@localhost ~/www.linuxidc.com]$rpm -qi nginx
查看nginx详细信息
要确认nginx服务器正在使用浏览器运行,只需在url栏中键入系统的ip地址或者网址(本文以https://www.linuxidc.com为例,如下图),然后按enter。
您应该能够看到“welcome to nginx onred hat enterprise linux!”网页,这表明您的nginx web服务器已启动并正在运行。
检查nginx网页
步骤3:在centos 8上安装mariadb
mariadb是mysql的免费开源分支,并提供了最新功能,这些功能使其可以更好地替代mysql。 要安装mariadb,请运行命令。
在centos 8中安装mariadb
要使mariadb在系统启动时自动启动,请运行。
[linuxidc@localhost ~/www.linuxidc.com]$systemctl start mariadb
[linuxidc@localhost ~/www.linuxidc.com]$systemctl enable mariadb
created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
mariadb在系统启动时自动启动
安装后,请使用以下命令检查其状态。
验证mariadb服务状态
mariadb数据库引擎不安全,任何人都可以在没有凭据的情况下登录。 要加固mariadb并对其进行保护以最大程度地减少未经授权的访问的机会,请运行命令。
[linuxidc@localhost ~/www.linuxidc.com]$mysql_secure_installation
note: running all parts of this script is recommended for all mariadb
servers in production use! please read each step carefully!
in order to log into mariadb to secure it, we\\\’ll need the current
password for the root user. if you\\\’ve just installed mariadb, and
you haven\\\’t set the root password yet, the password will be blank,
so you should just press enter here.
enter current password for root (enter for none):
系统将提示您输入root密码(如果您已经有root密码)或进行设置。在随后的每个提示中回答y。
设置密码后,回答其余问题以删除匿名用户,删除测试数据库并禁用远程root登录。
完成所有步骤后,您可以登录mariadb服务器并检查mariadb服务器版本信息(提供保护服务器时指定的密码)。
[linuxidc@localhost ~/www.linuxidc.com]$mysql -u root -p
enter
welcome to the mariadb monitor. commands end with ; or \\\\g.
your mariadb connection id is 8
server version: 10.3.17-mariadb mariadb server
copyright (c) 2000, 2018,oracle, mariadb corporation ab and others.
type \\\’help;\\\’ or \\\’\\\\h\\\’ for help. type \\\’\\\\c\\\’ to clear the current input statement.
mariadb [(none)]>
检查mariadb版本
步骤4:在centos 8上安装php 7
最后,我们将安装最后一个lemp组件组件,即php,这是一种脚本化web编程语言,通常用于开发动态网页。
在撰写本指南时,最新版本是php 7.4。 我们将使用remi存储库安装它。 remi资料库是一个免费的资料库,附带了最新的尖端软件版本,默认情况下在centos上不可用。
运行以下命令以安装epel存储库。
[linuxidc@localhost ~/www.linuxidc.com]$sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
接下来,安装yum utils并使用以下命令启用remi-repository。
[linuxidc@localhost ~/www.linuxidc.com]$sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm
成功安装yum-utils和remi-packages之后,通过运行命令搜索可下载的php模块。
[linuxidc@localhost ~/www.linuxidc.com]$sudo dnf module list php输出将包括可用的php模块,流和安装配置文件,如下所示。
extra packages for enterprise linux 8 – x8

选购云服务器需要考虑哪些因素
apache 下实现防盗链
网易有道的短视频试水:佛系入场,适者生存
服务器的流量是什么
如何访问云服务器网站
取消接入中-备案平台
我想问一下诺亚恒业和尚行文化这两个要备案的话上面的个表格应该
阿里云服务器的镜像还原