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

相关推荐

  • 解决CentOS lspci(command not found)方法

    今日需要查看一台机器的显卡型号,但未安装驱动,只能通过lspci 进行查询 在进行CentOS最小化安装后,会发现lspci命令不好使。其实是因为相应的软件包没有安装。在终端中执行下列命令: 将会得到如下的显示内容 在终端中输入 安装后,即可正常使用lspci了。 查看显卡信息: 然后就可以参照型号下载显卡驱动了

    2024年5月6日
    93600
  • 宝塔安装composer,出现 putenv() has been disabled for security reasons

    在宝塔安装composer,出现 putenv() has been disabled for security reasons 方法一:打开配置文件php.ini,找到disable_functions字符串,把后面的putenv删除即可正常安装。 方法二:宝塔面板的话,我的版本是7.2,就找到 PHP7.2管理→禁用函数→删除putenv,重载配置文件后…

    2023年2月14日
    1.5K00
  • nginx快速部署一个网站服务 + 多域名 + 多端口

    一、nginx虚拟主机,部署网站 都是在同一台服务器上部署 二、部署单域名/IP网站服务 1、创建一个普通用户,用户管理nginx网站服务 2、修改nginx主配置文件 3、创建虚拟主机nignx子配置文件 只需要写server{}标签即可。 上面配置文件中配置了index.html的地址,这里可以看到是没有的,我们创建一下; 4、测试nginx配置文件语法…

    2023年12月25日
    85500
  • CentOS7系统开机报错:you might want to save “/run/initramfs/rdsosreport.txt“ to a USB stick or /boot…

    一、报错场景我遇到的场景是Centos7强制下电,开机后报错,报错的大致意思是系统文件出现错误 具体报错如下 you might want to save “/run/initramfs/rdsosreport.txt“ to a USB stick or /boot after mounting them and attach it to a bug re…

    2023年10月16日
    1.1K00
  • Win系统C盘拒绝访问或打不开怎么办

    在使用Win系统的时候,有用户可能会遇到C盘拒绝访问或者无法打开的情况,因此可能会感到困惑和无助。而这通常是由于权限设置问题或者其他系统错误导致的。不过,不必过于担心,因为这种情况通常可以通过一些简单的步骤来解决,一起来看看吧。   C盘拒绝访问或打不开的解决方法   方法一:运行杀毒软件   使用受信任的杀毒软件扫描和清除病毒。你可以通过下载专业杀毒软件并…

    2024年6月13日
    65500

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信