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

相关推荐

  • windows10电脑开机错误提示0xc00000bb

    Windows10系统设备卡在主板logo提示B1InitializeLibrary failed 0xc00000bb的解决方法; 开机提示B1InitializeLibrary failed 0xc00000bb报错,是由于GUID主分区表损坏,无法正常读取UEFI启动项导致。 解决办法很简单,通过启动U盘进入WINPE系统,打开Diskgenius分区…

    2023年9月21日
    1.8K00
  • Word找回没有保存的文件方法

      1、“不保存”找回文件。   当我们关闭文档时,会提示,是否保存,如果点错了,直接点击“不保存”,咋办?   再次启动 Word,进入「打开」,选择右侧的「恢复未保存的文档」,在这里,我们可以看到许多文件,这些文件全部都是点击了“不保存”,没有保存下来的文件,找到我们需要的文件,然后“打开”即可。   2、死机、断电等导致文件丢失。   如果你正在使用 …

    2024年6月17日
    1.6K00
  • Windows10 此用户无法登录,因为该账户当前已被禁用

    当我访问同事电脑共享文件夹时,弹出如下提示框:(可以在命令提示符上ping通,就是死活不能访问) 网上的那些置顶解决办法我就不说了,什么修改本地策略、安全策略,什么关闭防火墙啦、什么打开网络发现啦……..    压根球用没有!!我这里用的是找得小众化的偏方: 1、打开控制面板; 2、选择用户账户; 3、打…

    2023年2月17日
    2.4K00
  • IP addr添加网络的使用

    IP addr 添加网络的使用 添加IP到网口 查看添加的IP 移除添加的IP 启用网口IP 禁用网口 检测路由 添加路由 移除路由 添加网关 移除网关

    2024年7月5日
    4.5K00
  • CentOS7单用户修改密码

    重启开机  按‘e’进入编辑模式 在下边 编辑修改两处:ro改为rw,在LANG=en_US.UFT-8后面添加 init=/bin/sh 按Ctrl+x 重启进入单用户,修改密码 由于selinux开启着的需要执行以下命令更新系统信息,否则重启之后密码未生效 重启系统

    2023年6月12日
    1.4K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信