Search code examples
phpapacheconfigfpm

SetHandler directive failing in VirtualHost but OK in main config


The setup is CentOS 7, Apache 2.4.6, php-fpm 5.6 and 7.3 (via remi repo).

I recently converted my default phpmod setup to php-fpm and got PHP 5.4.16 working just fine. Now I'm trying to enable PHP 7.3 as an option per Virtual Host. I got php73-php-fpm installed and running then looked at the Apache side.

My /etc/httpd/conf.d/php.conf includes the following directive:

<FilesMatch \.php$>
#    SetHandler application/x-httpd-php
    SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>

That works fine for all hosts. Then I added this <FilesMatch> directive inside one Virtual Host .conf file:

<VirtualHost *:80>
    ServerName www.sittingduck.co.nz
    ServerAlias sittingduck.co.nz
    DocumentRoot /var/www/sittingduck.co.nz/public_html
    ErrorLog /var/log/httpd/sittingduck.co.nz.error.log
    CustomLog /var/log/httpd/sittingduck.co.nz.requests.log combined
    <FilesMatch \.php$>
        SetHandler "proxy:fcgi://127.0.0.1:9073"
    </FilesMatch>
</VirtualHost>

When I restart the httpd server, the following shows up in the ErrorLog specified above.

[proxy:error] [pid 17061] (111)Connection refused: AH00957: FCGI: attempt to connect to 127.0.0.1:9073 (*) failed
[proxy_fcgi:error] [pid 17061] [client 54.36.148.97:33788] AH01079: failed to make connection to backend: 127.0.0.1

After verifying that both php-fpm servers were indeed running...

tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      16794/php-fpm: mast 
tcp        0      0 127.0.0.1:9073          0.0.0.0:*               LISTEN      17510/php-fpm: mast 

...I next tried switching over the main php.conf to the 9073 port. When I do that, all sites work and I can confirm (using a phpinfo page on the site above) that I am running on PHP 7.3.

What am I missing here? The Virtual Host configs are definitely loaded after php.conf, as the error would suggest, and the fpm is definitely in working order, and the port clearly is accessible.

I feel like there's some rule or caveat to the way I have the directives defined. Any help would be appreciated.


Solution

  • The problem was http versus https. My configuration file was defining *:80 but I was unthinkingly viewing the https version of the test page. The *:443 Virtual Host was in a separate configuration file that had been added after installation by the certbot tool. A manual edit of this extra file resolved the problem.

    I'm still not quite sure about why the errors in the log at the start and then not later, but possibly this was due to specific pages being requested over http and/or https at different times.