Hola:
Avanzando (a paso de caracol como veis) con el tema de mi web, estoy montando mi entorno local de desarrollo y he preferido hacerlo con tecnología de contenedores (Docker en este caso porque Rkt se me complicó mucho) para no enmarranar mi ya enmarranada máquina.
Total, que estuve mirando y me atrajeron los contenedores de Apache y PHP-FPM de Bitnami, que los han desarrollado bajo una mini-debian que utiliza muy pocos megas, cosa lógica para los contenedores. Pensé, y acerté, que tener por un lado Php y por otro Apache me podría dar problemas pero… bueno, parece que la documentación no era mala, así que… adelante, que narices.
Descrito el entorno, os pego el docker-compose.yml que hace funcionar los contenedores:
version: '2'
services:
apache:
image: 'bitnami/apache:latest'
depends_on:
- phpfpm
networks:
- red_cont
labels:
kompose.service.type: nodeport
ports:
- '80:80'
- '443:443'
volumes:
- ./apache:/bitnami/apache
- ./portal:/opt/bitnami/apache/htdocs
#- datos_apache
phpfpm:
image: 'bitnami/php-fpm:7.1'
ports:
- '9000:9000'
networks:
- red_cont
volumes:
- ./php:/bitnami/php
networks:
red_cont:
driver: bridge
Hasta ahí, bien, los contenedores se crean y se levantan sin ningún problema y, de los registros que después os pondré, parece que se comunican sin problemas.
Como el Php-FPM no esta en el mismo sitio que Apache, hay que configurar este para que «lo busque», esta es la parte relevante de la configuración, en el contenedor de Bitnami se encuentra en bitnami.conf:
# Default Virtual Host configuration.
<VirtualHost _default_:80>
ServerName mucharuina.local
DocumentRoot "/opt/bitnami/apache/htdocs"
<Directory "/opt/bitnami/apache/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
# Esta es la directiva con la que le decimos que el servidor Php esta en
# otro contenedor
#AddType application/x-httpd-fastphp5 .php
#Action application/x-httpd-fastphp5 /php5-fcgi
#Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
#AddHandler php-cgi .php
#Action php-cgi /php-fcgi/php5-fcgi
#FastCGIExternalServer /php5.fcgi -host 127.0.0.1:9000 Authorization
<Proxy "fcgi://phpfpm:9000" retry=0 timeout=300>
# <Proxy "fcgi://localhost:9000/" retry=0 timeout=300>
# <Proxy "fcgi://phpfpm/" retry=0>
# <Proxy "fcgi://127.0.0.1/" enablereuse=on max=10>
ProxyFCGIBackendType GENERIC
#ProxyFCGIBackendType FPM
ProxySet timeout=300
# ProxyPassMatch no puede estar dentro de Proxy, Apache casca.
# ProxyPassMatch ^/(.*\.php)$ fcgi://phpfpm:9000/opt/bitnami/apache/htdocs/$1
# ProxyPassMatch ".*\.php(/.*)?$" "fcgi://phpfpm:9000" enablereuse=on
</Proxy>
#
<FilesMatch "\.php$">
# Enganchamos con el contenedor de Php-fm
SetHandler "proxy:fcgi://phpfpm:9000/"
#SetHandler php-cgi
#SetHandler "proxy:fcgi://localhost/:9000"
</FilesMatch>
<LocationMatch "^(.*\.php)$">
ProxyPass fcgi://phpfpm:9000/opt/bitnami/apache/htdocs
</LocationMatch>
#RewriteRule . fcgi://phpfpm:9000/%1 [L,P]
# Error Documents
ErrorDocument 503 /503.html
# Niveles de registro
LogLevel trace6
</VirtualHost>
Como podéis ver he probado ya innumerables cosas (al principio pensaba que tenía Php-FPM 5, pero he comprobado que no, que es la versión 7.
En la configuración de Apache he activado los modulos mod_proxy y mod_proxy_fcgi.
A continuación pongo la configuración de Php-FPM, el archivo www.conf:
# grep -v \; conf/php-fpm.d/www.conf
[www]
user = daemon
group = daemon
listen = 9000
listen.allowed_clients =
pm = ondemand
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
include=/opt/bitnami/php/conf/environment.conf
include=/opt/bitnami/php/conf/common.conf
Estoy probando con el index.php más sencillo del mundo:
<? php
phpinfo();
?>
La página no carga, y muestra este error en el navegador:
Service Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
Additionally, a 503 Service Unavailable error was encountered while trying to use an ErrorDocument to handle the request.
El registro de Apache muestra esto en el momento de intentar cargar la página:
[Sat Jul 15 12:21:25.625217 2017] [core:trace5] [pid 39] protocol.c(645): [client 172.20.0.1:49286] Request received from client: GET /index.php HTTP/1.1
[Sat Jul 15 12:21:25.625291 2017] [http:trace4] [pid 39] http_request.c(420): [client 172.20.0.1:49286] Headers received from client:
[Sat Jul 15 12:21:25.625300 2017] [http:trace4] [pid 39] http_request.c(424): [client 172.20.0.1:49286] Host: localhost
[Sat Jul 15 12:21:25.625306 2017] [http:trace4] [pid 39] http_request.c(424): [client 172.20.0.1:49286] User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0
[Sat Jul 15 12:21:25.625311 2017] [http:trace4] [pid 39] http_request.c(424): [client 172.20.0.1:49286] Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
[Sat Jul 15 12:21:25.625316 2017] [http:trace4] [pid 39] http_request.c(424): [client 172.20.0.1:49286] Accept-Language: en-US,en;q=0.5
[Sat Jul 15 12:21:25.625331 2017] [http:trace4] [pid 39] http_request.c(424): [client 172.20.0.1:49286] Accept-Encoding: gzip, deflate
[Sat Jul 15 12:21:25.625338 2017] [http:trace4] [pid 39] http_request.c(424): [client 172.20.0.1:49286] Cookie: _gauges_unique_year=1; _gauges_unique=1; __utma=111872281.160699490.1495373190.1495373190.1495373190.1; __utmz=111872281.1495373190.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
[Sat Jul 15 12:21:25.625343 2017] [http:trace4] [pid 39] http_request.c(424): [client 172.20.0.1:49286] Connection: keep-alive
[Sat Jul 15 12:21:25.625383 2017] [proxy:trace2] [pid 39] mod_proxy.c(662): [client 172.20.0.1:49286] AH03461: attempting to match URI path '/index.php' against pattern '^(.*\\.php)$' for proxying
[Sat Jul 15 12:21:25.625397 2017] [proxy:trace1] [pid 39] mod_proxy.c(747): [client 172.20.0.1:49286] AH03464: URI path '/index.php' matches proxy handler 'proxy:fcgi://phpfpm:9000/opt/bitnami/apache/htdocs/index.php'
[Sat Jul 15 12:21:25.625426 2017] [authz_core:debug] [pid 39] mod_authz_core.c(835): [client 172.20.0.1:49286] AH01628: authorization result: granted (no directives)
[Sat Jul 15 12:21:25.625434 2017] [core:trace3] [pid 39] request.c(304): [client 172.20.0.1:49286] request authorized without authentication by access_checker_ex hook: /index.php
[Sat Jul 15 12:21:25.625454 2017] [proxy_fcgi:trace1] [pid 39] mod_proxy_fcgi.c(77): [client 172.20.0.1:49286] canonicalising URL //phpfpm:9000/opt/bitnami/apache/htdocs/index.php
[Sat Jul 15 12:21:25.625465 2017] [proxy_fcgi:debug] [pid 39] mod_proxy_fcgi.c(109): [client 172.20.0.1:49286] AH01060: set r->filename to proxy:fcgi://phpfpm:9000/opt/bitnami/apache/htdocs/index.php
[Sat Jul 15 12:21:25.625493 2017] [proxy:trace2] [pid 39] proxy_util.c(1962): [client 172.20.0.1:49286] fcgi: found worker fcgi://phpfpm:9000 for fcgi://phpfpm:9000/opt/bitnami/apache/htdocs/index.php
[Sat Jul 15 12:21:25.625502 2017] [proxy:debug] [pid 39] mod_proxy.c(1227): [client 172.20.0.1:49286] AH01143: Running scheme fcgi handler (attempt 0)
[Sat Jul 15 12:21:25.625507 2017] [proxy_fcgi:debug] [pid 39] mod_proxy_fcgi.c(1027): [client 172.20.0.1:49286] AH01076: url: fcgi://phpfpm:9000/opt/bitnami/apache/htdocs/index.php proxyname: (null) proxyport: 0
[Sat Jul 15 12:21:25.625513 2017] [proxy_fcgi:debug] [pid 39] mod_proxy_fcgi.c(1034): [client 172.20.0.1:49286] AH01078: serving URL fcgi://phpfpm:9000/opt/bitnami/apache/htdocs/index.php
[Sat Jul 15 12:21:25.625518 2017] [proxy:debug] [pid 39] proxy_util.c(2156): AH00942: FCGI: has acquired connection for (phpfpm)
[Sat Jul 15 12:21:25.625524 2017] [proxy:debug] [pid 39] proxy_util.c(2209): [client 172.20.0.1:49286] AH00944: connecting fcgi://phpfpm:9000/opt/bitnami/apache/htdocs/index.php to phpfpm:9000
[Sat Jul 15 12:21:25.646309 2017] [proxy:debug] [pid 39] proxy_util.c(2418): [client 172.20.0.1:49286] AH00947: connected /opt/bitnami/apache/htdocs/index.php to phpfpm:9000
[Sat Jul 15 12:21:25.646352 2017] [proxy:trace2] [pid 39] proxy_util.c(2853): FCGI: fam 2 socket created to connect to phpfpm
[Sat Jul 15 12:21:25.646903 2017] [proxy:debug] [pid 39] proxy_util.c(2887): AH02824: FCGI: connection established with 172.20.0.2:9000 (phpfpm)
[Sat Jul 15 12:21:25.647289 2017] [proxy_fcgi:error] [pid 39] [client 172.20.0.1:49286] AH01067: Failed to read FastCGI header
[Sat Jul 15 12:21:25.647310 2017] [proxy_fcgi:error] [pid 39] (104)Connection reset by peer: [client 172.20.0.1:49286] AH01075: Error dispatching request to :
[Sat Jul 15 12:21:25.647324 2017] [proxy:debug] [pid 39] proxy_util.c(2171): AH00943: FCGI: has released connection for (phpfpm)
[Sat Jul 15 12:21:25.647434 2017] [authz_core:debug] [pid 39] mod_authz_core.c(809): [client 172.20.0.1:49286] AH01626: authorization result of Require all granted: granted
[Sat Jul 15 12:21:25.647444 2017] [authz_core:debug] [pid 39] mod_authz_core.c(809): [client 172.20.0.1:49286] AH01626: authorization result of <RequireAny>: granted
[Sat Jul 15 12:21:25.647449 2017] [core:trace3] [pid 39] request.c(304): [client 172.20.0.1:49286] request authorized without authentication by access_checker_ex hook: /503.html
[Sat Jul 15 12:21:25.647480 2017] [core:info] [pid 39] [client 172.20.0.1:49286] AH00128: File does not exist: /opt/bitnami/apache/htdocs/503.html
[Sat Jul 15 12:21:25.647517 2017] [http:trace3] [pid 39] http_filters.c(1128): [client 172.20.0.1:49286] Response sent with status 503, headers:
[Sat Jul 15 12:21:25.647524 2017] [http:trace5] [pid 39] http_filters.c(1135): [client 172.20.0.1:49286] Date: Sat, 15 Jul 2017 12:21:25 GMT
[Sat Jul 15 12:21:25.647528 2017] [http:trace5] [pid 39] http_filters.c(1138): [client 172.20.0.1:49286] Server: Apache/2.4.26 (Unix) OpenSSL/1.0.1t
[Sat Jul 15 12:21:25.647536 2017] [http:trace4] [pid 39] http_filters.c(957): [client 172.20.0.1:49286] Content-Length: 428
[Sat Jul 15 12:21:25.647541 2017] [http:trace4] [pid 39] http_filters.c(957): [client 172.20.0.1:49286] Connection: close
[Sat Jul 15 12:21:25.647545 2017] [http:trace4] [pid 39] http_filters.c(957): [client 172.20.0.1:49286] Content-Type: text/html; charset=iso-8859-1
[Sat Jul 15 12:21:25.647563 2017] [core:trace6] [pid 39] core_filters.c(525): [client 172.20.0.1:49286] core_output_filter: flushing because of FLUSH bucket
[Sat Jul 15 12:21:25.647637 2017] [core:trace6] [pid 39] core_filters.c(525): [client 172.20.0.1:49286] core_output_filter: flushing because of FLUSH bucket
[Sat Jul 15 12:21:29.815313 2017] [mpm_prefork:notice] [pid 37] AH00169: caught SIGTERM, shutting down
Que coincide con esto en los registros de Php-FPM:
15-Jul-2017 12:21:24.286561] DEBUG: pid 22, fpm_pctl_perform_idle_server_maintenance(), line 362: [pool www] currently 0 active children, 0 spare children
[15-Jul-2017 12:21:25.287655] DEBUG: pid 22, fpm_pctl_perform_idle_server_maintenance(), line 362: [pool www] currently 0 active children, 0 spare children
[15-Jul-2017 12:21:25.646851] DEBUG: pid 22, fpm_children_make(), line 421: [pool www] child 30 started
[15-Jul-2017 12:21:25.646876] DEBUG: pid 22, fpm_pctl_on_socket_accept(), line 536: [pool www] got accept without idle child available .... I forked
[15-Jul-2017 12:21:25.646883] DEBUG: pid 22, fpm_event_loop(), line 419: event module triggered 1 events
[15-Jul-2017 12:21:26.288557] DEBUG: pid 22, fpm_pctl_perform_idle_server_maintenance(), line 362: [pool www] currently 0 active children, 1 spare children
[15-Jul-2017 12:21:27.289631] DEBUG: pid 22, fpm_pctl_perform_idle_server_maintenance(), line 362: [pool www] currently 0 active children, 1 spare children
Si cambio alguna cosa, como en vez de apuntar ha phpfpm apuntar a 127.0.0.1 o localhost el error cambia, pero es como círcular, al final llegas al mismo sitio.
Llevo muchas horas, repartidas en varios días, intentando lidiar con esto y nada. No encuentro salida.
Por cierto, la version de Apache es la 2.4.26 y lo de Php-FPM es:
# php-fpm -v
PHP 7.1.7 (fpm-fcgi) (built: Jul 6 2017 18:27:01)
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
Ah, he intentado quitar el opcache porque he léido que podía provocar el error, pero… agua.
Php.ini:
[opcache]
opcache.enable = 0
opcache.enable_cli = 0
opcache.memory_consumption = 128
opcache.interned_strings_buffer = 8
Me gustaría poder resolver esto, más por cabezonería que otra cosa, y por eso os consulto, aunque, en confianza os digo, que voy a pasar a un solo contenedor con Apache+Php -de toda la vida- entre tanto.
Gracias y perdón por el ladrillo.
Salud y Revolución.
Lobo.