Build WNMP environment from scratch

Keywords: PHP Nginx MySQL Windows

WNMP environment building steps

Installation of three major parts

Nginx installation

  • Download address:
  • Select stable version:
  • Download File Name:
  • Unzip the package and enter the directory, such as D:\wnmp\nginx
  • Run nginx.exe
  • Open the browser and enter localhost in the address bar

    If this page appears, the installation is successful.

PHP installation

  • Download address:
  • Choose a non thread safe version
  • Download File:
  • Unzip the package and enter the directory, for example: D:\wnmp\php
  • Open cmd and run the command php -v
    If this page appears, the installation is successful.

MySQL installation

  • Download address:
  • Select download - > no thanks, just start my download

  • Download File:
  • Decompress the compressed package to prepare for subsequent configuration

Three piece configuration

Nginx configuration

  • Back up the nginx.conf file under the conf directory (for example, D:\wnmp\nginx\conf)
  • Modify nginx.conf file, some comments are not posted
#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
        location ~ \.php$ {
           root           D:/wnmp/www/localhost;
           fastcgi_index  index.php;
           fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
           include        fastcgi_params;

PHP configuration

  • Modify php.ini-development to php.ini in D:\wnmp\php directory,
  • Only part of the configuration will be displayed, others will be modified according to the needs of the project

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

; 7

; 8
date.timezone = Asia/Shanghai

MySQL configuration

  • MySQL installation directory D:\wnmp\mysql-8.0.18-winx64 modify my.ini file (if not, add manually)
# set basedir to your installation path
# set datadir to the location of your data directory

Three piece joint commissioning

PHP connection Nginx

  • Create directory D:\wnmp\www\localhost
  • Create a new file phpinfo.php, as follows
  • Start PHP process (Note: cmd needs to run with administrator privileges)
d:\wnmp\php>php-cgi.exe -b -c php.ini
  • Open Nginx
d:\wnmp\nginx>start nginx.exe
  • Open browser, enter http://localhost/phpinfo.php , view page display

    At this point, it indicates that PHP and Nginx are connected successfully.

PHP connection to MySQL

  • Open MySQL
d:\wnmp>net start mysql
  • Write the script test_mysql.php as follows:
$servername = "localhost";
$username = "root";
$password = "phpphp";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Detection connection
if ($conn->connect_error) {
    die("connection failed: " . $conn->connect_error);
echo "Successful connection";

  • Open browser, input, view page display

    At this point, the connection between PHP and MySQL is successful.

Common scripts and commands

The following two scripts * * start? Nginx. Bat and stop? Nginx. Bat * * are used to quickly start and stop nginx & PHP services.


@echo off
echo Starting PHP FastCGI...
D:\wnmp\nginx\RunHiddenConsole "D:\wnmp\php\php-cgi.exe" -b -c "D:\wnmp\php\php.ini"
echo Starting nginx...
D:\wnmp\nginx\RunHiddenConsole "D:/wnmp/nginx/nginx.exe" -p "D:/wnmp/nginx/"


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

Frequently used commands

  • View process
tasklist /fi "imagename eq nginx.exe"
tasklist /fi "imagename eq php-cgi.exe"
netstat -ano | findstr "3306"
  • Nginx overload configuration
nginx -s reload
  • Nginx elegant close
nginx -s quit
  • Nginx help command
nginx -h
  • Shut down MySQL service
net stop mysql
53 original articles published, 20 praised, 40000 visitors+
Private letter follow

Posted by M.O.S. Studios on Sat, 11 Jan 2020 00:12:52 -0800