0

I'm using CentOS 9 Stream on a VM, trying to setup my apache server to be able to show php content on the web. The server works fine when its just html, but I'm getting these errors (503 in the browser) when I try it with php. My httpd.conf is basically the bare minimum to run a server with virtual hosts, and the only thing I added was the SetHandler for the php files. I'm not very familar with php, but from my understanding what it does is when the server gets a requiest for a php file it calls the php-fpm service to handle it.

Both the httpd and php-fpm services are running and I set the SELinux bool httpd_can_network_connect to 1 as I read this could result in a 503.

/var/log/httpd/error.log says:

[proxy:error] [pid 4807:tid 4812] (111)Connection refused: AH00957: FCGI: attempt to connect to [::]:8000 (*) failed
[proxy_fcgi:error] [pid 4807:tid 4812] [client 192.168.122.1:60494] AH01079: failed to make connection to backend: (null)

my httpd.conf:

Listen                  80
Listen                  8080
User                    apache
Group                   apache
ServerRoot              /etc/httpd
ErrorLog                /var/log/httpd/error.log


LoadModule              mpm_event_module        modules/mod_mpm_event.so
LoadModule              systemd_module          modules/mod_systemd.so
LoadModule              unixd_module            modules/mod_unixd.so
LoadModule              authz_core_module       modules/mod_authz_core.so
LoadModule              dir_module              modules/mod_dir.so

LoadModule              proxy_module            modules/mod_proxy.so
LoadModule              proxy_fcgi_module       modules/mod_proxy_fcgi.so


<Directory />
        Require all denied
</Directory>

<Directory /var/www/html>
        Require all granted
</Directory>

<Directory /srv/www>
        Require all granted
</Directory>


<VirtualHost 192.168.122.60:80>
        DocumentRoot "/var/www/html"
        DirectoryIndex  index.html
</VirtualHost>

<VirtualHost 192.168.122.60:8080>
        DocumentRoot "/srv/www"
        DirectoryIndex  index.php

        <FilesMatch \.php$>
            SetHandler "proxy:fcgi:/run/php-fpm/www.sock"
        </FilesMatch>
</VirtualHost>

and my www.conf:

listen = /run/php-fpm/www.sock
listen.owner = apache
listen.group = apache
listen.allowed_clients = 127.0.0.1

SOLUTION: As AlexD pointed out the problem was apache was trying to connent through localhost instead of the socket. I was able to make it work by either changing my config files to listen on 127.0.0.1:9000 If I want to use the unix socket I have to change the httpd.conf like this:

<Proxy "unix:/run/php-fpm/www.sock|fcgi://php-fpm">
   ProxySet disablereuse=off
</Proxy>

<FilesMatch \.php$>
   SetHandler proxy:fcgi://php-fpm
</FilesMatch>

Found this config here: https://tecadmin.net/install-apache-php-fpm-centos-8/

2 Answers 2

0

The error message (111)Connection refused: AH00957: FCGI: attempt to connect to [::]:8000 (*) failed indicates that your Apache is attempting to connect to a backend on a TCP port 8000 while your PHP-FPM is listening on a unix socket /run/php-fpm/www.sock. You probably forgot to restart Apache.

3
  • I restarted httpd after every config change. How else could I fix this if this is the problem? At least I understand the problem a little bit better, thanks!
    – bejgli
    Jan 20, 2022 at 19:18
  • If you restarted Apache then the config you posted doesn't match the running configuration for some reason.
    – AlexD
    Jan 21, 2022 at 6:19
  • I changed to config files to listen on 127.0.0.7:9000 and I was able to get to my site. With port 8000 the php-fpm service wouldnt start.
    – bejgli
    Jan 21, 2022 at 9:38
0

Another possible answer (at least, this happened to me). My configuration was completely correct, and Apache had been started without a problem after confiruration. Unfortunately, this process does not automatically start PHP-FPM, which requires the following line:

service php8.1-pfm start

(That's on PHP v8.1 on Ubuntu 23.04, your version may differ). In my case, it goes into a supervisord config file to be usable in a docker container.)

All the other configurations were left at their defaults. For completeness, here are the relevant bits of Dockerfile. Thanks to https://www.howtoforge.com/how-to-enable-http-2-in-apache/

RUN apt-get install -y php8.1-fpm
...
RUN a2enmod http2
RUN a2dismod php8.1
RUN a2enconf php8.1-fpm
RUN a2enmod proxy
RUN a2enmod proxy_fcgi
RUN a2dismod mpm_prefork
RUN a2enmod mpm_event

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .