The content of this article is the configuration of PHP and nginx environments. I share it with everyone here and give a reference to friends in need
<br>
<br>
<br>
1. First, you need to prepare the application package. nginx: nginx/Windows-1.0.4 php:php-5.2.16-nts-Win32-VC6-x86.zip (php under nginx runs in FastCGI mode, so We download the non-thread-safe php package of nts) (will also be used) RunHiddenConsole: RunHiddenConsole.zip2. Installation and configuration. 1) Installation and configuration of php. Directly decompress the downloaded php package and go to the PHP directory on drive D (D:\PHP). Here, rename the decompressed folder to php7. Enter the folder and modify the php.ini-recommended file to php.ini, and open it with Wordpad. Find thephp configuration file php.ini and save it.
<br>
Search for "extension_dir" and find: e;xtension_dir = "ext" First remove the semicolon in front and change it to extension_dir = "C:\wnmp\php \ext"Search for "date.timezone" and find: ;date.timezone = Remove the preceding semicolon first and then change it to date.timezone = Asia/ShanghaiSearch for "enable_dl", Found: enable_dl = Off Change to enable_dl = OnSearch for "cgi.force_redirect"; cgi.force_redirect = 1 First remove the semicolon in front and then change it to cgi.force_redirect = 0Search for " fastcgi.impersonate", find: ;fastcgi.impersonate = 1 Remove the preceding semicolon Search for "cgi.rfc2616_headers", find: ;cgi.rfc2616_headers = 0 Remove the preceding semicolon first and then change it to cgi. rfc2616_headers = 1 Search for "php_mysql" and find: "extension=php_mysql.dll and extension=php_mysqli.dll Remove the previous ";"extension=php_mysql.dll and extension=php_mysqli. dll (supports MYSQL database) Please change other configurations according to your own needs<br>
##Among them. php_mysql means: <br> <br> ##;extension=php_mysql.dll;extension=php_mysqli.dll libmysql.dll file in the php5 directory to the C:\Windows directory. You can also specify the path in the system variable. Of course, I chose it here for more convenience. Method ^_^. #At this point, php can already support mysql. Next we configure php so that php can be combined with nginx. Find
##<br>
<br>
<br>
;cgi.fix_pathinfo=1We remove the semicolon here.
<br>
cgi.fix_pathinfo=1
This stepVery important, here are the CGI settings of php. 2) Installation and configuration of nginx.
Extract the downloaded nginx-1.0.4 package to the PHP directory on drive D and rename it to nginx. Next, we configure nginx so that it can work with php. Enter the nginx conf directory, open the nginx configuration file nginx.conf, and find
<br>##location
/ { root html; #This is the root directory of the site index index.html index.htm;}Change root
html; to root D :/PHP/hostdoc (that is, the file where you will put the code in the future);
Go down further and find# pass the PHP scripts to FastCGI server listening 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 :/PHP/hostdoc;. Then change the /scripts marked in red to "$document_root". The "$document_root" here refers to the site path pointed to by the previous "root". This is the changed version: <br> pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 #location ~ \.php$ { 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; } <br> <br> <br> <br> off Not valid under Windows REM set PHP_FCGI_CHILDREN=5REM The maximum number of requests handled by each process, or set For Windows environment variables 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 <br> off echo Stopping nginx... taskkill /F /IM nginx .exe > nul ## echo Stopping PHP FastCGI...taskkill F /IM php-cgi.exe > nul exit After it is done, it will look like this 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 <br> <br> php phpinfo();?> After saving, open the browser Enter "http://localhost/phpinfo.php". If you see , it means that the nginx+php environment has been configured, haha~ <br><br>
<br>
3. 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, we can also use a script to achieve this.
#4. 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. 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 from Processes started in the script are not closed. Then create a script, named "start_nginx.bat", we edit it in Notepad++
<br>
The above is the detailed content of php+nginx environment configuration. For more information, please follow other related articles on the PHP Chinese website!