Installation and configuration of nginx and PhP5 in Windows

Source: Internet
Author: User
Tags php windows

The following are the steps for installing nginx and php5.2 in Windows 2003, The nginx performance in Windows is much worse than that in Linux/unsecure. .

Install PhP5
First, load the latest http://www.php.net/downloads.php Windows version from the PHP5.2.9-2, decompress to c: \ PHP, the compressed package of PHP. ini-recommended, renamed PHP. ini, and then open modify several options:

Error_reporting = e_all
Display_errors = on
Extension_dir = "C: \ PHP \ Ext"

; Dynamic expansion. You can remove the comments before extension as needed;
Such as loading PDO and MySQL
Extension = php_pdo.dll
Extension = php_pdo_mysql.dll

; CGI settings
CGI. force_redirect = 1
CGI. fix_pathinfo = 1
CGI. rfc2616_headers = 1

Pay attention to dependencies when loading extensions in PHP. For example, php_exif.dll requires php_mbstring.dll. You must put php_mbstring.dll in front of php_exif.dll to load it successfully. Some extensions depend on additional DLL files, such as PHP 5.0 + and php_mysqli.dll depend on libmysql. dll, while php_oci8.dll requires you to install the Oracle 8 client. If you are not familiar with these dependencies, refer to the install.txt file in the installation package.

Search sequence of dependent files: first, the directory where php.exe is located. If it is in ISAPI mode, the startup location of the web server will be searched, such as the bin directory of Apache; the second is the directory in the Windows PATH environment variable. Do not recompile any files in the Windows directory. If necessary, you can add c: \ PhP5 to the path, which will facilitate PHP upgrade in the future.

Install nginx
From v0.7.52, nginx began to release the Windows version of nginx, you can download from its official website: http://nginx.net
I used 0.8.37. After downloading it, decompress and release the file to D: \ nginx.

Configure PHP FastCGI
Nginx needs to work with the FastCGI server to process requests. You can run the PHP FastCGI server in either of the following ways:
RunC:/PHP/php-cgi.exe-B 127.0.0.1: 9000-C:/PHP. ini to start PHP FastCGI

Modify the nginx configuration fileD \ nginx \ conf \ nginx. confFind the PHP-related part and modify it as follows:
# Pass the PHP scripts to FastCGI server listening on Fig: 9000
Location ~ \. Php $ {
Root D:/public_html;
Include PHP. conf;
}
Root: $ document_root refers to your PHP scripts root directory, which is set as your website root directory. In Windows, you must note the root path. It is best to use "/" as the path separator instead of the default "\" in windows. Otherwise, problems may occur. For example, this path: D: \ public_html \ test does not work. nginx throws a 500 error because \ t in \ test is parsed as a tab. Of course, you can add a backslash escape, for example, D: \ public_html \ test.

PHP. conf is a file created by myself to save the PHP configuration. In fact, there are only three lines of commands in it:
# Connect to port 9000 of the local machine. The port here refers to the port opened by the PHP FastCGI server,
# Be consistent with the port opened by the php-cgi.exe
# When nginx receives a PHP file request, it will automatically forward it to the PHP FastCGI server.
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Include fastcgi_params;
Create an independent PHP. save the configuration in conf to streamline nginx. conf: when multiple virtual hosts are configured in nginx, PHP needs to be configured for each virtual host, and the master configuration file will become repeated and bloated.

Need to modifyD: \ nginx \ conf \ fastcgi_paramsFile, add a row:
Fastcgi_param script_filename $ document_root $ fastcgi_script_name;

And modifyPHP. ini, SetCGI. fix_pathinfo = 1Otherwise, PHP cannot find the PHP script to be processed.

For some other settings, the master server:
# Number of processes enabled by default
Worker_processes 1;
Error_log logs/error. log;
# Error_log logs/error. Log notice;
# Error_log logs/error. Log Info;
# PID logs/nginx. PID;
Events {
# Maximum number of connections processed by a process,
# For local development, the default 1024 value is not required. Here it is changed to 64
Worker_connections 64;
}

If the default index. php index.html or other homepage files do not exist under a directory, nginx will throw a 403 error. If you need to list this directory, you can go to HTTP {... }, Add the following command:
Autoindex on;
autoindex_exact_size on;
autoindex_localtime on;

start_nginx.bat , used to start both PHP FastCGI and nginx:
@ echo off
echo starting PHP FastCGI...
runhiddenconsole C:/PHP/php-cgi.exe-B 127.0.0.1: 9000-C:/PHP. INI
echo starting nginx...
D:/nginx/nginx.exe
runhi Ddenconsole.exe is a small Program used to hide dos windows. You can download runhiddenconsole.zip (1.01 KB) here ).
after start_nginx.bat is enabled, there will also be a DOS window, but it can be safely disabled and nginx and php-cgi.exe will not be closed.
stop_nginx.bat :
@ echo off
echo stopping nginx...
taskkill/f/IM nginx.exe> NUL
echo stopping PHP FastCGI...
taskkill/f/IM php-cgi.exe> NUL
exit
the basic configuration is complete here.

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: info-contact@alibabacloud.com 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.