• Yum搭建LNMP环境(动、静、库分离)(week4_day5)--技术流ken


    前言

    本篇博客使用yum来搭建lnmp环境,将采用动态,静态以及数据库分开安装的方式即nginx,php,mysql.会被分开安装在不同的服务器之上,搭建出来一套lnmp环境,并部署wordpress进行测试。

    LNMP准备环境

    centos7

    firewalld关闭状态

    selinux关闭状态

    nginx服务器IP:192.168.43.174

    php、php-fpm、php-mysql服务器IP: 192.168.43.175

    MySQL服务器IP:192.168.43.176

    LNMP搭建

    第一步:php、php-fpm、php-mysql服务器搭建

    下载用于和数据库通信的php-mysql,支持php文件的php以及实现fastcgi的php-fpm

    [root@server ~]# yum install php-mysql php php-fpm -y

    第二步:配置php-fpm文件

    主要修改12行处为本机的IP地址,24行处修改为nginx端的IP地址,保证本机有apache用户

     ; Start a new pool named 'www'.
      2 [www]
      3 
      4 ; The address on which to accept FastCGI requests.
      5 ; Valid syntaxes are:
      6 ;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific address on
      7 ;                            a specific port;
      8 ;   'port'                 - to listen on a TCP socket to all addresses on a
      9 ;                            specific port;
     10 ;   '/path/to/unix/socket' - to listen on a unix socket.
     11 ; Note: This value is mandatory.
     12 listen = 192.168.43.175:9000      ##这里修改为本机的IP地址
     13 
     14 ; Set listen(2) backlog. A value of '-1' means unlimited.
     15 ; Default Value: -1
     16 ;listen.backlog = -1
     17 
     18 ; List of ipv4 addresses of FastCGI clients which are allowed to connect.
     19 ; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original
     20 ; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address
     21 ; must be separated by a comma. If this value is left blank, conne; must be separated by a comma. If this value is left blank, connections will be
     22 ; accepted from any ip address.
     23 ; Default Value: any
     24 listen.allowed_clients = 192.168.43.174  ##修改为nginx端的IP地址
     25 
     26 ; Set permissions for unix socket, if one is used. In Linux, read/write
     27 ; permissions must be set in order to allow connections from a web server. Many
     28 ; BSD-derived systems allow connections regardless of permissions.
     29 ; Default Values: user and group are set as the running user
     30 ;                 mode is set to 0666
     31 ;listen.owner = nobody
     32 ;listen.group = nobody
     33 ;listen.mode = 0666
     34 
     35 ; Unix user/group of processes
     36 ; Note: The user is mandatory. If the group is not set, the default user's group
     37 ;       will be used.
     38 ; RPM: apache Choosed to be able to access some dir as httpd
     39 user = apache   #确保有apache用户
     40 ; RPM: Keep a group allowed to write in log dir.
     41 group = apache  #确保有apache组
    ...

    检查是否有apache用户,如果没有需要下载httpd服务,或者自建apache用户即可

    [root@server ~]# id apache
    uid=998(apache) gid=48(apache) groups=48(apache)

    第三步:启动php-fpm服务

    监听本机的9000端口

    [root@server ~]# systemctl restart php-fpm
    [root@server ~]# ss -tnl | grep 9000
    LISTEN     0      128    192.168.43.175:9000                     *:*     

    第四步:下载nginx

    在192.168.43.174服务器上面下载nginx

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

    第五步:配置nginx

    添加如下一个location,fastcgi_pass执行刚才配置的php服务器端

    [root@proxy ~]# vim /etc/nginx/nginx.conf
    ...
     server {
            listen       80;
            server_name  _;
            root         /var/www/html;
           index index.html index.php;
            # Load configuration files for the default server block.
        #    include /etc/nginx/default.d/*.conf;
    
            location ~ .php$ {
            fastcgi_pass 192.168.43.175:9000;
            include fastcgi.conf;
            
            }
    ....

    第六步:检查nginx配置

    [root@proxy ~]# nginx -t
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful

    第七步:启动nginx

    检查无误后启动nginx

    [root@proxy ~]# systemctl restart nginx 
    [root@proxy ~]# ss -tnl | lsof -i :80
    COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
    nginx   9433  root    6u  IPv4 188674      0t0  TCP *:http (LISTEN)
    nginx   9434 nginx    6u  IPv4 188674      0t0  TCP *:http (LISTEN)

    第八步:下载mysql

    在mysql服务器端下载数据库

    [root@agent ~]# yum install mariadb-server -y

    第九步:启动数据库

    [root@agent ~]# systemctl restart mariadb

    第十步:建立数据库及用户

    创建一个wordpress数据库,新建一个wordpress用户

    [root@agent ~]# mysql -uroot -p123
    Welcome to the MariaDB monitor.  Commands end with ; or g.
    Your MySQL connection id is 116
    Server version: 5.7.23-log MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    
    MySQL [(none)]> create database wordpress;
    Query OK, 1 row affected (0.06 sec)
    
    MySQL [(none)]> grant all on wordpress.* to wordpress@'%' identified by '123';
    Query OK, 0 rows affected, 1 warning (0.07 sec)
    
    MySQL [(none)]> flush privileges;
    Query OK, 0 rows affected (0.02 sec)

    经过以上十步lnmp环境就已经搭建完成

    LNMP环境部署wordpress进行测试

    第一步:nginx服务器端准备wordpress文件

    [root@proxy ~]# cd /var/www/html/
    [root@proxy html]# ls
    [root@proxy html]# rz
    [root@proxy html]# ls
    wordpress-3.3.1-zh_CN.zip
    [root@proxy html]# yum install unzip -y
    [root@proxy html]# unzip wordpress-3.3.1-zh_CN.zip

    第二步:php服务器端也要准备wordpress文件

    至于为什么也要在php服务器端准备wordpress文件是因为nginx文件里面的配置,相当于动静分离架构,动态文件即php文件会来php服务器端来找

    [root@server ~]# cd /var/www/html/
    [root@server html]# ls
    [root@server html]# rz
    [root@server html]# ls
    wordpress-3.3.1-zh_CN.zip
    [root@proxy html]# yum install unzip -y
    [root@server html]# unzip wordpress-3.3.1-zh_CN.zip
    [root@server html]# ls
    wordpress  wordpress-3.3.1-zh_CN.zip

    第三步:浏览器测试

    在浏览器输入nginx服务器的ip地址

    点击创建一个配置文件

    点击现在就开始

    输入之前创建的数据库信息及用户信息,点击提交

    提示创建失败,只能进行手工创建(nginx服务器端及php服务器端执行下面同样的操作)

    [root@proxy html]# cd wordpress
    [root@proxy wordpress]# cp wp-config-sample.php wp-config.php 
    [root@proxy wordpress]# vim wp-config.php 
    // ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
    /** WordPress 数据库的名称 */
    define('DB_NAME', 'wordpress');
    
    /** MySQL 数据库用户名 */
    define('DB_USER', 'wordpress');
    
    /** MySQL 数据库密码 */
    define('DB_PASSWORD', '123');
    
    /** MySQL 主机 */
    define('DB_HOST', '192.168.43.176');
    
    /** 创建数据表时默认的文字编码 */
    define('DB_CHARSET', 'utf8');

    再次打开浏览器进行测试

    根据提示输入以上信息,点击下面的安装

     

    输入账号和密码进行登录即可

    至此LNMP服务搭建完成

  • 相关阅读:
    storm概述
    Mac下python路径
    Frida的安装
    Mac上安装多版本python的手工处理方式
    idea下编写shell脚本并执行
    CTF PWN专用虚拟机
    二叉树输入与存储的问题
    逆向推荐博客(持续更新)
    Kali 爬坑日记
    官宣:从windos服务器迁移到linux
  • 原文地址:https://www.cnblogs.com/kenken2018/p/9955045.html
Copyright © 2020-2023  润新知