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

相关推荐

  • zabbix利用自带模板-监控mysql性能

    环境: zabbix3.4.4 mariadb 5.5.56   要求:  利用zabbix 自带的模板 监控mariadb 上的 并发连接数,慢查询数量,增删改查、请求流量带宽,mysql响应流量带宽等 (1)创建监控用户 grant all on *.* to zabbix@’localhost’ identified by ‘zab…

    2023年2月25日
    1.1K00
  • Win10 Edge浏览器无法使用内置管理员打开解决办法

    在Win10系统中我们经常会遇到这样的问题,应用打不开,提示无法使用内置管理员帐户打开此应用,今天有用户也遇到了Edge浏览器打不开的问题,一样的情况,这是由于Win10的特殊权限机制导致的,大家一般都会使用Administrator这个内置管理员帐户,想要打开应用还需要设置一下,具体看看下面解决方法。 解决方法一:还原UAC设置 1.打开win10系统的控…

    2023年12月1日
    1.5K00
  • 超微浪潮服务器webbios配置raid

    这段时间比较奇怪,服务器总是和我过不去 ——O(∩_∩)O,前段时间刚搞了一台IBM服务器做RAID0安装EXSi。今天又来了台浪潮NF5245M3,个头一点都不小。上个图看看,第一次接触这个品牌服务器。  好了,说重点吧。这次主要是用来做数据库服务器测试机的,有两个要求:        1、做RAID0,提…

    2024年5月23日
    93600
  • atop:监控Linux系统资源与进程

    命令简介 atop 命令是一款监控 Linux 系统资源与进程的工具,非内部命令,需要安装。 atop 是以一定的频率记录系统的运行状态,所采集的数据包含系统资源(CPU、内存、磁盘和网络)使用情况和进程运行情况,并能以日志文件的方式保存在磁盘中,服务器出现问题后,我们可获取相应的atop日志文件进行分析,atop是一款开源软件。 语法格式 选项说明 进程图…

    2023年9月5日
    1.1K00
  • ubuntu 编译 pyav 报错 libx264 not found

    解决办法:

    2023年9月7日
    1.1K00

发表回复

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

在线咨询: QQ交谈

邮件:712342017@qq.com

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

关注微信