Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the Multi-version coexistence Scheme of PHP connected with Apache under CentOS

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you the "CentOS how to achieve the PHP multi-version coexistence program connected with Apache", the content is easy to understand, well-organized, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to connect with Apache under CentOS PHP multi-version coexistence program" this article.

There are several fastCGI support schemes under apache: at least mod_fcgi, mod_fastcgi (git), mod_proxy_fcgi and so on. Both of these modules are a bit old, especially since mod_fastcgi has not been updated since 2007, leaving it aside, in fact, it has not been used. The mod_proxy_fcgi module is officially introduced in the version of httpd 2.4 + through a concise line of ProxyPassMatch instructions.

Mod_fcgi

The mod_fcgi module itself is managed by the fastCGI process, so there is no need to use php-fpm to manage the process. Core configuration parameters

The directory where LoadModule fcgid_module modules/mod_fcgid.so DocumentRoot "/ var/www/html/site_1" ServerName "www.yourhost.com" DirectoryIndex index.html index.php # php.ini is stored. Under Linux, there is usually no need for # FcgidInitialEnv PHPRC "D:/php" # to set PHP_FCGI_MAX_REQUESTS greater than or equal to FcgidMaxRequestsPerProcess. Prevent php-cgi processes from exiting FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000 # php-cgi maximum number of requests per process FcgidMaxRequestsPerProcess 1000 # php-cgi maximum number of processes FcgidMaxProcesses 3 # maximum execution time FcgidIOTimeout 600 FcgidIdleTimeout 600 # php-cgi path FcgidWrapper / usr/local/php7/bin/php-cgi .php AddHandler fcgid-script .php FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000 Options + ExecCGI before all requests are processed

Several Fcgid* instructions are used for optimization. Here is only an example, and the value should be adjusted according to the actual situation. For more information, please see the mod_fcgi official documentation.

Several characteristics of using mod_fcgid

The php-fgi process is started and managed by the apache module, and there is no need to configure php-fpm

When the php-cig process runs as the apache user, the files written by the php program have permissions for the apache user (unlike php-fpm, which is owned by the php-fpm user and the default is nobody), which is more consistent in directory rights management.

Mod_fastcgi

Although apache 2.2 is available under CentOS 6.x, fortunately some people have successfully transplanted it: https://github.com/ceph/mod-proxy-fcgi can be used directly; luckily, it has entered the epel source and can be installed directly with yum; if you don't want to match the Epel source, you can download the rpm package and install it directly (sample http://mirrors.ustc.edu.cn/epel/6/x86_64/)

Of course, you can recompile and install apache 2.4, so that mod_proxy_fcgi can be used directly, but here the original version remains the same, saving the compilation workload.

Refer to mod_proxy_fcgi official documentation and integrate php-fpm configuration instructions

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 syntax of the mod_proxy module, except that it changes the http protocol to the fcig protocol.

The above is the fastCGI running in apache integrated php-fpm mode. Next, you need to make some configuration changes to the php installed by yum.

The php configuration file / etc/httpd/conf.d/php.conf for yum installation, with the following line

AddHandler php5-script .php

We want to enable different php for different sites, the above line is for the global .php file assigned to the php module processing, we comment out this line. Instead, a different php operation mode is enabled at each site.

The above is how to deal with it.

[known problem]: bare directory address forwarding

There is a perplexing problem that has not been solved, which feels a bit like module bug:

For a directory configured with DirectoryIndex index.php, if the subdirectory does not have index.php, the above ProxyPassMatch will still be forwarded by fastCGI, and you will see the 404 response from php-fpm instead of the 403 page from apache. But the previous rule does not forward the url of the naked directory, so it feels like bug

Furthermore, for directories that ProxyPassMatch matches, the apache automatic indexing function fails. (of course, it doesn't matter if you don't turn on autoindex. Usually not open in a production environment)

Otherwise, there seems to be no serious consequences, or I am not aware of it.

Solution: place an index.html in each directory to prevent fpm-php from handling empty requests

The above is all the contents of the article "how to realize the multi-version coexistence scheme of PHP connected to Apache under CentOS". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report