CentOS and Apache-connected PHP multi-version coexistence scheme implementation _php example

Source: Internet
Author: User
Tags documentation fpm

Under the Apache Integration fastcgi mode operation of the PHP-FPM, it seems that little online materials, even the English version of the material is less. As long as it is php-fpm, basically with Nginx collocation. Check a large number of relevant information, write this summary.

Apache has a number of fastcgi support solutions: 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 is a formal introduction of the httpd 2.4+ version, with a simple line of proxypassmatch instructions.

mod_fcgi

The mod_fcgi module itself is managed by the fastcgi process, and it does not need to use the PHP-FPM management process. Core configuration parameters

LoadModule fcgid_module modules/mod_fcgid.so
<virtualhost *:80> documentroot
  "/var/www/html/site_1"
  ServerName "www.yourhost.com"
  DirectoryIndex index.html index.php
  #php. ini storage directory, Linux usually do not need to
  #FcgidInitialEnv PHPRC "d:/php"
  # set Php_ Fcgi_max_requests is greater than or equal to fcgidmaxrequestsperprocess, preventing the php-cgi process from exiting Fcgidinitialenv before all requests are processed
  Php_fcgi_max_ REQUESTS 1000
  #php-cgi maximum number of requests per process
  fcgidmaxrequestsperprocess 1000
  #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 1000
  <directory "/var/www/html/site_1" >
    Options +execcgi
  </Directory>
</VirtualHost>

Several fcgid* instructions, which are optimized for use, are only examples here, to adjust the values according to the actual situation. Refer to mod_fcgi official documentation

Several characteristics 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
The PHP-CIG process runs as an Apache user, and the PHP program writes files with the permissions of the Apache user (rather than the php-fpm file as the PHP-FPM user, the default is nobody), which allows for a higher consistency in directory rights management.
mod_fastcgi

Although CentOS 6.x is Apache 2.2, fortunately someone has successfully transplanted: https://github.com/ceph/mod-proxy-fcgi we can use directly; more fortunate that it has entered Epel source, directly yum installation can , do not want to match the Epel source, directly download the RPM package installation can also (example http://mirrors.ustc.edu.cn/epel/6/x86_64/)

Of course, you can recompile the installation of Apache 2.4, so that there is a direct mod_proxy_fcgi can be used, but here or keep the original version of the same, save the compilation workload.

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 to the actual needs. In fact, in line with the Mod_proxy module syntax, the difference is to change the HTTP protocol to the FCIG protocol.

The above is the Apache integrated PHP-FPM mode of Operation FastCGI, next to the Yum installed PHP to do configuration changes.

Yum installs the 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, you enable a different PHP run mode at each site.

The above is the way of handling.

[Known issues]: Raw Directory address forwarding
There is a troubling problem unresolved that feels a bit like a module bug:

For configuring the DirectoryIndex index.php directory, if the subdirectory does not have index.php, the above proxypassmatch will do fastcgi forwarding, you will see the PHP-FPM 404 response, rather than 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 automatic indexing function fails for proxypassmatch matching directories. (Of course it doesn't matter if you don't open the autoindex.) Usually not open in the production environment)

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

Workaround: In each directory, place a index.html to avoid fpm-php processing empty requests

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.