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

相关推荐

  • linux 文件挂载配置错误解决办法

    linux中挂载命令经常能够用到,特别是配置开机自动挂载的时候,一不留神就配置错误了,这样造成的后果就是重启过后就会发现系统起不来了!!! 首先进行模拟测试 格式化磁盘 mkfs.ext4 /dev/sdb1 挂载磁盘 mount /dev/sdb1 /mnt 修改配置文件并进行破环 vi /etc/fstab 重启验证后发现不能远程登录,系统进入救援模式!…

    2023年9月27日
    94100
  • 缩小vhdx文件的大小

    使用 Hyper-V 提供的 Optimize-VHD 进行缩小,执行之后 VHDX 文件的确是变小了,但是也还没有那么小 此时应进入到 WSL2 中,运行 zerofree 将 ext4 文件系统内已经不用的块填零,但 zerofree 不能运行在已经挂载为 rw 的文件系统上,那就把文件系统挂载为 rea…

    2023年7月21日
    1.6K00
  • Linux JumpServer 堡垒机远程访问

    前言JumpServer 是广受欢迎的开源堡垒机,是符合 4A 规范的专业运维安全审计系统。JumpServer 帮助企业以更安全的方式管控和登录所有类型的资产,实现事前授权、事中监察、事后审计,满足等保合规要求。 下面介绍如何简单设置即可使本地jump server 结合cpolar 内网穿透实现远程访问jump server 管理界面. 安装环境后.使用…

    2023年12月20日
    90900
  • Linux系统之安装uptime-kuma服务器监控面板

    一、检查本地环境 1.1 检查本地操作系统版本检查本地操作系统版本 1.2 检查系统内核版本 检查系统内核版本 1.3 检查系统是否安装Node.js 检查系统是否安装Node.js 二、部署Node.js 环境 2.1 下载Node.js安装包 下载Node.js安装包 2.2 解压Node.js安装包 解压Node.js安装包 2.3 复制二进制文件 将…

    2023年9月21日
    1.2K00
  • windows使用ipmitools管理ipmi

    今日有个服务器IPMI密码忘记,无法登陆,但是服务器不能够进行重启,并且还是windows系统,所以尝试通过ipmitool进行管理 首先安装ipmitool http://s.cnaaa11.com/soft/ipmitool.zip 服务器本地win系统下安装此工具,用于对自身服务器BMC发送指令,实现带内管理: 安装步骤: 1) 将IPMIToolWi…

    2024年5月7日
    1.2K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信