大网数据广告活动
服务器运维问答

How to use AddHandler in httpd 2.4 for php-fpm version change

· 52CE 我爱测

I have the following setup for httpd 2.2 (CentOS 6) with mod_fastcgi and php-fpm : LoadModule fastcgi_module modules/mod_fastcgi.so <IfModule mod_fastcgi.c> AddHandler application/x-httpd-php71 .php Action application/x-httpd-php…

问题原文

原帖链接 · plamer · CC BY-SA 3.0

I have the following setup for httpd 2.2 (CentOS 6) with mod_fastcgi and php-fpm:

LoadModule fastcgi_module modules/mod_fastcgi.so
<IfModule mod_fastcgi.c>
AddHandler application/x-httpd-php71 .php
Action application/x-httpd-php71 /php71-fcgi
Alias /php71-fcgi /usr/lib/cgi-bin/php71-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php71-fcgi -socket /var/run/php71.sock -pass-header Authorization

Action application/x-httpd-php72 /php72-fcgi
Alias /php72-fcgi /usr/lib/cgi-bin/php72-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php72-fcgi -socket /var/run/php72.sock -pass-header Authorization
</IfModule>
<Directory /usr/lib/cgi-bin>
    Order allow,deny
    Allow from all
</Directory>

But in httpd 2.4 (CentOS 7) there is mod_proxy_fcgi and since mod_fastcgi is not available I don't have FastCgiExternalServer I'm trying something like this:

AddHandler application/x-httpd-php70 .php
Action application/x-httpd-php70 /php70-fpm virtual
Alias /php70-fpm /php70-fpm
ProxyPassMatch "/php70-fpm" "unix:/var/run/php70.sock|fcgi://localhost"

Action application/x-httpd-php72 /php72-fpm virtual
Alias /php72-fpm /usr/local/php-fpm/php72-fpm
ProxyPass "/usr/local/php-fpm/php72-fpm" 
"unix:/var/run/php72.sock|fcgi://localhost"

<Directory /usr/local/php-fpm>
    Require all granted
</Directory>

I know it's wrong (and not working...) but for the moment I'm not able to find (if there is one) a way to keep using AddHandler application/x-httpd-phpXX .php in .htaccess for version change with CentOS7/Apache 2.4. I know I could use:

<FilesMatch "\.php$">
    SetHandler  "proxy:unix:/var/run/php70.sock|fcgi://localhost/"
</FilesMatch>

but I'm looking for a way to keep my .htaccess the same.

已采纳解答

原帖链接 · plamer · CC BY-SA 3.0

After searching a bit I found out that there is "Define" directive that could be used:

I've added in fcgi.conf (included in httpd.conf) the following:

Define php70 "proxy:unix:/var/run/php70.sock|fcgi://localhost"

And after that used the defined "php70" for a AddHandler in .htaccess:

AddHandler ${php70} .php

That's the closest thing I've managed to find. Hope it helps someone.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-01-12)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。