# Deploy Laravel

> A Laravel application with its database, cache, queues, scheduler and migrations, on Fransys.

Source: https://docs.fransys.cloud/en/guides/laravel/ Checked against the console on 2026-10-23.

## What you need

- A project attached to a cluster ([First deployment](https://docs.fransys.cloud/en/demarrer/premier-deploiement/)).
- Your application in a GitHub or GitLab repository, or a Docker image that's already built.

## The application service

Add an **Application**: Fransys runs it from a Docker image, either the one your Dockerfile builds or an image that's already published. Connect the repository and the CI: see [From GitHub or GitLab](https://docs.fransys.cloud/en/projets/github-gitlab/).

Set the **Container port** to the one your web server listens on (for example `8080` with the `serversideup/php` images, `80` with a standard nginx).

## The database

Add a PostgreSQL or MariaDB database **linked** to the application. The application receives its connection variables: open the **Variables** tab to see their names.

Laravel expects `DB_HOST`, `DB_PORT`, `DB_DATABASE`, `DB_USERNAME` and `DB_PASSWORD`. Two ways to match them:
- **rename** each received variable in this service (**Name in this service**);
- or **add** `DB_HOST=${…}` referencing the received variable, with **Allow ${VAR} references**.

Add `DB_CONNECTION=pgsql` (or `mariadb`).

## The application's variables

Import your `.env.example` (**Multiple variables (.env)** mode), then fill in:
- `APP_KEY`: generate it on your machine with `php artisan key:generate --show`, and add it **protected**;
- `APP_ENV=production`, `APP_DEBUG=false`;
- `APP_URL`: the service's address, on `fransysapp.com` or your own domain.

Keep secrets (API keys, SMTP passwords) as protected variables.

## Redis for cache, sessions and queues

Add a Redis linked to the application: it receives `REDIS_HOST`, `REDIS_PORT` and `REDIS_PASSWORD`, the names Laravel expects. Then `CACHE_STORE=redis`, `SESSION_DRIVER=redis`, `QUEUE_CONNECTION=redis`.

## Migrations

In **Deployment commands**, add `php artisan migrate --force` to **After the first install** and to **After an update**. Add `php artisan optimize` in the same place if you cache your configuration.

## The scheduler

Add a [scheduled task](https://docs.fransys.cloud/en/projets/taches-planifiees/) `php artisan schedule:run` every minute (`* * * * *`). Your tasks stay defined in your code (`routes/console.php` or `app/Console/Kernel.php`).

## Queue workers

Fransys doesn't change the container command. Have your entrypoint read a role:

```sh
#!/bin/sh
# entrypoint.sh
if [ "$CONTAINER_ROLE" = "worker" ]; then
  exec php artisan queue:work --tries=3
fi
exec "$@"
```

Then copy the application service and add `CONTAINER_ROLE=worker` to the copy. Your agent can prepare this copy in a plan.

## Files uploaded by your users

A container restarts without its files. For `storage/app`, add a volume in **Storage** (mount point `/var/www/html/storage/app`, depending on your image), or use S3-compatible object storage.

## Real time

For broadcasting, add a WebSocket service linked to the application, and the Pusher driver. See [Other services](https://docs.fransys.cloud/en/projets/autres-services/#websocket).

## Let your agent do it

Open the agent in the repository folder and give it the instruction from the launch guide: it reads the Dockerfile, the `docker-compose` file and the `.env.example`, then prepares the port, variables, databases, scheduler and workers in a plan, which you review. See [Deploy your code](https://docs.fransys.cloud/en/demarrer/deployer-votre-code/#let-your-agent-prepare-it).
