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

相关推荐

  • centos7下smartctl安装配置

    安装 使用

    2023年4月13日
    1.3K00
  • HBase 高可用集群详细图文安装部署

    一、HBase 安装部署 1.1 Zookeeper 正常部署 首先保证 Zookeeper 集群的正常部署,并启动之。 1.2 Hadoop 正常部署  Hadoop 集群的正常部署并启动。 1.3 HBase 安装  HBase 官方下载地址:Apache Download Mirrors 1.4 HBase 的配置文件  1.4.1 hbas…

    2023年12月15日
    1.0K00
  • Linux下安装PHP

    安装准备 安装PHP所需的系统库,可以扩展php更多功能 手动安装libiconv-devel(编译三部曲) 默认yum源中缺少libiconv-devel软件包,需要编译安装,用于php的编码转换 下载安装 国内镜像地址:http://mirrors.sohu.com/php/ 下载编译文件 编译安装 配置编译脚本 看到如下提示,说明编译成功了 进行编译安…

    2022年6月25日
    1.2K00
  • 幻兽帕鲁服务器版本更新

    幻兽帕鲁服务器游戏怎么升级版本?自建幻兽帕鲁服务器进入Palworld游戏提示“您正尝试加入的比赛正在运行不兼容的游戏版本,请尝试升级游戏版本”什么原因?这是由于你的客户端和幻兽帕鲁服务器版本不匹配,如何解决?更新幻兽帕鲁服务器即可解决。 幻兽帕鲁进行一次更新,服务器也需要同步更新,才能继续游玩。 Linux服务器更新 1、使用如下命令,首先切换至root用…

    2024年2月4日
    2.2K00
  • pve系统崩溃,ceph集群节点不能加入问题处理

    本次故障缘起,pve系统盘突然坏了,导致ceph集群降级,重装pve系统后,发现ceph不能加入原有的集群,需要清除所有配置才可完成 首先需要从集群中删除故障ceph ceph的配置文件路径 /etc/ceph/ceph.conf 此次故障的节点是pve3,在一个正常的节点配置文件中删除故障的节点 同时需要在web页面 监视器中销毁之前故障的节点 osd销毁…

    2024年4月2日
    1.3K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信