I'm running the latest stable Docker Desktop for Windows on Windows 10.
I've written a docker-compose
file (see below) that builds separate containers, based on Centos 6 with SCL, one for httpd24-httpd (Apache) and one for rh-php56-php-fpm (PHP-FPM). The containers start up fine with the services reporting an OK status. If I ping a container from the other it resolves it fine. If I visit the index.html page Apache is happy and brings it up.
Apache is currently set to use proxy:fcgi:phpfpm:9000
but if I try to load a php file Apache returns a 503 error. I have tried a number of different connection options e.g proxy:fcgi:127.0.0.1:9000 -- 0.0.0.0:9000 -- 172.20.0.3:9000
(this being the phpfpm ip from docker) however Apache is just logging:
[proxy:error] [pid 60:tid ...] (...)Connection refused: AH00957: FCGI: attempt to connect to 172.20.0.3:9000 (*) failed [proxy_fcgi:error] [pid 60:tid ...] [client 172.20.0.1:44546] AH01079: failed to make connection to backend: ...
I've also tried it with a proxypassmatch and still no joy.
<IfModule proxy_module>
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://php:9000/var/www/html/$1
</IfModule>
mod_proxy, mod_proxy_http and mod_proxy_fcgi are being loaded by Apache.
PHP-FPM is obviously also being configured. I've generally had this just set to listen on port 9000
but did also try :::9000
During the build in the development.php.dockerfile I've added:
EXPOSE 9000
and, as you can see in the compose file, httpd is linked to phpfpm so by my reckoning they should have total knowledge of each other and apache should be able to reach phpfpm:9000
Can anyone please help me work out why this isn't working?? It's driving me round the twist. Many many thanks.
docker-compose:
version: '2'
services:
httpd:
build:
context: .
dockerfile: ./docker/development.httpd.Dockerfile
environment:
- APACHE_RUN_USER=apache
- APACHE_RUN_GROUP=apache
- APACHE_LOG_DIR=/var/log/httpd24
- APACHE_RUN_DIR=/opt/rh/httpd24/root/var/run/httpd
- APACHE_LOCK_DIR=/opt/rh/httpd24/root/var/lock
- [email protected]
- APACHE_SERVERNAME=foo.bar
- APACHE_SERVERALIAS="foo.foo.bar www.foo.bar"
- APACHE_DOCUMENTROOT=/var/www/html
volumes:
- ./data/www/html:/var/www/html
ports:
- "10180:80"
tty: true
networks:
- front-tier
phpfpm:
build:
context: .
dockerfile: docker/development.php.Dockerfile
environment:
- PHPFPM_RUN_USER=apache
- PHPFPM_RUN_GROUP=apache
- PHPFPM_LISTEN=9000
- PHPFPM_PM=dynamic
- PHPFPM_PM_MAX_CHILDREN=50
- PHPFPM_PM_START_SERVERS=5
- PHPFPM_PM_MIN_SPARE_SERVERS=5
- PHPFPM_PM_MAX_SPARE_SERVERS=35
- PHPFPM_LOG_DIR=/var/log/rh-php56-php-fpm
volumes:
- ./data/www/html:/var/www/html
tty: true
networks:
- front-tier
- back-tier
mysql:
build:
context: .
dockerfile: docker/development.mysql.Dockerfile
volumes:
- ./data/db:/usr/tmp/db/
- mysql:/var/lib/mysql
expose:
- 3306
ports:
- "10133:3306"
tty: true
networks:
- back-tier
volumes:
mysql:
networks:
front-tier:
driver: bridge
back-tier:
driver: bridge
www.conf
[...]
user = apache
group = apache
listen = 9000
listen.allowed_clients = httpd
[...]
00-custom.conf
[...]
<VirtualHost *:80>
[...]
<Directory "/var/www/html">
Options -Indexes +FollowSymlinks +MultiViews
AllowOverride All
Require all granted
</Directory>
<FilesMatch \.php$>
SetHandler "proxy:fcgi://php:9000"
</FilesMatch>
[...]
</VirtualHost>
UPDATE Issue was with PHP-FPM configuration file. I didn't realise it but rh-php56-php-fpm from SCL was creating 2 directories of conf files. I was modifying /opt/rh/rh-php56/register.content/etc/opt/rh/rh-php56/php-fpm.d/www.conf but the service was using /etc/opt/rh/rh-php56/php-fpm.d/www.conf
I should have made clear the full filepaths in the question!
I also removed listen.allowed_clients = httpd
as it was causing a Broken pipe AH01074 Apache error. Using the container IP was fine but I don't want to head down that route. Either way not important.
Issue resolved.
The configurations were all correct but I was modifying the wrong www.conf file. rh-php56-php-fpm created 2 directories of conf files. I was modifying /opt/rh/rh-php56/register.content/etc/opt/rh/rh-php56/php-fpm.d/www.conf instead of /etc/opt/rh/rh-php56/php-fpm.d/www.conf which was used by the service.