I host various Laravel applications that use various versions of PHP, and decided to improve the current single bloated container Docker setup by having multiple PHP-FPM containers, one for each PHP version.
I tested the setup by having a PHP file at /var/www/html/index.php
mounted to all containers and it works as expected.
However, since Laravel apps are served from a public
subdirectory, this causes issue when the PHP container tries to find the file.
This is the Nginx config:
location /appname/ {
alias /var/www/html/appname/public;
index index.php;
# Use PHP 7
location ~ \.php$ {
fastcgi_pass php74:9007;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
So a request to /appname/index.php
actually gets served from /var/www/html/appname/public
, but the PHP containers don't know this and can't find the file.
I tried replacing $document_root
with /var/www/html/appname/public
or /appname/public
but neither worked.
This is the error PHP-FPM is throwing:
FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream
How do I go about letting PHP know the path to properly serve the app?
Feel free to recommend a better container setup to achieve this goal.
Both the
location
andalias
values should have a trailing/
for correct operation.When using an
alias
directive, use: