From 37f994bec1cdfb8f4c206aac5c594e9498cf7abd Mon Sep 17 00:00:00 2001 From: Parsa Aghayi Date: Thu, 1 Oct 2026 19:02:44 -0400 Subject: [PATCH] Make uploaded images actually reachable in the container Two things the image upload feature needs at runtime were missing. public/storage is gitignored, so it never reaches the build context, and nothing in the image created it. Storage::url() returns .../storage/media/x.jpg, so nginx 404s every file the admin uploaded even though the upload succeeded and the URL was stored in the record. storage:link at build time fixes it; the ln fallback covers artisan refusing to boot without APP_KEY. PHP's own ceiling was the other half. StoreMediaRequest accepts 4 MB but upload_max_filesize defaults to 2M, so larger files are discarded before Laravel validates them and the admin just sees a 422 for a valid image. Next's Server Action limit was already raised to 8 MB, so 8M keeps the whole chain consistent. post_max_size must sit above upload_max_filesize or the extra form fields are dropped along with $_FILES. The ini directory is resolved at build time rather than hardcoded, and the effective values are asserted so a silently mislocated ini fails the build. --- Dockerfile | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Dockerfile b/Dockerfile index bcba908..e948bd1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,4 +18,23 @@ RUN if [ -d /var/www/html/vendor ]; then \ composer install --no-dev --optimize-autoloader --no-interaction; \ fi +# The admin panel now uploads images to the `public` disk and stores the URL +# Laravel hands back, which is served off disk by nginx. public/storage is +# gitignored, so it is absent from the build context and every uploaded image +# would 404 in production. The `|| ln` covers the case where artisan bails out +# because APP_KEY is not set yet in the build stage. +RUN php artisan storage:link \ + || ln -sfn /var/www/html/storage/app/public /var/www/html/public/storage + +# StoreMediaRequest allows 4 MB, but PHP discards anything over 2 MB long +# before validation ever sees it, and Next's Server Action limit was raised to +# 8 MB. post_max_size has to exceed upload_max_filesize or the extra fields +# (and therefore $_POST) are dropped along with the file. +RUN INI_DIR="$(php --ini | sed -n 's/^Scan for additional .ini files in: //p' | tr -d '"')" \ + && test -n "$INI_DIR" \ + && mkdir -p "$INI_DIR" \ + && printf 'upload_max_filesize=8M\npost_max_size=10M\n' > "$INI_DIR/zz-uploads.ini" \ + && test "$(php -r 'echo ini_get("upload_max_filesize");')" = "8M" \ + && test "$(php -r 'echo ini_get("post_max_size");')" = "10M" + EXPOSE 8080 \ No newline at end of file