余晖落尽暮晚霞,黄昏迟暮远山寻
本站
当前位置:网站首页 > 编程知识 > 正文

CentOS 8 安裝LNMP

xiyangw 2023-10-11 17:09 25 浏览 0 评论

运行环境

操作系统:CentOS 8
软件版本:PHP7.3、MariaDB10.4、Nginx1.17

开始安裝

1. 安装Nginx

在CentOS 8 本身预设版本是 1.14,那Nginx 官方版本稳定版目前是 1.16,如不想使用预设版本想要使用官方采用的版请参考本次安裝流程。

到 Nginx 官方网站参考目前如何新增來源库

先安裝可以选择指定的 yum 的套件

# dnf install dnf-utils -y

新增#vim /etc/yum.repos.d/nginx.repo 官方所提供的来源库

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

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

指定所要安裝的版本,目前官方有兩个版本可以选择,一個是(nginx-stable)稳定版另一个是(nginx-mainline)开发版,正常我都是安裝稳定版本。

# yum-config-manager --enable nginx-nginx-stable

安裝Nginx服务,如果想要安裝自行新增的来源库的话,要下這一段指令才能安裝,不然會安裝到預設的安裝檔 --disablerepo=AppStream

# dnf install nginx --disablerepo=AppStream -y

配置Nginx

 location ~ \.php$ {         
   root   /usr/share/nginx/html;         
   fastcgi_pass unix:/run/php-fpm/www.sock;         
   fastcgi_index index.php;         
   try_files $uri =404;         
   fastcgi_param SCRIPT_FILENAME  
   $document_root$fastcgi_script_name;         
   include fastcgi_params;     
 }

启动服务

#systemctl start nginx ; systemctl enable nginx

2. 安装MariaDB

CentOS8现在预设是用MariaDB 10.3版本,想使用MariaDB 10.4版本可以利用新增来源库来安装。

新增加官方来源库MariaDB
vim /etc/yum.repos.d/MariaDB.repo

# MariaDB 10.4 CentOS repository list - created 2019-11-05 05:10 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos8-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
#dnf install boost-program-options -y
#dnf install MariaDB-server MariaDB-client --disablerepo=AppStream -y

启动MariaDB服务

#systemctl enable mariadb && systemctl start mariadb

MariaDB初始化

#mysql_secure_installation   #设定资料库的root密码 
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 
haven't set the root password yet, you should just press enter here. 
Enter current password for root (enter for none): 
OK, successfully used password, 
moving on... Setting the root password or using the unix_socket ensures that nobody 
can log into the MariaDB root user without the proper authorisation. 
You already have your root account protected, 
so you can safely answer 'n'. 
Switch to unix_socket authentication [Y/n] 
Enabled successfully! 
Reloading privilege tables..  ... Success! 
You already have your root account protected, so you can safely answer 'n'. 
Change the root password? [Y/n] New password:                      # 设置root的密码28Re-enter new password:             
# 确认root的密码 
Password updated successfully! 
Reloading privilege tables..  ... Success! 
By default, a MariaDB installation has an anonymous user, allowing anyone 
to log into MariaDB without having to have a user account created for them.  
This is intended only for testing, and to make the installation go a 
bit smoother.  
You should remove them before moving into a production environment. 
Remove anonymous users? [Y/n]  
... Success! 
Normally, root should only be allowed to connect from 'localhost'.  
This ensures that someone cannot guess at the root password from the 
network. Disallow root login remotely? [Y/n]  
... Success! 
By default, MariaDB comes with a database named 'test' that anyone can access.
This is also intended only for testing, and should be removed before moving 
into a production environment. 
Remove test database and access to it? [Y/n]  
  - Dropping test database...  ... Success!  
  - Removing privileges on test database...  
... Success! 
Reloading the privilege tables will ensure that all changes made 
so far will take effect immediately. 
Reload privilege tables now? [Y/n]  
... Success! Cleaning up... All done!  
If you've completed all of the above steps, your MariaDB installation 
should now be secure. Thanks for using MariaDB!

重启maridb服务
#systemctl restart mariadb

3.安装PHP7.3

CentOS8预设版本是PHP7.2版,那如果想要使用比较新的版本的话需要新增加来源库安装

安装 epel-release 套件服务
#dnf install -y epel-release

安裝官方所提供来源库版本
dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y

查询目前可安裝的版本
#dnf module list php
执行结果如下

使用PHP7.3版本

#dnf module reset php`#dnf module enable php:remi-7.3

使用PHP7.4版本

#dnf module reset php#dnf module enable php:remi-7.4

安裝PHP

#dnf install -y php php-mysqlnd php-pdo php-xml php-pear php-mbstring php-fpm php-mysql php-gd php-cli \php-json php-opcache php-curl php-ldap php-odbc php-xmlrpc php-soap php-intl php-zip curl curl-devel \gcc-c++ gcc php-tidy

配置php.ini
vim /etc/php.ini

[Date]
修改前;date.timezone = 
修改后date.timezone = Asia/Taipei
保存退出
:wq

配置php-fpm

vim /etc/php-fpm.d/www.conf

; RPM: apache user chosen to provide access to the same directories as httpd 
;user = apache 
user = nginx ; 
RPM: Keep a group allowed to write in log dir. 
;group = apache 
group =nginx 
保存退出
:wq

启动服务
#systemctl restart php-fpm ; systemctl enable php-fpm

测试

测试 PHP 是否能够正在运行,在 web 服务目录新增 info.php 档

<?php  phpinfo();?>

执行结果如下

相关推荐

华为交换机配置命令总结

1、配置文件相关命令[Quidway]displaycurrent-configuration显示当前生效的配置[Quidway]displaysaved-configuration显示fla...

解决账户无法登录的故障
解决账户无法登录的故障

在优化系统时错误地根据网上的提示,将唯一的Administrator账户设置为禁用,导致重启后无法进入系统。类似的故障还有使用组策略限制本地账户登录,导致重启后...

2023-10-11 17:16 xiyangw

S5720交换机登录提示初始密码存在安全风险
S5720交换机登录提示初始密码存在安全风险

问题描述客户每次登录输密码时,提示初始密码不安全,现在客户嫌麻烦想要去掉:Username:huaweiPassword:Warning:Theinitia...

2023-10-11 17:15 xiyangw

Springboot,Mybatis修改登录用户的密码
Springboot,Mybatis修改登录用户的密码

一、Mybatis.xml<updateid="changePassword"parameterType="string...

2023-10-11 17:15 xiyangw

PHP理论知识之沐浴更衣重看PHP基础(二)
PHP理论知识之沐浴更衣重看PHP基础(二)

接上篇,咱们继续讲解PHP基础八、标准PHP组件和框架的数量很多,随之产生的问题就是:单独开发的框架没有考虑到与其他框架的通信。这样对开发者和框架本身都是不利的...

2023-10-11 17:15 xiyangw

新鲜出炉UCloud云主机“数据方舟”评测报告(5)— — 关其城
新鲜出炉UCloud云主机“数据方舟”评测报告(5)— — 关其城

2015年10月29日,UCloud云主机黑科技——“数据方舟”功能正式上线,首轮内测随即开放。截止至2015年12月6日,我们共收到了534位用户的评测申...

2023-10-11 17:14 xiyangw

业余无线电Q简语及英文缩语
业余无线电Q简语及英文缩语

Q简语:语音通信及CW通信通用(加粗为常用)QRA电台何台QRB电台间之距离QRG告之正确频率QRH频率是否变动QRI发送音调QRJ能否收到QRK信号之可...

2023-10-11 17:14 xiyangw

非常详细!如何理解表格存储的多版本、生命周期和有效版本偏差
非常详细!如何理解表格存储的多版本、生命周期和有效版本偏差

表格存储在8月份推出了容量型实例,直接支持了表级别最大版本号和生命周期,高性能实例也将会在9月中旬支持这两个特性。那么,最大版本号和生命周期以及特有的...

2023-10-11 17:14 xiyangw

H3C交换机恢复出厂和各种基本配置,这20个要点你知道吗?
H3C交换机恢复出厂和各种基本配置,这20个要点你知道吗?

私信“干货”二字,即可领取138G伺服与机器人专属及电控资料!H3C交换机不知道密码如何恢复出厂设置1、开机启动,Ctrl+B进入bootrom菜单,选择恢复出...

2023-10-11 17:13 xiyangw

在使用移动支付系统的时候如何保护信息安全?

移动支付的方式近年来不断被更新,使得Venmo(据嘉丰瑞德理财师了解,此为美国的“支付宝”)之类的支付方式已经可以某种意义上代替随身携带现金了。但是你必须防范那些第三方应用程序轻松地获取你的银行卡以及...

界面控件DevExpress WinForms MVVM入门指南——登录表单(下)

从本文档中,您将了解如何向应用程序添加登录表单。在本节教程中着重讨论了如何实现此任务,这基本上是附加应用程序功能的一部分。DevExpressUniversalSubscription官方最新版免...

linux基础命令(一)
linux基础命令(一)

为啥要学linux?您可能熟悉WindowsXP、Windows7、Windows10和MacOSX等操作系统。Linux就是这样一种强大的操...

2023-10-11 17:13 xiyangw

MySQL数据库密码忘记了,怎么办?

#头条创作挑战赛#MySQL数据库密码忘记了且没有其他可以修改账号密码的账户时怎么办呢?登录MySQL,密码输入错误/*密码错误,报如下错误*/[root@TESTDB~]#mysql-u...

MobaXterm忘记Session密码,如何查看已保存的密码
MobaXterm忘记Session密码,如何查看已保存的密码

MobaXterm工具登录过SSH终端后,如果存储了Session(存储后再连接ssh的时候只需要输入账号不需要输入密码就可以直接连接上ssh),则可以...

2023-10-11 17:12 xiyangw

华为交换机密码丢失修改方法
华为交换机密码丢失修改方法

华为S2300交换机找回密码设置一、目的交换机的console和telnet密码丢失,无法登录设备。交换机已进行过数据配置,要把密码恢复而数据配置不能丢失。二、...

2023-10-11 17:12 xiyangw

取消回复欢迎 发表评论: