CentOS7搭建LNMP环境教程

一、安装nginx

创建 nginx.repo 文件

vi /etc/yum.repos.d/nginx.repo
敲击 i进入编辑模式,输入以下内容

[nginx]
name = nginx repo 
baseurl = https://nginx.org/packages/mainline/centos/7/$basearch/ 
gpgcheck = 0
enabled = 1

按ESC  输入:wq保存并退出。

安装配置nginx

yum install -y nginx 

进入 conf.d文件夹修改配置文件
cd /etc/nginx/conf.d 

备份默认文件
cp default.conf default.bak 

编辑配置文件
vi default.conf

配置文件详解

server {                         #服务器请求
listen       80;                     
 root   /usr/share/nginx/html;       #根目录
 server_name  www.123.com;            #域名
 #charset koi8-r;
 #access_log  /var/log/nginx/log/host.access.log  main;
 #
 location / {                         #默认页面
       index index.php index.html index.htm;    
 }
 #error_page  404              /404.html;
 #redirect server error pages to the static page /50x.html
 #
 error_page   500 502 503 504 /50x.html;
 location = /50x.html {                  #错误页面
   root   /usr/share/nginx/html;
 }
 #pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
 #
 location ~ .php$ {                    #匹配以.php结尾的访问请求
   fastcgi_pass   127.0.0.1:9000;      #传递给PHP-FPM处理
   fastcgi_index  index.php;
   fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
   include        fastcgi_params;
 }
}

启动并验证

systemctl start nginx      #启动nginx
systemctl enable nginx     #设置开机启动

防火墙开放端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
重载防火墙设置
firewall-cmd --reload

http://你的域名       #验证能否登录
CentOS7搭建LNMP环境教程

二、安装MariaDB

安装mariadb

查看系统是否已经安装过MariaDB
rpm -qa | grep -i mariadb

如果有需先移除
rpm -e 包名

yum安装
yum install mariadb -y

启动MariaDB
systemctl start mariadb
systemctl enable mariadb

使用Mysql需先初始化密码

三、安装PHP

更新yum源

rpm -Uvh https://mirrors.cloud.tencent.com/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

执行下面的命令安装所需的包

yum -y install mod_php72w.x86_64 php72w-cli.x86_64 php72w-common.x86_64 php72w-mysqlnd php72w-fpm.x86_64 

启动php-fpm

systemctl start php-fpm
systemctl enable php-fpm

创建测试文件

echo "<?php phpinfo(); ?>" >> /usr/share/nginx/html/index.php 

访问服务器,如果出现如下界面表示安装完成!

CentOS7搭建LNMP环境教程

这样Lnmp环境就快速搭建完成了!!!

文章来源:https://www.cnaaa.net,转载请注明出处:https://www.cnaaa.net/archives/6082

(0)
郭靖的头像郭靖
上一篇 2022年11月15日 上午10:52
下一篇 2022年11月15日 下午5:50

相关推荐

  • 解析Vue中的虚拟DOM与Diff算法:提升性能的利器

    前言 vue中的diff算法时常是面试过程中的考点,本文将为大家讲解何为diff以及diff算法的实现过程。那么在了解diff之前,我们需要先了解虚拟DOM是什么? 虚拟DOM 虚拟 DOM (Virtual DOM,简称 VDOM) 是一种编程概念,意为将目标所需的 UI 通过数据结构“虚拟”地表示出来,保存在内存中,然后将真实的DOM与之保持同步。具体来…

    2024年3月22日
    1.3K00
  • redis 集群 CLUSTERDOWN Hash slot not served 报错解决思路

    背景:  因机房故障,导致redis-cluster 集群中 有个节点 down 了 ,再从新拉起节点加入集群后,就没在意 过来小许,服务器磁盘告警来了,我看了下 应用服务器上的tomcat 的日志,不停的刷,日志内容 报redis 错误, CLUSTERDOWN Hash slot not served 吓得我 立马 去 redis 集群上去 检…

    2023年5月16日
    1.6K00
  • 在 Linux 上以 All-in-One 模式安装 KubeSphere

    步骤 1:准备 Linux 机器 若要以 All-in-One 模式进行安装,您仅需参考以下对机器硬件和操作系统的要求准备一台主机。 硬件推荐配置 操作系统 最低配置 Ubuntu 16.04, 18.04, 20.04, 22.04 2 核 CPU,4 GB 内存,40 GB 磁盘空间 Debian Bus…

    2023年4月18日
    1.1K00
  • CentOS图形化界面和命令行界面的转化–超详细(Linux操作系统)

    对于我这样的小白来说,Linux系统的图形化界面更加简单,但是Linux命令行才是精髓,如何进行转化呢? 1、快捷键方式切换(较为简单) 图形化界面转化成命令行界面  ctrl+alt+F3 命令行界面转化为图形化界面 ctrl+alt+F1 2、命令行形式切换切换成命令行模式: systemctl set-default mu…

    2023年12月13日
    1.6K00
  • rsync的搭建与使用

    rsync是数据镜像备份工具。使用快速增量备份工具Remote Sync可以远程同步,支持本地复制,或者与其他SSH、rsync主机同步。 已支持跨平台,可以在Windows与Linux间进行数据同步。 Ubuntu安装 Centos安装 基本用法 rsync语法有三种,分别是本地到本地形式Local to Local,本地到远程Local to Remot…

    2022年11月19日
    1.3K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

工作时间:周一至周五,8:30-17:30,节假日休息

关注微信