Nginx系列-2.配置LNMP(Linux、Nginx、MySQL、PHP)架构

Nginx系列-2.配置LNMP(Linux、Nginx、MySQL、PHP)架构

目录 - Nginx系列

Nginx系列-1.Linux下安装Nginx
Nginx系列-2.配置LNMP(Linux、Nginx、MySQL、PHP)架构
Nginx系列-3.配置Nginx虚拟主机
Nginx系列-4.Nginx日志配置及日志切割
Nginx系列-5.配置Nginx的防盗链
Nginx系列-6.配置Nginx的HTTPS
Nginx系列-7.配置Nginx使用uwsgi支持web.py框架
Nginx系列-8.配置Nginx+Apache实现动静分离
Nginx系列-9.配置NFS实现Nginx实现动静分离
Nginx系列-10.采用Nginx搭建正向代理服务
Nginx系列-11.配置Nginx反向代理和负载均衡


实验环境
一台最小化的 CentOS 7.3 虚拟机

一、安装软件包

yum install -y epel-*
yum install -y nginx mariadb-server php php-fpm php-mysql \
php-pdo php-pdo_dblib php-json php-devel php-gd \
php-pear php-xml php-pecl-zip wget vim

二、配置Nginx支持PHP

  1. 建立nginx的主目录

    mkdir /var/wwwroot
    cd /var/wwwroot
    echo -e hello_world >> index.html
    echo -e "<?php phpinfo(); ?>" >> info.php

    Nginx系列-2.配置LNMP(Linux、Nginx、MySQL、PHP)架构

  2. 编辑nginx配置文件

    vim /etc/nginx/nginx.conf

    Nginx系列-2.配置LNMP(Linux、Nginx、MySQL、PHP)架构

  3. 修改nginx主目录和索引
    3.1. 将http下的server下的root的值修改为/var/wwwroot
    3.2. 在http下的server下添加

    index index.php index.html index.htm

    Nginx系列-2.配置LNMP(Linux、Nginx、MySQL、PHP)架构

  4. http下的server下的加入以下内容

    location ~ \.php$ {
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include         fastcgi_params;
    }

    Nginx系列-2.配置LNMP(Linux、Nginx、MySQL、PHP)架构

  5. 启动nginxphp-fpm

    systemctl start nginx php-fpm
  6. 关闭防火墙

    setenforce 0
    systemctl stop firewalld
    systemctl disable firewalld
  7. 在宿主机访问nginx
    访问http://[centos_ip]/info.php
    Nginx系列-2.配置LNMP(Linux、Nginx、MySQL、PHP)架构

三、配置MySQL

  1. 启动MySQL

    systemctl start mariadb
  2. 输入以下命令,配置MySQL

    mysql_secure_installation
  3. 提示Enter current password for root (enter for none):
    敲击回车

  4. 提示Set root password? [Y/n]
    Y,随后设置密码
    Nginx系列-2.配置LNMP(Linux、Nginx、MySQL、PHP)架构

  5. 提示Remove anonymous users?
    意思为是否删除匿名用户

  6. 提示Disallow root login remotely?
    意思为远程禁止root登录吗?

  7. 提示Remove test database and access to it?
    意思为删除测试数据库吗?

  8. 提示Reload privilege tables now?
    意思为现在重新加载特权表吗?

  9. 登录mysql数据库
    mysql -uroot -p

    Nginx系列-2.配置LNMP(Linux、Nginx、MySQL、PHP)架构

四、下载WordPress测试LNMP

  1. 下载WordPress

    cd /var/wwwroot
    rm -rf index.html
    rm -rf info.php
    wget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz
    tar -zxvf wordpress-4.9.4-zh_CN.tar.gz
    cp -rf /var/wwwroot/wordpress/* /var/wwwroot
    cd /var/wwwroot
    rm -rf wordpress
    chmod -R 777 *
  2. 登录mysql创建数据库

    mysql -uroot -p
    CREATE DATABASE wordpress;
  3. 在宿主机访问nginx服务器
    访问http://[centos_ip]/
    按提示安装即可
    Nginx系列-2.配置LNMP(Linux、Nginx、MySQL、PHP)架构
    Nginx系列-2.配置LNMP(Linux、Nginx、MySQL、PHP)架构
    Nginx系列-2.配置LNMP(Linux、Nginx、MySQL、PHP)架构

猜你喜欢

转载自blog.51cto.com/tong707/2126257