The running environment is windows server 2008 64-bit system.
Installation directory D:/wnmp
Mysql 5.7 Download Address: https://dev.mysql.com/downloads/mysql/5.7.html#downloads
(This article chooses 5.7.25 | Microsoft Windows | All | Windows (x86, 64-bit), ZIP Archive)
php7.2 Download Address: https://windows.php.net/downloads/releases/php-7.2.17-nts-Win32-VC15-x64.zip
(This article chooses php-7.2.17-nts-Win32-VC15-x64)
nginx download address: http://nginx.org/download/nginx-1.15.11.zip
(This article chose the mainline version nginx/Windows-1.15.11)
-
Install mysql 5.7
- mysql 5.7 compressed package was downloaded from the official website and decompressed under D:/wnmp.
- Create a database configuration file: my.ini
Create my.ini file in the D:/wnmp/mysql5.7 directory and write the following
[client] port=3306 # Setting up port 3306 [mysql] default-character-set=utf8 # Setting the default character set for mysql client [mysqld] port=3306 basedir="D:\wnmp\mysql5.7" # Set up the installation directory of mysql datadir="D:\wnmp\mysql5.7\data" # Set up the storage directory of mysql database, where the database tables will be stored character-set-server=utf8 # The character set used by the server defaults to the latin1 character set of 8 bits encoding default-storage-engine=MyISAM # Default storage engine to be used when creating new tables #Support INNODB engine mode. Modify it to default-storage-engine=INNODB. #If INNODB mode fails to start, delete the log file at the beginning of ib in the data directory and restart. sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" max_connections=512 query_cache_size=0 table_cache=256 tmp_table_size=18M thread_cache_size=8 myisam_max_sort_file_size=64G myisam_sort_buffer_size=35M key_buffer_size=25M read_buffer_size=64K read_rnd_buffer_size=256K sort_buffer_size=256K innodb_additional_mem_pool_size=2M innodb_flush_log_at_trx_commit=1 innodb_log_buffer_size=1M innodb_buffer_pool_size=47M innodb_log_file_size=24M innodb_thread_concurrency=8
- Initialize and start mysql service
- Running cmd with administrator privileges
- Enter the directory D:/wnmp/mysql5.7/bin
- Initialize and generate data files. (If you execute any of the following commands, you will find that a data folder has been generated in the D:/wnmp/mysql 5.7 directory)
(The following command is recommended for not setting the root password) mysqld --initialize-insecure (The following command randomly generates the root password, which is generated in my.ini configuration file datadir Items are in a file with the suffix err in the directory where they are located. For example, in my my.ini configuration file, my configuration Datadir= "D: wnmp mysql5.7 data" so I need to use D: wnmp mysql5.7 data Look for the file with the suffix err in the directory, then open the file with the suffix err and search for "A" temporary password is generated for root@localhost:"You can see randomly generated passwords) mysqld --initialize
- Install mysql service
mysqld -install
- Start the mysql service
net start mysql (corresponding service shutdown command is net stop mysql)
- Log in to mysql (you will be prompted to enter your password and return directly if you don't have it set)
mysql -u root -p
- Set the root password (you need to log in to MySQL before you can execute the following command. The following: Set mysql's root account password to 123456
// Method 01, set password for root@localhost = password('123456'); // Method 02, mysqladmin -u root -p password 123456
-
Install nginx
- Download the nginx compressed package on the official website and decompress it in the D:/wnmp directory after downloading.
- Double-clicking nginx.exe directly in the D:/wnmp/nginx directory can start the server directly, and the following commands can also be executed to start the service
// Startup service start nginx // Stop nginx nginx -s stop // Reload configuration file nginx -s reload
- Input localhost directly into the browser. If welcome to nginx appears, the installation of nginx is successful!
-
Install php7.2
- Download the php7.2nts (non-thread-safe) compressed package on the official website, and then decompress it in the D:/wnmp directory.
- Copy a php.ini-development file and change the file name to php.ini
- Modify the php.ini configuration file
01,Search keywords“ date.timezone",find ;date.timezone = First go to the front semicolon and then change it to date.timezone = Asia/Shanghai //Open a series of required extensions such as extension=php_mysql.dll, extension=php_mysqli.dll, etc. 02,Modify extension dll The directory where the file is located extension_dir="D:\wnmp\php-7.2.1-nts\ext" 03,CGI Set up enable_dl = On cgi.force_redirect = 0 cgi.fix_pathinfo=1 fastcgi.impersonate = 1 cgi.rfc2616_headers = 1
-
Configuring nginx enables nginx to parse php
- Open the nginx.conf configuration file in the directory D: wnmp nginx conf
- Modify nginx.conf configuration file
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; gzip on; server { listen 80; server_name localhost; location / { root D:\wnmp\www; index index.html index.htm index.php; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ \.php$ { root D:\wnmp\www; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } }
Actually, two locations have been changed:
The first place:
take
location / { root html; index index.html index.htm; }
Modified to become
location / { root D:\wnmp\www; index index.html index.htm index.php; }
Second places:
take
#location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #}
Modified to become
location ~ \.php$ { root D:\wnmp\www; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
- Start php's built-in cgi program and listen on port 9000 for requests from nginx (executed in the cmd command)
D:\wnmp\php7.2nts\php-cgi.exe -b 127.0.0.1:9000-c D:\wnmp\php7.2nts\php.ini
- Restart nginx.
- Test. Create a new index.php file in the D: wnmp www directory, write a PHP test code, and then use the browser to visit the localhost to see if there is any content.
-
Windows uses the Run Hidden Console button to start nginx,php-cgi services
- First, Baidu Networks downloaded Run Hidden Console software. (It's hard to find on the Internet, here is ready.)
The link address is: https://pan.baidu.com/s/1G4xfGBiIc2KekHTlvOMCzA
Extraction code: prdk
The function of RunHiddenConsole.exe is to automatically close the script after executing the command-line script, while the process opened from the script is not closed.
- Create a new start.bat to write the following (note that the following path address needs to be replaced by your own actual software path address)
@echo off set php_home=C:\wnmp\php-7.2.17-nts-Win32-VC15-x64 set nginx_home=C:\wnmp\nginx-1.15.10 REM Windows Invalid under REM set PHP_FCGI_CHILDREN=5 REM The maximum number of requests processed by each process, or set to Windows environment variable set PHP_FCGI_MAX_REQUESTS=1000 echo Starting PHP FastCGI... C:\wnmp\RunHiddenConsole\RunHiddenConsole.exe %php_home%\php-cgi.exe -b 127.0.0.1:9000 -c %php_home%\php.ini echo Starting nginx... C:\wnmp\RunHiddenConsole\RunHiddenConsole.exe %nginx_home%\nginx.exe -p %nginx_home%
- Create a new stop.bat to write the following
@echo off echo Stopping nginx... taskkill /F /IM nginx.exe > nul echo Stopping PHP FastCGI... taskkill /F /IM php-cgi.exe > nul exit
- In addition, it should be noted that. Do not add MySQL startup to the script above, which may cause the MySQL service to fail to restart. So far, I have added the command "net start mysql" to the start.bat script. The reason why the MySQL service can not be restarted has not been found.