Home  >  Article  >  Backend Development  >  Building php plus nginx environment under Windows

Building php plus nginx environment under Windows

不言
不言Original
2018-04-09 16:51:329287browse

This article shares with you about setting up PHP and nginx environment under Windows. Friends in need can refer to

Scenario description:
In order to make it easier to learn nginx when there is a local Apache php environment, we built nginx locally and switched the project to the nginx environment. Therefore, this article will not introduce the installation of PHP, but only the installation of nginx and switching from apache to nginx environment. Regarding php construction, you can refer to: https://blog.csdn.net/qq_21386275/article/details/78271375

1. Nginx installation
1. Download
Download Address: http://nginx.org/en/download.html. As shown below, download the stable version
Building php plus nginx environment under Windows

2. Unzip
Unzip it to the directory where you installed nginx. I unzipped it to the same directory as apache. The directory after decompression is as follows.
Building php plus nginx environment under Windows

3. Installation
Double-click nginx.exe or command line to execute nginx, as shown below:
Building php plus nginx environment under Windows

4. Verify whether the installation is successful
Enter localhost in the browser, and the following page appears, indicating that the access is successful
Building php plus nginx environment under Windows5. Problems encountered
① Since there is apache locally, port 80 may be occupied ( Usually apache, you need to kill its process first). When a 10013 error occurs during command line execution, it means that port 80 is occupied.
Solution 1:
Step 1
netstat -aon|findstr "80" //View the process occupying port 80
Building php plus nginx environment under Windows

Steps 2

 tasklist|findstr "9924"  //根据上边查出来的9924端口,查看端口对应的服务名称

Building php plus nginx environment under Windows

Step 3
End the process in the task manager.

Solution 2:
If the above method does not work, directly modify the port monitored by nginx in the configuration, and then restart. Add port 81 to the access path, localhost:81
Building php plus nginx environment under Windows

2. Modify the nginx and php.ini configuration so that the local project can run in the nginx environment
1. Modify php .ini configuration
Change the following configuration to the following values, and remove the ; symbol.

enable_dl = On
cgi.force_redirect = 0 
cgi.fix_pathinfo=1fastcgi.impersonate = 1cgi.rfc2616_headers = 1extension_dir = "./ext"

, and then execute the following instructions in cmd:

php-cgi.exe -b 127.0.0.1:9000 -c D:\IdeMix442_jcp\php-5.5.27-Win32-VC11-x64\php.ini//后边路径切换成你本地php.ini文件路径

2. Modify the nginx.conf configuration
Mainly modify the server configuration on line 35, as follows, other unchanged The configuration is not listed

server { 
        listen 80; 
        server_name benxiaohai.ren; #本地访问项目的域名

        location / {
            root   D:/benxiaohai/Source;#项目的地址
            index  index.html index.htm index.php;
            autoindex on; #开启网站目录文件列表功能,访问目录时列出其中的文件列表,默认不开启
        }

        location ~ \.php$ {
            root   D:/benxiaohai/Source;#项目的地址
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;#$document_root是root的值
            include        fastcgi_params;
        }
    }

3. Add hosts configuration

127.0.0.1  benxiaohai.ren

4. Then you will see the following process in the task manager:
Building php plus nginx environment under Windows

5. Access the local project: benxiaohai.ren
Note: Do not use "\" in the project address in the nginx.conf configuration, which is prone to errors (the log reports The system cannot find the file specified) . If you use "/"

3. nginx virtual host configuration
Follow step 2 to modify the nginx.conf configuration, copy a server configuration, and then add your hosts

server{ ...}
server{ ...}
127.0.0.1  你的域名 #例如127.0.0.1  benxiaohai.ren

Related recommendations:

How to build Apache PHP environment under Windows

PHP environment building tutorial - detailed explanation with pictures and text

The above is the detailed content of Building php plus nginx environment under Windows. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn