Go to: install and configure Nginx + PHP5 on Windows

Source: Internet
Author: User
Go to Nginx + PHP5 installation and configuration in Windows. go to Nginx + PHP5 installation and configuration in Windows? It is a lightweight, high-performance HTTP webserver written in event-driven mode. Therefore, compared with Apache, Nginx is more stable, has better performance, and has simple configuration and low resource usage. Here is how to install and configure Nginx + PHP5 in Windows
Go to: install and configure Nginx + PHP5 in Windows

Nginx? It is a lightweight, high-performance Http WebServer written in event-driven mode. Therefore, compared with Apache, Nginx is more stable, has better performance, and has simple configuration and low resource usage. The following are the steps for installing Nginx and PHP5.2 in Windows 7.

Install PHP5

First? Http://www.php.net/downloads.php? Download the latest PHP5.2.9-2 Windows version, decompress to C: \ php5, the compressed package of php. ini-recommended, renamed php. ini, and then open modify several options:

1            2            3            4            5            6            7            8            9            10            11            12            13            
Error_reporting = E_ALL display_errors = On extension_dir = "C: \ php5 \ ext "? ; Dynamic expansion, you can remove the comments before extension as needed; such as loading PDO, MySQL extension = php_pdo.dll extension = php_pdo_mysql.dll? 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. HereNoCopy any file to the Windows directory. if necessary, you can add C: \ php5 to the PATH to facilitate PHP upgrade in the future.

Install Nginx

Starting from v0.7.52, Nginx has been released for Windows. you can download it from its official website:

Http://nginx.net

If you need an earlier version of Nginx for Windows, can you? Kevin Worthington? For the website.

I used 0.7.55. after downloading it, decompress and release the file to C: \ nginx.

So how to configure Nginx so that it can work with PHP?

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:

1                
c:/php5/php-cgi.exe -b 127.0.0.1:9000 -c c:/php5/php.ini

Another way is to use third-party tools such as PHP-FPM and cgi-fcgi. Apparently! It is extremely painful to use these tools in Windows. you may need Cygwin and other things. some people have done so, although I think it is self-seeking.

Next, start to modify the Nginx configuration file C: \ nginx \ conf \ nginx. conf, find the php-related part, and modify it as follows:

1                    2                    3                    4                    5                    
# pass the PHP scripts to FastCGI server listening on 127.0.0.1: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:

1                        2                        3                        4                        5                        6                        
# Connect to the local port 9000, the port here is the port opened by the PHP FastCGI Server, # Please be consistent with the port opened by the php-cgi.exe # When Nginx receives the php file request, will be automatically forwarded 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.

In addition, you need to modify the c: \ nginx \ conf \ fastcgi_params file and add a line:

1                            
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

It is important to modify php. ini and set cgi. fix_pathinfo = 1. otherwise, PHP cannot find the php script to be processed.

For some other settings, the master server:

1                                2                                3                                4                                5                                6                                7                                8                                9                                10                                11                                12                                13                                14                                
# 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 # The default 1024 value is not required for local development. change this value 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:

1                                    2                                    3                                    
autoindex on;                                    autoindex_exact_size on;                                    autoindex_localtime on;

OK, integrated

Create start_nginx.bat to start both PHP FastCGI and Nginx:

1                                        2                                        3                                        4                                        5                                        6                                        
@echo off                                        echo Starting PHP FastCGI...                                        RunHiddenConsole c:/php5/php-cgi.exe -b 127.0.0.1:9000 -c c:/php5/php.ini                                        ?                                        echo Starting nginx...                                        c:/nginx/nginx.exe

RunHiddenConsole.exe is a small program used to hide the DOS window. you can download it here.

After start_nginx.bat is enabled, there will also be a DOS window, but it can be safely disabled, and does not close Nginx and php-cgi.exe.

Similarly, stop_nginx.bat is used to disable:

1                                            2                                            3                                            4                                            5                                            6                                            
@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.

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.