From zero to build WNMP environment

Big Three installation

Nginx installation

  • Download: http://nginx.org/en/download.html
  • Select the stable version:Here Insert Picture Description
  • Download File Name: nginx-1.16.1.zip
  • Extracting archive, and enter the directory, such as D: \ wnmp \ nginx
  • Run nginx.exe
  • Open your browser address bar: localhost, Enter
    Here Insert Picture Description
    appear on this page, the installation was successful.

PHP installation

  • Download: https://windows.php.net/download#php-7.4
  • Select non-thread-safe version
    Here Insert Picture Description
  • Download file: php-7.4.1-nts-Win32-vc15-x64.zip
  • Extracting archive, and enter the directory, for example: D: \ WNMP \ PHP
  • Open cmd, run the command php -vHere Insert Picture Description
    appear on this page, the installation was successful.

MySQL Installation

  • Download: https://dev.mysql.com/downloads/mysql/
  • Select Download -> No Thanks, the Just Start My download.
    Here Insert Picture Description
    Here Insert Picture Description
  • Download file: mysql-8.0.18-winx64.zip
  • Extracting archive, to prepare for subsequent configuration

Big Three Configuration

Nginx configuration

  • 备份conf目录(比如D:\wnmp\nginx\conf)下nginx.conf文件
  • 修改nginx.conf文件,部分注释内容未贴出来
#user  nobody;
worker_processes  1;

http {

    server {
        listen       80;
        server_name  localhost;
        location / {
            root   D:/wnmp/www/localhost;
            index  index.html index.htm index.php;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
           root           D:/wnmp/www/localhost;
           fastcgi_pass   127.0.0.1:9000;
           fastcgi_index  index.php;
           fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
           include        fastcgi_params;
        }
    }
}

PHP配置

  • 修改D:\wnmp\php目录下php.ini-development为php.ini,
  • 仅展示部分配置,其余根据项目需要自行修改配置
[PHP]

; 1
extension_dir = "D:\wnmp\php\ext"
; 2
enable_dl = On
; 3
cgi.force_redirect = 0
; 4
cgi.fix_pathinfo=1
; 5
fastcgi.impersonate = 1
; 6
cgi.rfc2616_headers = 1

; 7
extension=php_mysqli.dll

; 8
date.timezone = Asia/Shanghai

MySQL配置

  • MySQL安装目录D:\wnmp\mysql-8.0.18-winx64修改my.ini文件(如无,则手动添加)
[mysqld]
# set basedir to your installation path
basedir=D:\\wnmp\\mysql-8.0.18-winx64
# set datadir to the location of your data directory
datadir=D:\\wnmp\\mysql-8.0.18-winx64\\data

三大件联调

PHP连接Nginx

  • 创建目录D:\wnmp\www\localhost
  • 新建文件phpinfo.php,内容如下
<?php
  phpinfo();
  • 开启PHP进程(注意:cmd需要以管理员权限运行
d:\wnmp\php>php-cgi.exe -b 127.0.0.1:9000 -c php.ini
  • 开启Nginx
d:\wnmp\nginx>start nginx.exe

PHP连接MySQL

  • 开启MySQL
d:\wnmp>net start mysql
  • 编写脚本test_mysql.php,内容如下:
<?php
$servername = "localhost";
$username = "root";
$password = "phpphp";
 
// 创建连接
$conn = new mysqli($servername, $username, $password);
 
// 检测连接
if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
} 
echo "连接成功";

  • 打开浏览器,输入,查看页面展示
    Here Insert Picture Description
    至此,则表示PHP和MySQL连接成功。

常用脚本和命令

The following two scripts ** start_nginx.bat and stop_nginx.bat ** for quick starts, stops Nginx & PHP services.

start_nginx.bat

@echo off
 
REM set PHP_FCGI_CHILDREN=5
set PHP_FCGI_MAX_REQUESTS=1000
  
echo Starting PHP FastCGI...
D:\wnmp\nginx\RunHiddenConsole "D:\wnmp\php\php-cgi.exe" -b 127.0.0.1:9000 -c "D:\wnmp\php\php.ini"
echo Starting nginx...
D:\wnmp\nginx\RunHiddenConsole "D:/wnmp/nginx/nginx.exe" -p "D:/wnmp/nginx/"

stop_nginx.bat

@echo off
echo Stopping nginx...  
taskkill /F /IM nginx.exe > nul
echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe > nul
exit

Common Commands

  • View the process
tasklist /fi "imagename eq nginx.exe"
tasklist /fi "imagename eq php-cgi.exe"
netstat -ano | findstr "3306"
  • Nginx configuration reload
nginx -s reload
  • Nginx elegant close
nginx -s quit
  • Nginx help command
nginx -h
  • Shut down MySQL service
net stop mysql
Published 53 original articles · won praise 20 · views 40000 +

Guess you like

Origin blog.csdn.net/lylfv/article/details/103918976