LNMP搭建

LNMP搭建

nginx安装

#:创建系统用户nginx
[root@localhost ~]# useradd -r -M -s /sbin/nologin nginx

#:安装依赖环境
[root@localhost ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++
安装过程略....
[root@localhost ~]# yum -y groups mark install 'Development Tools'
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Marked install: Development Tools

#:创建日志存放目录
[root@localhost ~]# mkdir -p /var/log/nginx
[root@localhost ~]# chown -R nginx.nginx /var/log/nginx

#:下载nginx
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget http:#:nginx.org/download/nginx-1.22.1.tar.gz
#:编译安装
[root@localhost src]# ls
 anaconda-ks.cfg  nginx-1.12.0.tar.gz
[root@localhost src]# tar xf nginx-1.22.1.tar.gz
[root@localhost src]# cd nginx-1.22.1
[root@localhost nginx-1.22.1]# ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-debug \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_image_filter_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log

[root@localhost nginx-1.22.1]# make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install
安装过程略....

安装数据库

[root@localhost ~]#  yum -y install mariadb mariadb-server
[root@localhost ~]#  systemctl start mariadb 
[root@localhost ~]#  systemctl enable mariadb

配置环境变量并启动nginx

[root@localhost ~]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@localhost ~]# . /etc/profile.d/nginx.sh
[root@localhost ~]# nginx
[root@localhost ~]# ss -antl 
State     Recv-Q    Send-Q         Local Address:Port         Peer Address:Port    
LISTEN    0         128                  0.0.0.0:80                0.0.0.0:*       
LISTEN    0         128                  0.0.0.0:22                0.0.0.0:*       
LISTEN    0         128                     [::]:22                   [::]:*       
LISTEN    0         80                         *:3306                    *:*  

编辑nginx配置文件

#:编辑 /usr/local/nginx/conf/nginx.conf 将以下行取消注释
location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME   /$document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
        #:将原来的/scripts$fastcgi_script_name;改成/$document_root$fastcgi_script_name;然后重新启动nginx

编辑php配置文件

#:编辑 /etc/httpd/conf.d/php.conf 文件在文档最后添加
#:没有配置文件请安装php服务,nginx本身不做nginx解析;
</IfModule>
<VirtualHost *:9000>
    DocumentRoot "/usr/local/nginx/html"
    ErrorLog "/usr/local/nginx/html"
    CustomLog "/usr/local/nginx/html" common
   ProxyRequests off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/nginx/html$1
   <Directory "/usr/local/nginx/html">
     Options none
     AllowOverride none
     Require all granted
  </Directory>
</VirtualHost>

#:编辑 /etc/php-fpm.d/www.conf  最后添加
 
listen = 0.0.0.0:9000

#:重启php服务

编辑php默认页

#:编写/usr/local/nginx/html/index.php 文件内容如下
<?php
  phpinfo();
?>

网站测试:

动态页面:

在这里插入图片描述

静态页面:

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值