|NO.Z.00006|——————————|^^ 构建 ^^|——|Nginx&Nginx.V1.16&企业级LNMP&Yum.V2|

一、从0开始构建LNMP WEB平台,主要有两种方式;
### --- 从0开始构建LNMP WEB平台,主要有两种方式;

~~~     YUM二进制方式
~~~     MAKE源码编译方式
~~~     此处我们基于YUM二进制方式(网络源的形式,服务器能够上外网,配置局域网YUM源)
~~~     构建LNMP的操作

一、部署nginx:
### --- 添加Epel-release扩展源

[root@localhost ~]# yum -y install epel-release 
[root@localhost ~]# ll /etc/yum.repos.d/|grep -aw epel
-rw-r--r-- 1 root root  951 Oct  3  2017 epel.repo
-rw-r--r-- 1 root root 1050 Oct  3  2017 epel-testing.repo
### --- 安装nginx软件包:
### --- 显示Complete!表示安装成功;

[root@localhost ~]# yum -y install nginx 
### --- 检测nginx软件包是否安装成功

[root@27ba4cba71d5 ~]# rpm -qa |grep nginx 
nginx-filesystem-1.14.1-9.module_el8.0.0+184+e34fea82.noarch
nginx-mod-http-perl-1.14.1-9.module_el8.0.0+184+e34fea82.x86_64
nginx-mod-mail-1.14.1-9.module_el8.0.0+184+e34fea82.x86_64
nginx-1.14.1-9.module_el8.0.0+184+e34fea82.x86_64
nginx-all-modules-1.14.1-9.module_el8.0.0+184+e34fea82.noarch
nginx-mod-http-xslt-filter-1.14.1-9.module_el8.0.0+184+e34fea82.x86_64
nginx-mod-stream-1.14.1-9.module_el8.0.0+184+e34fea82.x86_64
nginx-mod-http-image-filter-1.14.1-9.module_el8.0.0+184+e34fea82.x86_64
### --- 查看端口和进程

[root@27ba4cba71d5 ~]# systemctl start nginx.service
[root@27ba4cba71d5 ~]# ps -ef |grep nginx 
[root@27ba4cba71d5 ~]# netstat -tunlp |grep -aw 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      258/nginx: master p 
tcp6       0      0 :::80                   :::*                    LISTEN      258/nginx: master p 
二、部署Mariadb:
### --- 安装Mariadb:

[root@27ba4cba71d5 ~]# yum -y install mariadb-server mariadb mariadb-devel 
### --- 检测Mariadb安装是否成功:

rpm -qa |grep mariadb
### --- 查看Mariadb进程和端口号;

[root@27ba4cba71d5 ~]# systemctl start mariadb.service
[root@27ba4cba71d5 ~]# ps -ef |grep mysql
mysql        452       1  0 08:04 ?        00:00:00 /usr/libexec/mysqld --basedir=/usr
root         518     121  0 08:04 ?        00:00:00 grep --color=auto mysql
[root@27ba4cba71d5 ~]# netstat -tunlp |grep -aw 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      452/mysqld
三、部署PHP:
### --- 安装php

[root@27ba4cba71d5 ~]# yum -y install php php-devel php-fpm php-mysql
### --- 检测PHP是否安装成功:

[root@27ba4cba71d5 ~]# rpm -qa |grep php
### --- 查看PHP进程及端口号
### --- 此时没有查到9000端口

[root@27ba4cba71d5 ~]# systemctl start php-fpm.service
[root@27ba4cba71d5 ~]# ps -ef |grep php
[root@27ba4cba71d5 ~]# netstat -tunlp|grep -aw 9000                 
四、根据如上LNMP部署指令操作,LNMP平台部署完成,查看其进程
### --- 根据如上LNMP部署指令操作,LNMP平台部署完成,查看其进程

[root@27ba4cba71d5 ~]# ps -ef |grep -wE "nginx|mysqld|php"
root         258       1  0 07:52 ?        00:00:00 nginx: master process /usr/sbin/nginx
nginx        259     258  0 07:52 ?        00:00:00 nginx: worker process
nginx        260     258  0 07:52 ?        00:00:00 nginx: worker process
mysql        452       1  0 08:04 ?        00:00:03 /usr/libexec/mysqld --basedir=/usr
root         598       1  0 08:14 ?        00:00:00 php-fpm: master process (/etc/php-fpm.conf)
apache       599     598  0 08:14 ?        00:00:00 php-fpm: pool www
apache       600     598  0 08:14 ?        00:00:00 php-fpm: pool www
apache       601     598  0 08:14 ?        00:00:00 php-fpm: pool www
apache       602     598  0 08:14 ?        00:00:00 php-fpm: pool www
apache       603     598  0 08:14 ?        00:00:00 php-fpm: pool www
root         647     121  0 08:23 ?        00:00:00 grep --color=auto -wE nginx|mysqld|php
五、nginx和php-fpm进行配置整合
### --- 要讲nginx和php-fpm进行配置整合,实现nginx检测到用户请求PHP动态网页时,
### --- nginx会将用户的请求通过CGI网关协议发送给后端PHP-FPM解释器取出来,
### --- nginx.conf配置代码如下:

### --- nginx配置:
[root@localhost nginx]# 
        location / {                                            // 第二步
            root   html;
            index index.php index.html index.htm;               // 加上nginx.php表示引导页。

        location ~ \.php$ {
            root           /usr/share/nginx/html;               // 更改发布目录;第一步
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;                           // 添加$document_root;表示发布目录  //第三步
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
### --- 查看nginx.conf文件并去掉#号空行。

[root@localhost nginx]# grep -vE "#|^$" nginx.conf
worker_processes  1;                    
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;                                      // 以上为全局配置
    server {                                                    // 以下为server主机的配置
        listen       80;
        server_name  localhost;
        location / {                                            // location /是正常匹配,处于正则匹配后执行。
            root   html;
            index index.php index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location ~ \.php$ {                                     // location ~是正则匹配,是优先匹配,   
            root           /usr/share/nginx/html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;                           // 指定发布目录的变量,绝对路径也可以:/usr/share/nginx/html;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;   
            include        fastcgi_params;
        }
    }
}
六、更改完成之后:
### --- 重启nginx服务

[root@27ba4cba71d5 nginx]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@27ba4cba71d5 nginx]# nginx -s reload
七、nginx、php-fpm发布目录;/usr/share/nginx/html,在该目录创建index.php,代码内容如下。
### --- nginx、php-fpm发布目录;
### --- /usr/share/nginx/html,在该目录创建index.php,代码内容如下。

[root@27ba4cba71d5 nginx]# vim /usr/share/nginx/html/index.php
<?php
phpinfo();
?>
八、通过LNMP发布网站:
### --- 我们只需要把我们打开发包解压到发布目录就可以了:

[root@localhost ~]# ls
anaconda-ks.cfg  web.html.tar
[root@localhost ~]# tar -zxvf web.html.tar /usr/share/nginx/html

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

posted on   yanqi_vip  阅读(19)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示