Home > Backend Development > PHP Tutorial > php+nginx environment configuration

php+nginx environment configuration

不言
Release: 2023-03-23 07:48:01
Original
19720 people have browsed it

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>

##php+ nginx environment configuration

<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.zip

2. 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 the

php 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/Shanghai

Search for "enable_dl", Found: enable_dl = Off Change to enable_dl = On

Search for "cgi.force_redirect"; cgi.force_redirect = 1 First remove the semicolon in front and then change it to cgi.force_redirect = 0

Search 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>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login

<br>

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

After specifying the ext path of php earlier, just remove the corresponding ";" in front of the required expansion package. Open php_mysql.dll and php_mysqli.dll here to let php support mysql. Of course, don’t forget that a very important step is to copy the

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>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
<br>

<br>

;cgi.fix_pathinfo

=1We remove the semicolon here.

<br>

cgi.fix_pathinfo

=1

This step

Very 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

php+nginx environment configuration

<br>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login

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

#}

php+nginx environment configuration

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>

php+nginx environment configuration

<br>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login

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;

}

php+nginx environment configuration

##Save the configuration file and that’s it.

 

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.

<br>

<br>

<br>

#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>

##

<br>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
php+nginx environment configuration@echo

off

##REM

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

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

php+nginx environment configuration##Create another one named stop_nginx The .bat script is used to shut down nginx

<br>

#

<br>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
php+nginx environment configuration@echo

off

echo Stopping nginx... taskkill

/F /IM nginx .exe > nul

## echo Stopping PHP FastCGI...taskkill

/

F /IM php-cgi.exe > nul

exit

php+nginx environment configuration

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>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login

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

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template