This Dockerfile serves a Laravel app with FrankenPHP. It installs your Composer packages without dev ones, builds your front-end assets with Vite, and answers on the port in PORT, which we set for each instance.
The Dockerfile
Add it to the root of your Laravel app:
# Add this file to the root of your Laravel app.
# PHP dependencies, without dev packages.
FROM composer:2 AS vendor
WORKDIR /app
COPY composer.json composer.lock ./
RUN composer install --no-dev --no-interaction --no-scripts --prefer-dist --no-autoloader
COPY . .
RUN composer dump-autoload --no-dev --optimize
# Front-end assets, if your app uses Vite.
FROM node:22-alpine AS assets
WORKDIR /app
COPY package*.json ./
RUN if [ -f package-lock.json ]; then npm ci; else npm install; fi
COPY . .
RUN npm run build
# The app, served by FrankenPHP on the port the platform sets.
FROM dunglas/frankenphp:1-php8.4
WORKDIR /app
RUN install-php-extensions pdo_pgsql
COPY --from=vendor /app /app
COPY --from=assets /app/public/build /app/public/build
RUN chown -R www-data:www-data storage bootstrap/cache /data/caddy /config/caddy
USER www-data
ENV LOG_CHANNEL=stderr
CMD ["sh", "-c", "exec frankenphp php-server --listen :${PORT:-8080} --root /app/public"]
And a .dockerignore beside it, so local files aren’t copied in:
vendor
node_modules
public/build
.env
.git
storage/logs/*
If your app doesn’t use Vite, delete the assets stage and the line that copies from it.
Variables it needs
Add these in the app’s Variables and secrets before you deploy:
| Variable | Value |
|---|---|
APP_KEY |
The output of php artisan key:generate --show. Mark it Secret |
APP_ENV |
production |
APP_URL |
Your app’s address, such as https://my-laravel-app.fireflyplus.site |
Logs go to stderr (the Dockerfile sets LOG_CHANNEL), so they show in the app’s Logs.
A database
The app’s own files are lost when an instance is replaced, so don’t keep a database file in it. Run your database as another app with a volume, reach it at its private address, and set DB_HOST and the other DB_ variables to it. Run your migrations as the app’s release command, php artisan migrate --force, so they run once before each release starts.
Until you have a database, set SESSION_DRIVER=cookie and CACHE_STORE=array so the app doesn’t need one.
Deploy it
You can deploy it two ways.
From GitHub
- Put these files in a repository on GitHub.
- In the dashboard, choose Create app, name it, and choose GitHub repository as its source. Pick the repository and branch.
- Keep the web process’s Port at 8080, or any port you like: your app reads it from
PORT. - Choose Create app. It builds your Dockerfile and deploys; every push to the branch does it again.
From an image you build
-
Build the image for 64-bit Linux, and push it to a registry you use, such as Docker Hub or GitHub’s:
docker build --platform linux/amd64 -t ghcr.io/you/my-laravel-app:1 . docker push ghcr.io/you/my-laravel-app:1 -
Choose Create app, name it, choose Container image, and enter the image in Image.
-
Keep the web process’s Port at 8080, and choose Create app.
Check it
Once its deploy succeeds, open https://my-laravel-app.fireflyplus.site: you see the Laravel welcome page. If the deploy fails, its Deploys page shows why, and Logs shows your app’s output.