Configuration of nginx + php environment in Windows

Source: Internet
Author: User
1. The application package to be prepared first. Nginx: nginxWindows-1.0.4php: (nginx php is run in FastCGI mode, so we download non-thread security is the php package of ETS) (also used) RunHiddenConsole: 2. installation and configuration. 1

1. The application package to be prepared first. Nginx: nginx/Windows-1.0.4 php: 2. installation and configuration. 1

1. The application package to be prepared first.

Nginx: nginx/Windows-1.0.4

Php: (php under nginx is run in FastCGI mode, so we download non-thread security, that is, the php package of ETS)

(Also used) RunHiddenConsole:

2. installation and configuration.

1) install and configure php.

Directly decompress the downloaded php package to the wnmp directory (D: \ wnmp) on the D Drive. Here, rename the decompressed folder to php5. Go to the folder and modify the php. ini-recommended file to php. ini, and open it with Editplus or Notepad ++. Find

extension_dir = "./ext"


extension_dir = "D:/wnmp/php5/ext"

Look down and find again


After specifying the php ext path, you only need to remove the ";" corresponding to the extension package. Open php_mysql.dll and php_mysqli.dll to allow php to support mysql. Of course, do not forget the important step is to put libmysql under the php5 directory. copy the dll file to the C: \ Windows directory. You can also specify the path in the system variables. Of course, here I chose a more convenient method ^_^.

Now, php supports mysql.

Next we will configure php so that php can be combined with nginx. Find


We will remove the title here.


This step is very important. Here is the CGI setting of php.

2) install and configure nginx.

Decompress the downloaded nginx-1.0.4 package to the wnmp directory of the d disk and rename it nginx. Next, configure nginx to work with php. Go to the nginx conf directory, open the nginx configuration file nginx. conf, and find

Location/{root html; # Here is the site's root directory index index.html index.htm ;}

Change root html; To root D:/wnmp/www;

Next, find

# pass the PHP scripts to FastCGI server listening on ~ \.php$ {#    root           html;#    fastcgi_pass;#    fastcgi_index  index.php;#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;#    include        fastcgi_params;#}

First remove "#" And change root html; To root D:/wnmp/www ;. Change the/scripts marked in red to "$ document_root". Here, "$ document_root" refers to the site path referred to by "root". This is changed:

# pass the PHP scripts to FastCGI server listening on ~ \.php$ {      root           D:/wnmp/www;      fastcgi_pass;      fastcgi_index  index.php;      fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;      include        fastcgi_params;}

Save the configuration file.

The nginx + php environment has been initially configured. We can enter the command

To start php and manually start nginx. Of course, you can also use the script.

First, decompress the downloaded runhiddenconsole.zippackage to the nginxdirectory. runhiddenconsole.exe automatically closes the script after executing the command line script, but the process enabled from the script is not closed. Create a script named "start_nginx.bat". Edit it in Notepad ++.

@ Echo offREM in Windows the REM set PHP_FCGI_CHILDREN is invalid = 5REM the maximum number of requests processed by each process, or set it to the Windows environment variable set PHP_FCGI_MAX_REQUESTS = 1000 echo Starting PHP FastCGI... runHiddenConsole D:/wnmp/php5/php-cgi.exe-B 9000-c D:/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 disable nginx.

@echo offecho Stopping nginx...  taskkill /F /IM nginx.exe > nulecho Stopping PHP FastCGI...taskkill /F /IM php-cgi.exe > nulexit

This is the case.

In this way, all our service scripts have been created. Double-click start_nginx.batto check whether the process manager has two nginx.exepaths and a php-cgi.exe process?

In this way, the nginx service is started and php runs in fastCGI mode.

Go to the site directory, create a phpinfo. php file, and edit it in it.


After saving, open the browser and enter "http: // localhost/phpinfo. php". If you see

The nginx + php environment has been configured ~

Problems I encountered during installation:

1. I have installed apache and used port 80. What should I do?

Solution: Method 1: If you do not want to change the nginx http default port (that is, 80), do not start apache when using nginx.

Method 2: Modify the listen port value under the server (for example, my listen 81) in nginx. conf to access the webpage using apache and nginx at the same time.

2. nginx can be started normally. You can access the page http: // 81/index.html, but cannot access the PHP file ???

My configuration is all configured by a dedicated user, but I find that php-cgi.exe cannot be started in the resource manager. Why ???

Find the cause: Enter netstat-anob In the cmd command window to check that port 9000 is occupied by KugouService, so it cannot be started properly. Close codoy and click start_nginx.bat. Everything is OK.

After nginx is installed, you can check whether the nginx and mysql are properly installed. Check the phpinfo () information, check whether php and nginx are properly connected, run the php file, and do it manually !!!!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.