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 Server 2008 访问NFS共享存储

    打开CMD窗口 输入servermanagercmd.exe -install FS-NFS-Services,进行安装 让磁盘映射永久存在 为了保证系统重启之后磁盘映射依然存在,要运行以下命令: net use /persistent:yes 挂接磁盘文件 mount -u:用户名  -p:密码 服务器IP:/mnt/volume/myNFS z:

    2022年8月4日
    1.4K00
  • Linux安装青龙面板 稳定版超级详细

    一.安装docker容器 1.工具安装 复制所有代码然后直接右键粘贴进去 中间过程输入y 回车 yum install docker-io –y 这里输入y 安装成功之后是这个样子 输入以下代码回车 systemctl start docker 复制粘贴下面命令回车 docker ps 如果显示下图 即为成功 二.安装青龙面板 1.安装面板 (想改青龙面板端…

    2022年6月22日
    3.1K00
  • 如何清理windows server 2008 R2 中winsxs文件夹

    最近发现公司的一台服务器C盘只剩5G左右的空间,经过仔细查看发现C:\windows\winsxs 目录占了20多G的容量。此文件夹是更新系统补丁产生的不能直接删除,所以只能通过cleanmgr.exe工具进行清理C盘。 以下方法亲自验证清理成功: 一、在Windows Server 2008 R2,右击C盘,查看属性,发现界面中没有清理C盘的工具按钮,那如…

    2023年4月3日
    1.0K00
  • Ubuntu 启用root账户并开启远程登录

    1.启用root账户 修改root用户密码,输入下方命令后,还需要输入当前普通用户的密码进行身份验证,然后修改root用户的新密码 sudo passwd root 2、开启远程登录 执行下方命令后开启root用户的远程登录 此时就能使用root账户成功登录了

    2022年6月11日
    1.6K00
  • Linux中监测磁盘IO性能

    Linux 存储系统 I/O 栈由文件系统层(file system layer)、通用块层( general block layer)和设备层(device layer)构成。 其中,通用块层是 Linux 磁盘 I/O 的核心。向上,它为访问文件系统和应用程序的块设备提供了标准接口;向下,它将各种异构磁盘设备抽象为一个统一的块设备,并响应文件系统和应用程…

    2022年12月1日
    1.1K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信