Home > Article > Backend Development > Install and configure Nginx php mysql environment on win platform, nginxmysql_PHP tutorial
1. Preparation work
(1) PHP version 5.6.17 download address PHP official website Bangkejia download address
(2) Nginx version 1.8.0 download address Nginx official website Bangkejia download address
(3) MySQL version 5.7.10 MySQL official website Bangkejia download address
2.php installation and configuration
Directly decompress the downloaded php package and go to the wnmp directory on drive D (D:wnmp). Here, rename the decompressed folder to php5. Enter the folder and modify the php.ini-delelopment file to php.ini, and open it with Editplus or Notepad. Found
extension_dir = "ext" changed to extension_dir = "D:/wnmp/php5/ext"
Commonly used extensions, remove the leading ";"
extension=php_curl.dll extension=php_gd2.dll extension=php_mbstring.dll extension=php_mcrypt.dll extension=php_mysql.dll extension=php_mysqli.dll extension=php_pdo.dll extension=php_pdo_mysql.dll extension=php_xmlrpc.dll
nginx supports configuration, remove the leading ";"
;cgi.fix_pathinfo=1
;cgi.force_redirect = 1
;cgi.rfc2616_headers = 0. First remove the semicolon and then change it to cgi.rfc2616_headers = 1
3.Nginx installation configuration
Extract the downloaded package to D:wnmp and directly run nginx.exe in the directory to start.
1. There are 3 startup methods
(1) Double-click the nginx.exe icon, a black window will flash by, and the startup is completed.
(2) Go to the nginx directory from the command line and enter nginx to start. (Note: In this method, the command line window has no prompts and is locked)
(3) Go to the nginx directory from the command line and enter start nginx to start. This method will not lock
2. Modify the configuration to support PHP
Enter the conf directory of nginx, open the nginx configuration file nginx.conf, and find
location / { root html;#这里是站点的根目录 index index.html index.htm index.php; }
Change root html; to root D:/wnmp/www;
Go further down and find
# pass the PHP scripts to FastCGI serverlistening on 127.0.0.1:9000 # #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; #}
First remove the “#” in front, and also change root html; to root D:/wnmp/www;. Then change /scripts marked in red to "$document_root". "$document_root" here refers to the site path pointed to by "root". This is the changed version:
# pass the PHP scripts to FastCGI serverlistening on 127.0.0.1:9000 # 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; }
Save the configuration file and that’s it.
The nginx php environment has been initially configured, let’s take a look. We can enter the command
to start php and start nginx manually. Of course, you can also use scripts to achieve this.
First, unzip the downloaded RunHiddenConsole.zip package into the nginx directory. The function of RunHiddenConsole.exe is to automatically close the script after executing the command line script, and the process started from the script will not be closed. Then create a script and name it "start_nginx.bat".
@echooff
Invalid under REMWindows
REM set PHP_FCGI_CHILDREN=5
REM The maximum number of requests handled by each process, or set to a Windows environment variable
setPHP_FCGI_MAX_REQUESTS=1000
echo Starting PHPFastCGI...
RunHiddenConsole D:/wnmp/php5/php-cgi.exe -b 127.0.0.1:9000 -cD:/wnmp/php5/php.ini
echo Starting nginx...
RunHiddenConsole D:/wnmp/nginx/nginx.exe -p D:/wnmp/nginx
Create another script named stop_nginx.bat to shut down nginx
@echooff echo Stoppingnginx... taskkill /F /IM nginx.exe > nul echo Stopping PHPFastCGI... taskkill /F /IM php-cgi.exe > nul exit
In this way, our service scripts have been created. Double-click start_nginx.bat and see if there are two nginx.exe processes and one php-cgi.exe process in the process manager?
In this way, the nginx service is started, and php is also run in fastCGI mode.
Go to the site directory, create a new phpinfo.php file, and edit it
<?php echo phpinfo();?>
After saving, open the browser and enter "http://localhost/phpinfo.php", if you see
It means that the nginx php environment has been configured, haha~
4.MySQL installation and configuration
(Simple) After downloading the MySQL installation, go to next to install it.