Hi, I used this guide to build docker for production:
But there is issue that I use Inertia (Laravel + React) with Wayfinder (GitHub - laravel/wayfinder) and when nginx tries to build I get this error:
5.544 [@laravel/vite-plugin-wayfinder] [plugin @laravel/vite-plugin-wayfinder] Error generating types: Error: Command failed: php artisan wayfinder:generate --with-form
5.544 /bin/sh: 1: php: not found
I understand that problem is because in nginx Dockerfile there is no PHP. So my questions is - what’s the best practice to add PHP that wayfinder could successfully execute php artisan wayfinder:generate command?
I’ve not read the article, just saw there are a few dockerfiles on it. You have mentioned nginx and the error is clear : php is not present in the image. Nginx is a Web server so most probably you’re using an incorrect image, please use a PHP image.
The linked guide shows multiple Dockerfiles. Including the one for php-fpm. You cannot run php commands in an nginx container so you can’t add the commands to an nginx Dockerfile, only to the php-fpm dockerfile. Nginx is only for serving the website and communicating with the php-fpm container in the background like a proxy.
I moved the npm install and npm run build commands into the php-fpm Dockerfile, and it kinda works — but I’m running into a file naming mismatch issue with Nginx.
Specifically, Nginx can’t locate the built assets inside the assets/build folder because the filenames don’t match what the app expects. For example, the browser tries to load index-458dacb48.min.js, but the actual built file is named something like index-9zd489a.min.js.
I assume it is caused by some kind of cache. If PHP generates the HTML correctly and it is returned by nginx to the browser, the right javascript should be loaded. And I think nginx would also need to see the static asset files directly not just through PHP unless the PHP app is configured to read the static files and return those as well.
Now that I start to remember my PHP days, and start to understand what you are doing, I guess you generated the new files in the new image but the old files are still mounted back from a docker volume. Volumes will override whatever you have in the image if you mount tham over an existing folder. So when I needed to update these kind of apps, I created versioned volumes and when a new image was built with new assets, I basically used a new empty volume so everything was copied from the image to the empty volume.
If you can show your compose file and dockerfile, we can check it if you need more help.