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 7 NTP 内网时间定时同步

    一、环境 二、ntp安装服务 server服务器配置: client服务器配置:(如果有多台client服务器,亦可如此配置) 四、启动NTP服务&开机启动设置(包括server服务器和client服务器) 五、server服务器防火墙配置 六、client服务器手动从server服务器进行时间同步 在server服务器上执行date命令,查看时间 …

    2023年6月14日
    64200
  • ubuntu20.04 删除linux中软raid的方法

    取消软件 RAID 可能涉及到几个步骤,具体取决于你的操作系统和使用的软件。在大多数 Linux 系统中,mdadm 是用于管理软件 RAID 的常见工具。以下是在 Linux 中取消软件 RAID 的一般步骤: 请注意:在执行这些步骤之前,请确保你已经备份了所有重要数据,因为取消 RAID 可能会导致数据丢失。 查看当前 RAID 状态: 使用以下命令查看…

    2023年11月24日
    1.0K00
  • 编译安装python3.10,使用ansible管理windows

    前言 以下适用于CentOS7.9,因为ansible又是由python编写的,而yum源仅能下载到python3.6.8。ansible for windows是2019年推出的,需要用到的高版本ansible和插件,所以需要更新到python3.8以上版本才能支持,否则会运行会出现各种错误。 0.设置yum为阿里源 1.准备安装 2.下载安装python…

    2023年2月13日
    1.1K00
  • Centos7 安装GUI图形界面-VNC远程连接

    VNC需要系统安装的有桌面,如果是生产环境服务器,安装时使用的最小化安装,那么进行下面操作按章GNOME 桌面。 # 列出的组列表里有GNOME Desktop。 #安装 # 安装完成后,修改默认启动方式为图形化界面 # 如果要换回来 #然后重启系统即可 ———————&#8…

    2023年5月11日
    92400
  • Asciinema:你的所有操作都将被录制

    asciinema 是一款开源免费的终端录制工具,它可以将命令行输入输出的任何内容加上时间保存在文件中,同时还提供方法在终端或者web浏览器中进行回放 asciinema的录制和播放都是基于文本的,相比传统的video有很多好处,例如录制文件体积小,在播放的过程中可以暂停复制其中的文本内容等等 同时asciinema还提供了一个网站,你如果愿意还可…

    2023年5月23日
    76900

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信