The PHP Multi-version coexistence scheme with Apache connected under CentOS is detailed, _php tutorial

Source: Internet
Author: User
Tags apache php nginx server

The implementation of the PHP multi-version coexistence scheme, which is connected to Apache under CentOS,


In Apache under the integration of fastcgi mode running PHP-FPM, it seems that few related materials on the Internet, even the English version of the material is also few. As long as the PHP-FPM, basically with the Nginx collocation. Check a large number of relevant information, write a summary of this article.

There are several fastcgi support options under Apache: At least mod_fcgi, mod_fastcgi (git), mod_proxy_fcgi, and so on. These two modules are a bit old, especially mod_fastcgi since 2007 has not been updated, slightly off, in fact, useless. The MOD_PROXY_FCGI module was formally introduced in the httpd 2.4+ version, with a simple one-line proxypassmatch instruction.

mod_fcgi

MOD_FCGI module itself is to do fastcgi process management, use it does not need to use PHP-FPM management process. Core configuration parameters

LoadModule fcgid_module modules/mod_fcgid.so
 
  
   
    documentroot "/var/www/html/site_1"  ServerName " Www.yourhost.com "  directoryindex index.html index.php  #php. ini storage directory, which is usually not required under Linux  #FcgidInitialEnv PHPRC "d:/php"  # setting php_fcgi_max_requests is greater than or equal to fcgidmaxrequestsperprocess, preventing the php-cgi process from exiting  before processing all requests Fcgidinitialenv php_fcgi_max_requests  #php-cgi Maximum number of requests per process  Fcgidmaxrequestsperprocess  php-cgi maximum number of processes  fcgidmaxprocesses 3  #最大执行时间  fcgidiotimeout  fcgididletimeout  php-cgi path  fcgidwrapper/usr/local/php7/bin/php-cgi. php  AddHandler fcgid-script. PHP  Fcgidinitialenv php_fcgi_max_requests  
  
   
    
       Options +execcgi  
  
   
 
  

Several fcgid* directives are used for optimization, and here are just examples to adjust the values according to the actual situation. See MOD_FCGI official documentation for details

Several features of using mod_fcgid
The PHP-FGI process is started and managed by the Apache module and does not need to be configured PHP-FPM
In the PHP-CIG process to run as Apache user, the PHP program writes the file, its permissions for the Apache user (and not like PHP-FPM write the file for PHP-FPM users all, the default is nobody), so that in the directory Rights Management consistency higher.
mod_fastcgi

Although the CentOS 6.x is Apache 2.2, it has been successfully transplanted: https://github.com/ceph/mod-proxy-fcgi We can use directly, and fortunately it has entered the Epel source, directly yum installation can be Do not want to match Epel source, direct download RPM package installation can also (example http://mirrors.ustc.edu.cn/epel/6/x86_64/)

Of course, you can recompile and install Apache 2.4, so that there is a direct mod_proxy_fcgi can use, but here still keep the original version of the same, eliminating the workload of compiling.

Refer to MOD_PROXY_FCGI official documentation to integrate PHP-FPM configuration directives

Proxypassmatch "^/myapp/.*\.php (/.*)? $" "fcgi://localhost:9000/var/www/"
The syntax is simple, similar to configuring a reverse proxy, and can be modified as needed. In fact, it is consistent with the Mod_proxy module syntax, where the HTTP protocol is changed to the FCIG protocol.

The above is the Apache integrated PHP-FPM mode running fastcgi, next to the Yum installation of PHP configuration changes.

Yum installed PHP configuration file/etc/httpd/conf.d/php.conf, which has the following line

AddHandler php5-script. php

We want to enable different PHP for different sites, the above line is to the global. php file assigned to the PHP module processing, we put this line commented out. Instead, different PHP run modes are enabled at each site.

The above is the way of processing.

[Known issues]: Bare Directory address forwarding
There is a puzzle problem that is not resolved and feels a bit like a module bug:

For the DirectoryIndex configured index.php directory, if its subdirectories do not have index.php, the above Proxypassmatch will still do fastcgi forwarding, you will see the PHP-FPM 404 response, and not the Apache Response 403 page. But the previous rule does not forward the URL of this bare empty directory, so it feels like a bug

Furthermore, the Apache auto-indexing function fails for proxypassmatch matching directories. (Of course it doesn't matter if you don't open autoindex.) Normally not open in a production environment)

Other, there seems to be no serious consequences, or I did not realize (?).

Workaround: Place a index.html in each directory to avoid fpm-php processing of empty requests

Articles you may be interested in:

    • Installation of multi-version PHP coexistence with Nginx server using Linux system

http://www.bkjia.com/PHPjc/1084597.html www.bkjia.com true http://www.bkjia.com/PHPjc/1084597.html techarticle under the CentOS connection with Apache PHP multi-version coexistence scheme implementation, in the Apache under the integration of fastcgi mode running PHP-FPM, seems to be very few related materials on the Internet, even the English version of the material is also few. Only ...

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