LNMP架构Fastcgi协议

文章详细描述了在Linux环境中使用LNMP框架部署知乎和电商平台的步骤,包括配置Nginx服务,创建数据库,代码上传与解压,修改配置文件,以及进行hosts解析。同时,提到了将数据库迁移到独立服务器的过程,包括数据导出、导入,创建远程数据库用户,并修改业务代码以连接新数据库。
摘要由CSDN通过智能技术生成

部署第二个业务: 知乎
第一步: LNMP框架 Linux Nginx MySQL PHP
第二步: 配置Nginx服务
[root@web01 conf.d]# cp wordpress.conf zh.conf
修改zh.conf内容
    [root@web01 conf.d]# cat zh.conf 
    server {
        listen 80;
        server_name zh.oldboy.com;

        location / {
        root /code/zh/;
        index  index.php index.html;
        }

        location ~ \.php$ {
        root /code/zh/;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        }

    }
    检测语法并重启服务
    [root@web01 conf.d]# nginx -t
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
    [root@web01 conf.d]# systemctl restart nginx

    
    
第三步: 创建代码目录 并下载代码
    mkdir /code/zh
    上传wecenter代码到/code/zh
    解压代码:
    [root@web01 zh]# unzip WeCenter_V3.6.2.zip
    
    授权属主属组为apache
    [root@web01 zh]# chown -R apache.apache ../zh

    
第四步: 创建zh库
    [root@web01 zh]# mysql -uroot -plzy123.com -e "create database zh;"
    [root@web01 zh]# mysql -uroot -plzy123.com -e "show databases;"
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | test               |
    | wordpress          |
    | zh                 |
    +--------------------+


第五步: hosts解析
10.0.0.7  zh.oldboy.com

第六步: 通过浏览器安装部署业务


部署电商平台: 官网http://www.phpshe.com/
phpshe.oldboy.com/install
第一步: 创建商城nginx配置文件
    [root@web01 conf.d]# cp zh.conf phpshe.conf
    [root@web01 conf.d]# vim php.conf 
    server {
    listen 80;
    server_name phpshe.oldboy.com;

    location / {
    root /code/phpshe/;
    index  index.php index.html;
    }

    location ~ \.php$ {
    root /code/phpshe/;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }

    }
    
    检测并重启nginx
    [root@web01 conf.d]# nginx -t
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
    [root@web01 conf.d]# systemctl restart nginx

    
第二步:  创建代码目录 /code/phpshe 上传代码

    [root@web01 ~]# mkdir /code/phpshe
    [root@web01 ~]# cd /code/phpshe
    [root@web01 phpshe]# 

第三步: 解压移动
    [root@web01 phpshe]# unzip 1.zip

    将1目录下的代码文件移动到当前phpshe目录
    [root@web01 phpshe]# mv 1/* .

    授权属主属组为apache
    [root@web01 phpshe]# chown -R apache.apache ../phpshe/
    
第四步: hosts解析
    10.0.0.7 phpshe.oldboy.com
    
第五步: 浏览器访问安装

作业: 
1)部署知乎
2)部署PHPshe电商平台
3)部署edusoho
4)部署网盘 http://www.kodcloud.com/


统一用户: 修改为www用户 Nginx PHP
创建用户:
[root@web01 ~]# groupadd -g666 www
[root@web01 ~]# useradd -u666 -g666 -M -s /sbin/nologin www
[root@web01 ~]# id www
uid=666(www) gid=666(www) groups=666(www)
修改服务启动用户:
    Nginx:
    [root@web01 ~]# vim /etc/nginx/nginx.conf 
    [root@web01 ~]# head /etc/nginx/nginx.conf

    user  www;

    PHP:
    [root@web01 ~]# vim /etc/php-fpm.d/www.conf 
    [root@web01 ~]# grep www /etc/php-fpm.d/www.conf
    ; Start a new pool named 'www'.
    [www]
    user = www
    group = www

    重启服务并修改代码目录属主属组www:
    [root@web01 ~]# systemctl restart php-fpm nginx
    [root@web01 ~]# chown -R www.www /code/

    
    PHPshe管理员登陆问题:
    [root@web01 ~]# chown -R www.www /var/lib/php/session/
    
    
    
    
拆分数据库到独立服务器10.0.0.51:
第一步: 准备服务器安装mariadb
    [root@db01 ~]# yum -y install mariadb-server

第二步: 启动数据库加入开机自启动
    [root@db01 ~]# systemctl start mariadb
    [root@db01 ~]# systemctl enable mariadb


第三步: 将web01数据库的数据导出到all.sql
        [root@web01 ~]# mysqldump -uroot -plzy123.com -A > all.sql
        [root@web01 ~]# ll all.sql 
        -rw-r--r-- 1 root root 2252811 Jun 20 11:52 all.sql
    

第四步: 将all.sql拷贝10.0.0.51 导入到新的数据库中
        [root@web01 ~]# scp all.sql 10.0.0.51:/root/
        # 导入到新的数据库    
        [root@db01 ~]# mysql -uroot < all.sql
        # 重启数据库
        [root@db01 ~]# systemctl restart mariadb
        
        检查数据库是否导入正常: phpshe zh wordpress
        [root@db01 ~]# mysql -uroot -plzy123.com
        Welcome to the MariaDB monitor.  Commands end with ; or \g.
        Your MariaDB connection id is 3
        Server version: 5.5.68-MariaDB MariaDB Server

        Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

        Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

        MariaDB [(none)]> show databases;
        +--------------------+
        | Database           |
        +--------------------+
        | information_schema |
        | mysql              |
        | performance_schema |
        | phpshe             |
        | test               |
        | wordpress          |
        | zh                 |
        +--------------------+
        7 rows in set (0.00 sec)
        
第五步: 在新的库授权一个账号能支持远程连接51
        创建lzy用户管理所有的库和里面所有的表 密码是lzy123.com
        MariaDB [(none)]> grant all on *.* to lzy@'%' identified by 'lzy123.com';

        测试远程连接数据库:
        测试连接本地: 
        [root@db01 ~]# mysql -uroot -plzy123.com -h 127.0.0.1

        测试远程连接: web01连接db01测试
        [root@web01 ~]# mysql -ulzy -plzy123.com -h 172.16.1.51
        
        
第六步: 修改业务代码PHP的数据库连接信息 连接到172.16.1.51去查询数据
        停止WEB01的数据库
        [root@web01 ~]# systemctl stop mariadb
        [root@web01 ~]# systemctl disable mariadb
        
        wordpress代码:
        [root@web01 ~]# cd /code/wordpress/
        [root@web01 wordpress]# vim wp-config.php
        /** Database username */
        define( 'DB_USER', 'lzy' );                     # 需要改用户名

        /** Database password */
        define( 'DB_PASSWORD', 'lzy123.com' );

        /** Database hostname */
        define( 'DB_HOST', '172.16.1.51' );              # 修改连接的IP地址为远端服务器51
        
        修改zh代码:
        [root@web01 ~]# cd /code/zh/
        [root@web01 zh]# vim system/config/database.php 
        [root@web01 zh]# cat system/config/database.php
        <?php

        $config['charset'] = 'utf8mb4';
        $config['prefix'] = 'aws_';
        $config['driver'] = 'MySQLi';
        $config['master'] = array (
          'charset' => 'utf8mb4',
          'host' => '172.16.1.51',
          'username' => 'lzy',
          'password' => 'lzy123.com',
          'dbname' => 'zh',
          'port' => '3306',

        修改PHP代码:自己找文件配置


        
在安装的时候直接将数据部署到10.0.0.51
在安装部署过程中需要用到一个远程用户
其他安装步骤都一样的

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值