Wnmp environment configuration (Windows + nginx + MySQL + PHP)

1. Packages to be prepared:
nginx: http://nginx.org Here I download the latest version of 1.11.13
PHP: http://windows.php.net/download (Note: PHP in nginx runs in fastcgi mode, so download PHP package of non ready-made security NTS)
runhiddenconsole: RunHiddenConsole.zip Used to write quick start and stop programs

2. Installation and configuration. Create a new directory D: wnmp
1. Installation and configuration of PHP:
decompress and rename the downloaded PHP package php-5.6.30-nts-win32-vc11-x64 to PHP5 to form the path D: wnmp Go down and find it

;extension=php_mysql.dll
;extension=php_mysqli.dll

Remove the front “;” and add MySQL extension to make PHP support mysql. Later, you can add other extensions as needed, all of which are to remove the semicolon.
Next, configure PHP to work with nginx. Find out; cgi.fix_ Pathinfo = 1, remove the semicolon. This step is very important. This is the CGI setting of PHP.

cgi.fix_pathinfo=1

2. Nginx installation and configuration:
unzip the downloaded nginx-1.11.13 package to the wnmp directory, named nginx. Enter the nginx/conf directory and open the configuration file nginx.conf , find

location/{
  root  html;  #This is the root directory of the site, in nginx/html
  index index.html index.htm;
}

Change to:

location/{
    root  D:/wnmp/www;  #Specify the site root directory as D:/wnmp/www
    index index.php index.html index.htm; # Add index.php, giving priority to parsing php files
}

Further down, find it

#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 previous “#”, then change root HTML; to root D/wnmp/www, and then change/scripts to $document_ Root, here’s “$document_ “Root” is the site path specified by “root” above. The results are as follows

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;
}

Just save the configuration file. In this way, the environment of nginx + PHP is initially configured. You can enter the command to start PHP, and start nginx manually, and create a new one in the directory D:: (wnmp) www phpinfo.php File to test whether it works.

3. Write quick start and stop scripts
to download the RunHiddenConsole.zip The files are decompressed and stored in the directory D/wnmp (or nginx), RunHiddenConsole.exe The function of the script is to automatically close the script after executing the command line script, and the process opened in the script will not be closed. Create a script named“ start.bat “, the content is as follows:

@echo off
REM Windows 
REM set PHP_FCGI_CHILDREN=5

REM Maximum number of requests per process, or set as a Windows environment variable
set PHP_FCGI_MAX_REQUESTS=1000

echo Starting PHP FastCGI...
RunHiddenConsole D:/wnmp/php5/php-cgi.exe -b 127.0.0.1:9000 -c D:/wnmp/php5/php.ini

echo Starting nginx...
RunHiddenConsole D:/wnmp/nginx/nginx.exe -p D:/wnmp/nginx

Create another one called“ stop.bat “To close nginx and PHP:

@echo off

echo Stopping nginx...
taskkill /F /IM nginx.exe > null

echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe > null

exit

After completion, the D/wnmp directory is as follows:

In this way, the service scripts are created. double-click start.bat You can see that there are two in the process manager nginx.exe Process and a PHP- cgi.exe Process.

3、 test: create a new file in the site directory D/wnmp/www phpinfo.php The contents are as follows:

<?php
	phpinfo();	
?>

After saving, the browser accesses“ http://localhost/phpinfo.php ”, see the following information, that windows nginx + PHP development environment has been configured successfully!

Testing MySQL database connection: please see another article about MySQL service. Under D/wnmp/www, create a new index.php The contents are as follows:

<?php 
	if (mysqli_connect("localhost","root","root")) {
		echo "successful!";
	}else{
		echo "error...";
	}
 ?>

Browser anti question“ http://localhost/index.php “, see the following prompt successful! It indicates that all wnmp development rings are configured successfully!

improvement: in step 3 above, when writing quick start script, use% ~ DP0 instead of absolute path D/wnmp .

@echo off
REM Windows
REM set PHP_FCGI_CHILDREN=5

REM Maximum number of requests per process, or set as a Windows environment variable
set PHP_FCGI_MAX_REQUESTS=1000

echo Starting PHP FastCGI...
RunHiddenConsole %~dp0/php5/php-cgi.exe -b 127.0.0.1:9000 -c %~dp0/php5/php.ini

echo Starting nginx...
RunHiddenConsole %~dp0/nginx/nginx.exe -p %~dp0/nginx

% – DP0 refers to the current drive letter plus path, which can only be used in batch file. Bat. works the same as% CD%, but% CD% can be used in batch files or on the command line.

In this way, when the wnmp folder path changes (such as moving from disk d to disk E), there is no need to change the script file.

Similar Posts: