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
<Directory /usr/lib/cgi-bin>
    Order allow,deny
    Allow from all

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" 

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

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/"

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

  • no, you must use the sethandler method. – ezra-s Jan 14 '18 at 4:24

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.

  • So the point of the question was to keep using the directive "AddHandler", not the directive and parameters as it was before. I sincerily do not understand the motives. – ezra-s Jan 19 '18 at 7:55
  • The motives are that most of us work with users, and it's easier for the user to get used to this: AddHandler ${application/x-httpd-phpXX} .php (or something similar) than the SetHandler method – plamer Jan 19 '18 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.