Laravel deployment fails due to wayfinder

Hey there,

I just tried to deploy the laravel + vue starter-kit and wasn’t successful with that.

...
FROM node:${NODE_VERSION} as node_modules_go_brrr 
RUN mkdir /app 
RUN mkdir -p /app 
WORKDIR /app 
COPY . .
COPY --from=base /var/www/html/vendor /app/vendor 

# Use yarn or npm depending on what type of # lock file we might find. Defaults to # NPM if no lock file is found. 
# Note: We run "production" for Mix and "build" for Vite 
RUN if [ -f "vite.config.js" ] || <- FAILS HERE
...

Error msg (partly):

[@laravel/vite-plugin-wayfinder] [plugin @laravel/vite-plugin-wayfinder] Error generating types: Error: Command failed: php artisan wayfinder:generate --with-form 9.781 /bin/sh: 1: php: not found

As I see it now, the second stage in the generated Dockerfile triggers the vite build process, which also runs wayfinder. But wayfinder needs php, which is not present in the FROM node:${NODE_VERSION} stage.

After some tries, my workaround is to change the second stage from the above to:

FROM base as node_modules_go_brrr

# new
RUN curl -sL https://deb.nodesource.com/setup_22.x -o nodesource_setup.sh \
    && bash nodesource_setup.sh \
    && apt install nodejs -y

RUN mkdir /app

RUN mkdir -p  /app
WORKDIR /app
COPY . .
COPY --from=base /var/www/html/vendor /app/vendor

That way I just use the base image with php installed and add npm and node to it.
As I am fairly new to Laravel and web in general I am unsure what exactly was the problem. Is this a viable solution? Is this a general setup error of the fly.io Dockerfile presets?

edit: typo

Yup, you need to install PHP to use PHP :upside_down_face:

Consider adding RUN apt install -y php-cli as a separate line, or add php-cli to an existing apt install line. However, this will only get you PHP on the command line; if you actually want to run Laravel, you may need a web server capable of serving PHP.

I would recommend that. Vue is an add-on to Laravel, not the other way around. Lead with PHP (plus Apache/Nginx if required), then add your frontend tooling to it.

1 Like

Got it working with my solution. I was just curious since I followed the examples but I guess they were not updated for Wayfinder, which is fairly new as I understand.

1 Like

@olevsz mind sharing your final Dockerfile? I’m unable to just install PHP since it looks like Laravel as a whole needs to be installed to get access to the artisan command?

Could you show us your Dockerfile @shahzeb1, and also confirm whether it does or does not build locally? It is often better to fix what one has, rather than changing it wholesale.

Sure, but worth noting my Dockerfile is basically just the vanilla Dockerfile after running fly deploy for the first time. Since wayfinder is now a key dependency of the newest Laravel starter (Starter Kits - Laravel - The PHP Framework For Web Artisans), it requires both php and specifically artisan to be present during the build step. For now I’ve commented out the wayfinder lines out of by vite.config.ts

I’ve commented out one line in the Dockerfile:

Fair enough, but most folks here will be writing Dockerfiles from scratch, and so won’t have seen this.

Regarding this:

# !!!!!!!!!!!!!
# I had to comment this line out for some reason it was not finding the vendor folder:
# COPY --from=base /var/www/html/vendor /app/vendor

I’d be minded to fix this first; a Laravel app won’t run without its vendor folder. If you uncomment that and rebuild, what error do you get specifically?

It does look like it should work; the working folder looks like it is correct. I wonder if it is not finding the vendor part of the target, not the source; does COPY --from=base /var/www/html/vendor vendor work better?

I should say that if you don’t already have Docker installed locally, do install it and build locally. Debugging Dockerfiles only through remote builds is a pain; your feedback loops will be much quicker if you can do it on a dev laptop.

FYI the missing vendor folder issue is due to the prior ‘composer install’ command failing, but its output is suppressed. I put the RUN composer cmd on its own line and built local and the failure was due to the default composer.lock for Laravel 12 having dependencies that require PHP8.4. If you bump ARG PHP_VERSION the build will succeed.

There’s another similar issue with the ECHO command that creates the ‘/etc/cron.d/laravel’ file silently failing.

Both of these were raised as issues several months back here: https://github.com/fly-apps/dockerfile-laravel/issues . It would be good if the Fly.io team addressed these issues and/or updated the Laravel docs page ( Laravel on Fly.io · Fly Docs ), because currently the ‘Fly launch’ step results in failure and a rather cryptic error message.