[nginx] Construction of nginx+php7 under Windows 2008

Regarding the construction of php, previously in "[php] local development environment deployment and helloworld" ( https://blog.csdn.net/yongh701/article/details/41789753 ) and "[php] Configuring Apache2.4 under Windows2003 and php5.4" ( https://blog.csdn.net/yongh701/article/details/47080057 ) are mentioned. One is a fool-like installation package, and the other is to build php on the apache server. php can also be built directly by using the iis server of Windows. For details, see "[php] IIS configuration php5.4 under Windows 2003" ( https://blog.csdn.net/yongh701/article/details/47083231 ). Unfortunately, this is not a mainstream php collocation method. Now, it should be said that a long time ago, most of the more professional websites have used nginx to carry PHP. The following will directly use an example to illustrate how to use nginx to configure php under windows2008.

 

1. Download of nginx and php

Before downloading nginx and php, go to Microsoft's official website ( https://www.microsoft.com/en-us/download/details.aspx?id=48145 ) to install vc15. It should be noted that whether your computer is a 32-bit system or a 64-bit system, install whichever one is. Generally, win2008 is 64-bit, so here I downloaded x64.

After downloading, the obtained vc_redist.x64.exe is a one-click fool installation file that you don't even need to choose the installation directory, and you shouldn't choose it. php7 needs vc15 runtime library to run, which is why win2003 and winxp only support php5.4, because php5.4 starts with vc9, and windows2003 and xp can only support vc8.

Then download nginx. In fact, nginx is the same thing as IIS and Apache, which means tomcat. We first have to go to his official website ( http://nginx.org/ ) to download nginx. After entering, select download and find the stable version of windows. After downloading, I got something called nginx-1.14.0.zip.

Then go to the official website of php ( http://www.php.net/ ) and download the latest php7. Whether it is thread-safe or not, it doesn't matter because we don't use the IIS version to configure PHP. However, it should be noted that your computer is a 32-bit system or a 64-bit system. Generally, win2008 is 64-bit, so here I downloaded the x64 php. After downloading, I got something called php-7.2.5-Win32-VC15-x64.zip.

 

Second, the configuration of nginx and php

1. After downloading, it is recommended to create a new folder, here I am called PHP, and extract nginx-1.14.0.zip and php-7.2.5-Win32-VC15-x64.zip here respectively. Then create a new folder called WWW, which will be where we store our php website in the future. As shown.

2. Open nginx.conf in .\PHP\nginx-1.14.0\conf, which is also the configuration file of nginx. The modified parts are concentrated in lines 43~46 and 65~71. First, remove the # in front of lines 65~71. Modify the root on lines 44 and 66 to the directory path we just created and will be used to put the website in the future. Remember to enclose the path with double quotation marks "". After this, change the index on line 45 and fastcgi_index on line 68 to index.php. Fastcgi_param on line 69 is changed to SCRIPT_FILENAME $document_root$fastcgi_script_name;. After making changes, save and exit. In this way, nginx is set up.

3. Next, set up php, which is almost the same as the previous php settings.

(1) Make a copy of php.ini-development and rename it to php.ini. Then use notepad, preferably notepad or something to open it.

(2) Search for "extension_dir" and find: extension_dir = "ext" Go to the previous semicolon and change it to extension_dir = "your php directory\ext", here is extension_dir = "C:/Program Files/PHP/php -7.2.5-Win32-VC15-x64/ext".

Search for "enable_dl" and find: enable_dl = Off Change to enable_dl = On

Search for "cgi.force_redirect", change cgi.force_redirect = 1 to the previous semicolon and then change to cgi.force_redirect = 0

Search for "date.timezone" and find: ;date.timezone = , go to the previous semicolon and change to date.timezone = Asia/Shanghai

Search for "fastcgi.impersonate" and find: ;fastcgi.impersonate = 1 , remove the preceding semicolon

Search for "cgi.rfc2616_headers" and find: ;cgi.rfc2616_headers = 0, go to the previous semicolon and change to cgi.rfc2616_headers = 1

Then search for "extension" and find: "extension=pdo_mysql and extension=mysqli, remove the preceding semicolon ";" to support the MYSQL database. I will not repeat the Mysql database here, see "[Mysql] Mysql for details. Installation, Deployment and Graphics" ( https://blog.csdn.net/yongh701/article/details/42648763 ).

At this point, the configuration of php is complete.

In the WWW folder we just created, create a new index.php, the content is classic:

<?php
	phpinfo();
?>

 

3. Startup of nginx and php

Add the system32 folder to the system variable first, so as to avoid some command prompts: "not an internal command". It is the same as matching java with php. Right-click on "Computer", Properties->Advanced System Settings->Advanced->Environment Variables, find Path->Edit in the system variables below, add a semicolon to the original path, and add C:\Windows\System32. All the way to "OK".

(1) Open php first

Use win+r, run a cmd, use cd to enter your php directory first, I am cd C:\Program Files\PHP\php-7.2.5-Win32-VC15-x64, then php-cgi.exe -b 127.0.0.1:9000 -c php.ini Open php, as shown in the figure.

(2) Open nginx again

The same is to use win+r, then run a cmd, use cd to enter your nginx directory first, I am cd C:\Program Files\PHP\nginx-1.14.0, and then enter nginx.exe, as shown in the figure.

Then hang these two cmds, open a browser, enter http://localhost or 127.0.0.1, you will see the following php.info page, which proves that the layout is complete!

 

Fourth, the end of nginx and php

You can create a new stop.bat with notepad or notepad, write the following statement, and run it. Or enter directly in cmd line by line, you can close nginx and php.

taskkill /F /IM nginx.exe > nul 
taskkill /F /IM php-cgi.exe > nul  
exit  

 

Note: Also refer to the article "[nginx] nginx migration, path setting and one-key startup under windows2008" ( https://my.oschina.net/u/3776619/blog/1805163 ) is more exciting!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325435768&siteId=291194637