I've got a Mezzio application that works perfectly on built-in php server using compoer serve
, however, when I try it in docker environment, it gives me following error.
Fatal error: Uncaught Laminas\View\Exception\RuntimeException: Laminas\View\Renderer\PhpRenderer::render: Unable to render template "error::error"; resolver could not resolve to a file in /var/www/portal/vendor/laminas/laminas-view/src/Renderer/PhpRenderer.php:492 Stack trace: #0 /var/www/portal/vendor/mezzio/mezzio-laminasviewrenderer/src/LaminasViewRenderer.php(232): Laminas\View\Renderer\PhpRenderer->render(NULL) #1 /var/www/portal/vendor/mezzio/mezzio-laminasviewrenderer/src/LaminasViewRenderer.php(221): Mezzio\LaminasView\LaminasViewRenderer->renderModel(Object(Laminas\View\Model\ViewModel), Object(Laminas\View\Renderer\PhpRenderer), Object(Laminas\View\Model\ViewModel)) #2 /var/www/portal/vendor/mezzio/mezzio-laminasviewrenderer/src/LaminasViewRenderer.php(138): Mezzio\LaminasView\LaminasViewRenderer->renderModel(Object(Laminas\View\Model\ViewModel), Object(Laminas\View\Renderer\PhpRenderer)) #3 /var/www/portal/vendor/mezzio/mezzio/src/Response/ErrorResponseGeneratorTrait.php(61): Mezzio\LaminasView\LaminasViewRende in /var/www/portal/vendor/laminas/laminas-view/src/Renderer/PhpRenderer.php on line 492
NGINX proxy (nginx.conf)
user root;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 1024;
}
http {
upstream nginx-web {
server web:8110;
}
upstream nginx-portal {
server portal:8115;
}
upstream nginx-api {
server api:8120;
}
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
server {
listen 80;
server_name proxy;
location /web {
proxy_pass http://nginx-web;
}
location /portal {
proxy_pass http://nginx-portal;
}
location /api {
proxy_pass http://nginx-api;
}
}
}
Server Block (default.conf) portal
server {
listen 8110;
root /var/www/portal/public;
server_name proxy;
location / {
try_files $uri $uri/ /index.php$is_args$args;
index index.php;
}
location ~ ^/.+\.php(/|$) {
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
docker-compose.yml
version: "3.9"
services:
db:
container_name: db
image: mysql:5.7
ports:
- "3306:3306"
volumes:
- "${PROJECT_ROOT}/db:/var/lib/mysql"
- ./conf/db/my.cnf:/etc/mysql/conf.d/my.cnf:ro
env_file:
- .env
networks:
- backend
proxy:
container_name: proxy
image: nginx:mainline-alpine
volumes:
- ./conf/proxy/nginx.conf:/etc/nginx/nginx.conf:ro
ports:
- "80:80"
- "8110:8110"
# - "8115:8115"
- "8120:8120"
depends_on:
- web
- portal
- api
networks:
- backend
web:
container_name: web
image: nginx:mainline-alpine
volumes:
- "${PROJECT_ROOT}/web:/var/www/web"
- ./conf/web/default.conf:/etc/nginx/conf.d/default.conf:ro
depends_on:
- php
networks:
- backend
portal:
container_name: portal
image: nginx:mainline-alpine
volumes:
- "${PROJECT_ROOT}/portal:/var/www/portal"
- ./conf/portal/default.conf:/etc/nginx/conf.d/default.conf:ro
depends_on:
- db
- php
port:
- "8115:8115"
networks:
- backend
api:
container_name: api
image: nginx:mainline-alpine
volumes:
- "${PROJECT_ROOT}/api:/var/www/api"
- ./conf/api/default.conf:/etc/nginx/conf.d/default.conf:ro
depends_on:
- php
networks:
- backend
php:
container_name: php
image: maciejslawik/php-fpm-xdebug:latest
ports:
- "9000:9000"
volumes:
- "${PROJECT_ROOT}/web:/var/www/web"
- "${PROJECT_ROOT}/portal:/var/www/portal"
- "${PROJECT_ROOT}/api:/var/www/api"
- ./conf/php/docker-php-ext-xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini:ro
networks:
- backend
composer:
container_name: composer
image: composer:2
restart: "no"
command: install
volumes:
- "${PROJECT_ROOT}/composer:/app"
- ./composer/composer.json:/app/composer.json
networks:
- backend
phinx:
container_name: phinx
image: vegbrasil/phinx:latest
volumes:
- "${PROJECT_ROOT}/migrations/database/migrations:/app/database/migrations"
- "${PROJECT_ROOT}/migrations/database/seeds:/app/database/seeds"
- ./conf/phinx/phinx.php:/app/phinx.php:ro
env_file:
- .env
depends_on:
- db
restart: "no"
command: "status"
environment:
- TESTS_PHINX_DB_ADAPTER_MYSQL_HOST=db
networks:
- backend
schemaspy:
container_name: schemaspy
image: schemaspy/schemaspy:latest
volumes:
- "${PROJECT_ROOT}/schemaspy/output:/output"
- ./conf/schemaspy/schemaspy.properties:/schemaspy.properties:ro
restart: "no"
depends_on:
- db
networks:
- backend
networks:
backend:
Update
I've tried to xdebug the issue. What I've figured out is that .phtml
template file is not being resolved by PhpRenderer.php
. Also I'm accessing it with url http://web.local:8115/dashboard
however, ideally, I'd like to access it as http://web.local/portal/dashboard
.
Suggestions
Could it be that default.conf
file is processing only .php
files and not .phtml
files, however, I doubt it as the issue is, there's a line $file->isReadable()
isn't able to process the file whereas I've verified that the file does exist. i.e. summary.phtml
.
The permission for this file is also fine.
drwxrwxrwx 1 root root 4096 Oct 31 07:57 .
drwxrwxrwx 1 root root 4096 Oct 31 07:57 ..
-rwxrwxrwx 1 root root 197 Oct 31 07:57 summary.phtml