程序笔记   发布时间:2022-07-15  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Web进阶LNMP网站部署1大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

Web进阶LNMP网站部署1

什么是LNMP

LNMP是一套技术的组合,L=Linux、N=Nginx、M~=MySQL、P~=php

LNMP架构工作流程

首先Nginx服务是不能处理动态请求,那么当用户发起动态请求时, Nginx又是如何进行处理的。

当用户发起http请求,请求会被Nginx处理,如果是静态资源请求Nginx则直接返回,如果是动态请求Nginx则通过fastcgi协议转交给后端的php程序处理,具体如下图所示

Web进阶LNMP网站部署1

详细流程

@H_450_43@

1.用户通过http协议发起请求,请求会先抵达LNMP架构中的Nginx

2.Nginx会根据用户的请求进行判断,这个判断是有LOCATIOn进行完成

3.判断用户请求的是静态页面,Nginx直接进行处理

4.判断用户请求的是动态页面,Nginx会将该请求交给fastcgi协议下发

5.fastgi会将请求交给php-fpm管理进程, php-fpm管理进程接收到后会调用具体的工作进程warrap

6.warrap进程会调用php程序进行解析,如果只是解析代码php直接返回

7.如果有查询数据库操作,则由php连接数据库(用户 密码 Ip)发起查询的操作

8.最终数据由*@H_918_5@mysql->php->php-fpm->fastcgi->nginx->http->user

部署LNMP架构

1.安装nginx

[root@web01 ~]# yum install -y nginx

2.安装php

# 1.更改yum源
[root@web01 ~]# wget http://us-east.repo.webtatic.com/yum/el7/webtatic-release.rpm
[root@web01 ~]# yum localinstall webtatic-release.rpm -y

# 2.生成缓存
[root@web01 ~]# yum makecache

# 3.安装php
[root@web01 ~]# yum -y install php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mcrypt php71w-mbString php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb

# 4.统一用户
## 创建www用户组
[root@web01 ~]# groupadd www -g 666
## 创建www用户
[root@web01 ~]# useradd www -u 666 -g 666 -s /sbin/nologin -M
## 修改nginx配置文件使用www用户
[root@web01 ~]# vim /etc/nginx/nginx.conf
user www;
## 修改php服务使用www用户
[root@web01 ~]# vim /etc/php-fpm.d/www.conf
[www]
user = www
group = www

# 5.启动php-fpm
[root@web01 ~]# systemctl start php-fpm

# 6.加入开机自启
[root@web01 ~]# systemctl enable php-fpm

# 7.检查php的进程
[root@web01 ~]# ps -ef|grep '[p]hp-fpm'
root 7570 1 0 16:00 ? 00:00:00 php-fpm: master process (/etc/phpfpm.conf)
www 7571 7570 0 16:00 ? 00:00:00 php-fpm: pool www
www 7572 7570 0 16:00 ? 00:00:00 php-fpm: pool www
www 7573 7570 0 16:00 ? 00:00:00 php-fpm: pool www
www 7574 7570 0 16:00 ? 00:00:00 php-fpm: pool www
www 7575 7570 0 16:00 ? 00:00:00 php-fpm: pool www

# 8.检查php端口
[root@web01 ~]# netstat -lntup|grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 7570/php-fpm:
maste

3.安装数据库

# 1.安装mariadb
[root@web01 ~]# yum install -y mariadb-server

# 2.启动mariadb
[root@web01 ~]# systemctl start mariadb

# 3.开机自启mariadb
[root@web01 ~]# systemctl enable mariadb

# 4.检查MySQL端口(3306)
[root@web01 ~]# netstat -lntup|grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
7909/mysqld

# 5.检查MySQL进程
[root@web01 ~]# ps -ef|grep '[m]ysqld'

# 6.设置mariadb密码为123
[root@web01 ~]# mysqladmin -uroot password '123'
### 修改密码
[root@web01 ~]# mysqladmin -uroot -p123 password '678'

# 7.客户端连接命令(登入数据库)
[root@web01 ~]# mysql -uroot -p123

将Nginx和php建立连接

# 1.修改nginx配置文件
[root@web01 nginx]# vim /etc/nginx/conf.d/blog.conf
server{
        listen 80;
        server_name localhost;
        root /code/;

        LOCATIOn / {
                index index.php index.html;
        }

        LOCATIOn ~ .php$ {
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_param SCRIPT_FILename $document_root$fastcgi_script_name;
                include /etc/nginx/fastcgi_params;
        }
}

$document_root:站点目录/code
$fastcgi_script_name:指的是index.php

# 2.创建站点目录
[root@web01 nginx]# mkdir /code

# 3.编辑php测试文件
[root@web01 nginx]# vim /code/info.php
<?php
   phpinfo();
?>

Web进阶LNMP网站部署1

测试php连接MySQL

[root@web01 nginx]# vim /code/mysql.php
<?php
     $servername = "localhost";
     $username = "root";
     $password = "123";
     
     // 创建连接
     $conn = mysqli_connect($servername, $username, $password);
     
     // 检测连接
     if (!$conn) {
         die("Connection failed: " . mysqli_connect_error());
     }
     echo "小哥哥,php可以连接MySQl...";
?>

<img style='width:100%;height:100%;'
src=https://blog.driverzeng.com/zenglaoshi/php_mysql.png>

Web进阶LNMP网站部署1

部署博客软件(wordpress)

wordpress官网:TP

# 1.下载wordpress
[root@web01 code]# wget https://wordpress.org/latest.tar.gz

# 2.解压
[root@web01 code]# tar xf latest.tar.gz

# 3.递归修改wordpress文件权限
[root@web01 code]# chown -R www.www /code/wordpress

# 4.编写wordpress的nginx配置文件
[root@web01 code]# vim /etc/nginx/conf.d/blog.conf
server{
        listen 80;
        server_name localhost;
        root /code/wordpress;

        LOCATIOn / {
                index index.php index.html;
        }

        LOCATIOn ~ .php$ {
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_param SCRIPT_FILename $document_root$fastcgi_script_name;
                include /etc/nginx/fastcgi_params;
        }
}

# 5.连接到MySQL中,创建一个给wordpress使用的库
[root@web01 wordpress]# mysql -uroot -p123
### 创建数据库 库名wp 字符集是utf8
MariaDB [(nonE)]> create database wp charset utf8

### 查看有几个库
MariaDB [(nonE)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_scheR_657_11845@a |
| mysql |
| perfoRMANce_scheR_657_11845@a |
| test |
| wp |
+--------------------+
5 rows in set (0.00 seC)

# 6.打开浏览器访问http://10.0.0.7

Web进阶LNMP网站部署1

Web进阶LNMP网站部署1

Web进阶LNMP网站部署1

大佬总结

以上是大佬教程为你收集整理的Web进阶LNMP网站部署1全部内容,希望文章能够帮你解决Web进阶LNMP网站部署1所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。