How PHP works in Nginx and Apache servers

Source: Internet
Author: User

One of the great advantages of PHP5 's CGI approach is the built-in fastcgi support, which simply indicates that the bound address and port parameters can be run in fastcgi manner, as follows:

Php-cgi-b 127.0.0.1:9000

Configuring the Nginx PHP FastCGI

Save the following as a fastcgi_params file, saved under/usr/local/nginx/conf (Ubuntu can be saved under/etc/nginx), and he sets the basic environment variables for our fastcgi module:

#Fastcgi_paramsFastcgi_param Gateway_interface cgi/1.1; Fastcgi_param server_software nginx;fastcgi_param query_string $query _string;fastcgi_param REQUEST_METHOD $request _method;fastcgi_param content_type $content _type;fastcgi_param content_length $content _length;fas Tcgi_param script_filename $document _root$fastcgi_script_name;fastcgi_param script_name $fastcgi _script_name;f       Astcgi_param Request_uri $request _uri;fastcgi_param document_uri $document _uri;fastcgi_param document_root $document _root;fastcgi_param server_protocol $server _protocol;fastcgi_param remote_addr $remote _addr;fas        Tcgi_param remote_port $remote _port;fastcgi_param server_addr $server _addr;fastcgi_param server_port $server _port;fastcgi_param server_name $server _name;#PHP only, required if PHP is built with--enable-force-cgi-redirectFastcgi_param Redirect_status 200;

Pay particular attention to the "Fastcgi_script_name" line, where php-cgi specifically needs this information to determine the location of the PHP file.

In addition, you need to open the Cgi.fix_pathinfo option in the php-cgi configuration file (Ubuntu on this profile located in/etc/php5/cgi/php.ini):

Cgi.fix_pathinfo=1;

This allows the php-cgi to use the script_filename variable normally.

Next in the Nginx configuration for PHP files configured to use the FASTCGI process to execute:

Server {    index index.php;    Root  /usr/local/nginx/html;      ~. *. php$ {        /usr/local/nginx/conf/fastcgi_params;  # Please set it according to the path you saved         fastcgi_index index.php;        Fastcgi_pass  # Please configure according to the address and port of your fastcgi binding     }}

How PHP works in Nginx and Apache servers

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.