Deploy a Laravel Zero app

Is it possible to deploy a Laravel Zero app to Fly.io?

The app doesn’t need nginx just php-fpm.

1 Like

Hi @tubiz! Of course! You can deploy your Laravel Zero app to Fly.io with a bit of configuration.
You just need to give a way for the Fly builder to build your app into an image. You can give it one of the three:

  1. Dockerfile
  2. Buildpack
  3. Image

Please read this page for details regarding Fly builders: Builders and Fly · Fly Docs.
For example, Laravel apps are already configured by Fly.io with our custom Dockerfile during fly launch .

1 Like

This looks promising for generating a Dockerfile: GitHub - owenvoke/laravel-zero-docker: A Laravel Zero command to generate a Dockerfile using Box

1 Like

@kathrynannetan @kurt thanks so much for the guides.

I have been able to create a Dockerfile for the deployment but deployment always fails due to healthchecks.

This is a command line app that doesn’t need a webserver (nginx) so no need for me to open port 8080

Is there a way to make healthcheck passes for this use case?

Below is the content of my fly.toml file

app = "demo-cli-app"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[experimental]
allowed_public_ports = []
auto_rollback = true

And my Dockerfile file

FROM serversideup/php:8.1-cli

RUN apt-get update && apt-get install -y \
    git curl zip unzip ca-certificates vim htop cron \
    php8.1-bcmath php8.1-xml php8.1-mbstring \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

RUN mkdir -p /var/www/html
WORKDIR /var/www/html

# copy application code, skipping files based on .dockerignore
COPY . /var/www/html

RUN composer install --optimize-autoloader --no-dev \
    && mkdir -p storage/logs \
    && chown -R webuser:webgroup /var/www/html \
    && echo "MAILTO=\"\"\n* * * * * webuser /usr/bin/php /var/www/html/demo-app schedule:run" > /etc/cron.d/laravel \
    && rm -rf /etc/cont-init.d/* \
    && composer dump-autoload

CMD [ "sleep", "100000" ]

Hi @tubiz awesome work on creating your Dockerfile!

In your app logs you might find an error like: “s6-overlay-suexec: fatal: can only run as pid 1”, if you do, this might be because you are using the base image FROM serversideup/php:8.1-cli. The latest version might be using [s6-overlay] (edit:v3)(GitHub - just-containers/s6-overlay: s6 overlay for containers (includes execline, s6-linux-utils & a custom init)).

As you can read from the error above,“s6-overlay” can only run as pid 1! However we can’t run other processes as pid1 in Fly.io, for more details, please check this doc and here out for that!

So to fix this, as announced here: 📣 [Laravel] Fix for error "Failed due to unhealthy allocations", kindly append a stable version to your base image that does not use the (edit:s6-v3)process:

FROM serversideup/php:8.1-cli-v1.5.0

Let me know how it goes!

2 Likes

Thank you very much. Deployment successful. :man_dancing:

1 Like

Awesome to hear! :raised_hands: