About the apache2.4 module mod_php mod_fastcgi mod_fcgi

Source: Internet
Author: User

failure : Loading fastcgi module under apache2.4 Web server, always unable to load

analysis : 1, find the document process found, Apache also has another function similar module, mod_fcgid, many people say, Fcgid is better than fastcgi compatibility, because Mod_ FastCGI is a fastcgi.com project and complies with the fastcgi licensing terms. Mod_fcgid is a project owned by the Apache Foundation and uses the Apache-2.0 license terms. Therefore, not only the main responsible units are different, their licensing methods are also different

MOD_FASTCGI's authorization is not a standard free/open source license clause, so it appears to be incompatible with other licensing terms, coupled with the factors of the Linux  distribution Suite management policy, making Mod_ FastCGI is difficult to fully access all distribution official libraries. Online will find that mod_fastcgi has almost no further development, so that many people on the network to recommend Mod_fcgid. In fact, this is the biggest misunderstanding. Officially, FastCGI protocol is a lightweight and mature communication protocol, so there is little need for additional features, and the current work is mainly on defect repair, and there is almost no development progress.

3, Although mod_fastcgi and Mod_fcgid both support fastcgi protocol, but the concept of design is different. Mod_fcgid's idea is to quickly end the FASTCGI server and produce one quickly. This method differs from FastCGI protocol's original intention, and FastCGI protocol is hoping to allow long-running request. In PHP applications, for example, Bytecode/opcode caches, such as APC, Eaccelerator, or xcache, are often used to speed up PHP performance. But in order to share the cache, it means that the process/request must be in the same shared cache, but not across different fastcgi or FCGI process. Therefore, in the design, only one PHP process can be allowed to start, then spawn multiple children process, so that children can enjoy the bytecode/opcode of the parent.

4,The official description of Mod_fcgid is:

mod_fcgid isa high performance alternative to mod_cgiorMod_cgid, which starts a sufficient number instances of the CGI program to handle concurrent requests, andThese programs remain running to handle further incoming requests. It isfavored by the PHP developers, forexample, asa preferred alternative to running mod_phpinch-process, delivering very similar performance.5, so it doesn't matter which module to use

Processing process :

1, according to the configuration normal in the Apache configuration file conf-enable configuration php5-fpm but found always unable to load,

2, after analysis, it is found that the CGI mode and mod_php Way is different, mod_php is to access the PHP file as an executable to run, so it directly run any file, can have multiple portals, and fastcgi is different, It sends the request only to a portal PHP file, which is forwarded by this file. Therefore, the MOD_PHP5 module in the apache2.4 environment and mod_fastcgi in conflict with each other, so a2dismod php5 shut down the module, FASTCGI will be able to load the normal

504 faults :

according to many articles on the web search on the principle of failure, is hesitant back-end PHP processing time is too long, the backend application server has not returned to the previous server, this is the previous server has timed out, so the previous server has returned the timeout result to the client, but in fact, The back end is still in normal inability PHP program, the solution is very simple, is the php-fpm.conf

Request_terminate_timeout = 10 time is set more than the previous server timeout time is small, so that the backend server if the processing is not finished, PHP-FPM will re-terminate php-fastcgi re-open a new process, and return to the previous segment, Re-process the request so that there is no 504 error,


about two ways to load fastcgi modules :

1, the first, not applicable to the MOD_FASTCGI module, continue to use MOD_PHP5, but the need for additional modules is the Mod_proxy proxy, so all PHP requests have been URL form request, in passing some regular rules, forwarded to the backend PHP-FPM Server, so, there is a certain problem, is the development if the PHP file type is hidden, then the regular will become extremely difficult to write

2, the second, is to install the mod_fastcgi module directly, and in conf-enable/php5-fpm.conf loaded into Apache, and then forwarded to the backend of the PHP-FPM server, for the reasons described in the " processing process " above


finally post the configuration :

The system is Ubuntu14.04

Apache2/conf-enable/php5-fpm.conf

<ifmodule mod_fastcgi.c> AddHandler php5-fcgi. php Action php5-fcgi/php5-fcgi ALIAS/PHP5-FCGI/USR/LIB/CG I-BIN/PHP5-FCGI # Fastcgiexternalserver/usr/lib/cgi-bin/php5-fcgi-socket/var/run/php5-fpm.sock-pass-header Authorization fastcgiexternalserver/usr/lib/cgi-bin/php5-fcgi-host 127.0.0.1:9000-pass-header Authorization- Idle-timeout 60-flush</ifmodule>

Modify the configuration file and point to the backend PHP5-FPM server

Also enable A2enmod fastcgi module default configuration is good

Finally, I see from phpinfo that the server API is fpm/fastcgi

Here's the configuration to illustrate:

The timeout period for fascgi is greater than max_execution_time (PHP execution time) and request_terminate_timeout (CGI subprocess processing request time),

The server will report a 500 error if the time-out relationship between the three is mistaken

PS: Finally spit a bit of Apache Web server, this configuration file is a mess of a force, directory Che cut, originally very simple a 504 error caused such a problem, 4 days is also a harvest


About the apache2.4 module mod_php mod_fastcgi mod_fcgi

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.