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 服务器配置虚拟内存 本小节以 Windows Server 2022 为例,其他版本的 Windows 操作系统类似,可据此做参考。 1、打开服务器的控制面板。可以通过开始菜单或在搜索框内运行命令”control”来打开控制面板。 2、在控制面板中,选择”系统和安全”,然后选择”…

    2024年1月31日
    1.7K00
  • 又见问题之-Windows Server 2012 R2 安装.net 4.6.1

    服务器是新版的Windows Server 2012 R2 ,今天安装一个软件,软件需要(.net v4.6.1)环境,发现报错,缺少.Netframework, Version=v4.6.1,直接下载对应版本的.Netframework 连续点击是,会跳转到 .net 的下载页面,选中所需的 .net 版本 下载安装之后报错,你需要先安装 对应于 KB29…

    2023年10月25日
    2.0K00
  • 在 Kubernetes 上最小化安装 KubeSphere

    除了在 Linux 机器上安装 KubeSphere 之外,您还可以将其直接部署在现有的 Kubernetes 集群上。本快速入门指南将引导您完成在 Kubernetes 上最小化安装 KubeSphere 的一般性步骤。 准备工作 备注 部署 KubeSphere 确保您的机器满足安装的前提条件之后,可以按照以下步骤安装 KubeSphere。 执行以下命…

    2023年4月18日
    1.3K00
  • Linux实验案例:构建Samba文件共享服务器

    根据公司的信息化建设要求,公司需要在局域网内部搭建一台文件服务器,便于对数据的集中管理和备份。考虑服务器的运行效率及稳定性、安全性问题,选择在CentOS系统中构建Samba服务器以提供文件资源共享服务。 需求描述 1.在/var/share/目录中建立三个子目录public、training、devel,用途如下。 public目录用于存放公共数据,如公司…

    2024年6月24日
    1.8K00
  • Windows 添加新用户,并授予该用户远程登录权限

    首先添加新用户: 以管理员身份登录,选择“更改账户设置”:  选择 “其他用户” –> “将其他人添加到这台电脑”: 选择  “用户”: 单击鼠标右键,选择  “新用户”: 选择新建用户,单击鼠标右键,选择 “属性”: 接下来授予远程登陆权限: ——只需要将该用户加入 “Remote Desktop Users” 组即可。

    2023年6月29日
    1.5K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信