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

相关推荐

  • 通过远程桌面连接Windows实例,提示“为安全考虑,已锁定该用户账户,原因是登录尝试或密码更改尝试过多”错误怎么办?

    问题描述 使用远程桌面连接Windows系统的ECS实例,提示“为安全考虑,已锁定该用户账户,原因是登录尝试或密码更改尝试过多”错误,具体报错信息如下图所示。 问题原因 Windows系统的ECS实例系统组策略中配置了用户锁定策略,在登录时输入错误的密码次数过多,该账户会被锁定,导致远程桌面无法登录。 解决方案 您可以修改Windows实例组策略账户锁定阈值…

    2023年11月13日
    1.7K00
  • centos7 shell 支持中文显示

    其实很简单,让 shell 支持 utf8 即可。先使用locale命令看一下设置情况: LC_ALL没有设置,需要赋值en_US.UTF-8,很简单: 最后,不要忘了source一下bash_profile,让其生效。

    2023年3月14日
    1.1K00
  • VMware 虚拟机里连不上网的五种解决方案

    大家好,又见面了,我是你们的朋友全栈君。 在VMware虚拟机里的虚拟机系统连接不上网络 首先,注意查看适配器选项里的网络连接这两个网络连接是否存在,如果不存在可以重新装一下VM 如果存在,连不上网 解决办法一: 虚拟机设置里,找到“网络适配器”,右边的网络连接选择“NAT 模式”,如果不行的话再 linux系统。还是不行的话接着看第二种解决方案。 解决方法…

    2024年6月28日
    3.1K00
  • 通过远程桌面连接Windows实例提示“远程桌面用户组没有该权限”错误怎么办?

    本文介绍通过远程桌面连接Windows实例提示“远程桌面用户组没有该权限”错误的解决方案。 问题描述 本地客户端通过远程桌面连接Windows实例时提示“远程桌面用户组没有该权限”错误 解决方案 根据实际情况,选择对应方案进行解决。本文以Windows Server 2012操作系统为例。 方案一:修改本地安全策略。 右键单击开始,然后单击运行。在运行对话框…

    2023年3月2日
    1.3K00
  • 解决ESXi忘记密码问题

    解决ESXi密码忘记问题的方法 1. 通过VMware官方提供的VMware Password Reset方法 VMware通过向管理员发送一封电子邮件,其中包含了用于重设root 密码的链接来解决这个问题。以下是该方法的具体步骤: 2.通过VMware PowerCLI 另外一种重置ESXi密码的方法是使用VMware PowerCLI。它是一种基于Pow…

    2023年10月11日
    1.8K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信