WNMP environment building steps
Installation of three major parts
Nginx installation
- Download address: http://nginx.org/en/download.html
- Select stable version:
- Download File Name: nginx-1.16.1.zip
- 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: https://windows.php.net/download#php-7.4
- Choose a non thread safe version
- Download File: php-7.4.1-nts-Win32-vc15-x64.zip
- 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: https://dev.mysql.com/downloads/mysql/
- Select download - > no thanks, just start my download
- Download File: mysql-8.0.18-winx64.zip
- 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 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 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
[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 configuration
- MySQL installation directory D:\wnmp\mysql-8.0.18-winx64 modify my.ini file (if not, add manually)
[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
- For detailed configuration, please refer to the MySQL configuration section of this document: https://blog.csdn.net/lylfv/article/details/82284750
Three piece joint commissioning
PHP connection Nginx
- Create directory D:\wnmp\www\localhost
- Create a new file phpinfo.php, as follows
<?php phpinfo();
- Start PHP process (Note: cmd needs to run with administrator privileges)
d:\wnmp\php>php-cgi.exe -b 127.0.0.1:9000 -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:
<?php $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.
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
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