> ## Documentation Index
> Fetch the complete documentation index at: https://www.qovery.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy a Laravel Application

> Deploy a Laravel application with PostgreSQL on Kubernetes in your own cloud account with Qovery: production Dockerfile with PHP and Apache, the /up health check, artisan migrations as a lifecycle job.

This guide deploys a Laravel application served by Apache with PHP, with a PostgreSQL database and migrations that run before each release. Qovery builds the image from your Dockerfile and runs it on a Kubernetes cluster in your own cloud account.

> [!NOTE]
>
> **No configuration file in your repository.** Qovery does not read a `qovery.yml`, `.qovery.yml` or `.qovery.toml`, and there is no `qovery init`. Projects, environments and services are created in the Console, with `qovery api`, or with [Terraform](https://www.qovery.com/docs/terraform-provider/overview.md). For the full path from a repository to a running app with commands only, see [Deploy with the CLI and API](https://www.qovery.com/docs/getting-started/quickstart/cli-and-api.md).

## Prerequisites

* A Laravel 11 or later application in a GitHub, GitLab or Bitbucket repository, with a `composer.lock`.
* A Qovery account and a cluster: [create one in your cloud account](https://www.qovery.com/docs/getting-started/quickstart/cloud.md), [connect your own cluster](https://www.qovery.com/docs/getting-started/installation/kubernetes.md), or [try it on your laptop](https://www.qovery.com/docs/getting-started/quickstart/try-with-an-agent.md).
* An application key, generated with `php artisan key:generate --show`.

## Prepare the application

Laravel reads a full connection URL from `DB_URL`. In `config/database.php`, let the `pgsql` connection fall back to `DATABASE_URL`, the name the other services of the environment use:

```php config/database.php theme={null}
'pgsql' => [
    'driver' => 'pgsql',
    'url' => env('DB_URL', env('DATABASE_URL')),
    // keep the other keys as they are
],
```

In `bootstrap/app.php`, trust the cluster's ingress, so Laravel builds `https://` URLs and reads the client IP from the forwarded headers:

```php bootstrap/app.php theme={null}
->withMiddleware(function (Middleware $middleware): void {
    $middleware->trustProxies(at: '*');
})
```

The pod is only reachable through the ingress, so trusting every proxy address is safe here.

## Add a production Dockerfile

Create a `Dockerfile` at the root of the repository:

```dockerfile Dockerfile theme={null}
FROM php:8.4-apache

ENV APP_ENV=production \
    APP_DEBUG=false \
    LOG_CHANNEL=stderr \
    APACHE_DOCUMENT_ROOT=/var/www/html/public

RUN apt-get update \
 && apt-get install -y --no-install-recommends libpq-dev libzip-dev unzip \
 && docker-php-ext-install pdo_pgsql opcache zip \
 && rm -rf /var/lib/apt/lists/*

RUN a2enmod rewrite \
 && sed -ri 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf \
 && sed -ri 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf \
 && sed -ri 's!Listen 80$!Listen 8080!' /etc/apache2/ports.conf \
 && sed -ri 's!<VirtualHost \*:80>!<VirtualHost *:8080>!' /etc/apache2/sites-available/000-default.conf \
 && mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

COPY --from=composer:2 /usr/bin/composer /usr/bin/composer

WORKDIR /var/www/html

COPY composer.json composer.lock ./
RUN composer install --no-dev --no-interaction --prefer-dist --no-scripts --no-autoloader

COPY . .
RUN composer dump-autoload --no-dev --optimize \
 && php artisan package:discover --ansi \
 && chown -R www-data:www-data storage bootstrap/cache

USER www-data
EXPOSE 8080
CMD ["sh", "-c", "php artisan optimize && exec apache2-foreground"]
```

* `php:8.4-apache` is the official PHP image with Apache, which serves PHP in a single container. The `fpm` variant needs a separate web server in front of it. Match the PHP version to the `php` constraint of your `composer.json`.
* It adds the `pdo_pgsql` extension for PostgreSQL, `opcache` to cache compiled PHP, and `zip` for Composer, and uses the production `php.ini`.
* The `sed` lines point Apache at the `public` folder, where Laravel's entry point is, and move it to port `8080`, so it runs without root. `mod_rewrite` reads the `.htaccess` that Laravel ships in `public`.
* Composer comes from the official `composer:2` image. Installing the dependencies before copying the code keeps that layer cached when only the code changes.
* The container runs as `www-data`, which owns `storage` and `bootstrap/cache`, the folders Laravel writes to.
* `php artisan optimize` caches the configuration, routes and views at startup, when the variables are set, then `exec` makes Apache the main process, so it receives the stop signal.
* `LOG_CHANNEL=stderr` sends the logs to the container output, where Qovery reads them.

If the application uses Vite, build the assets in a first stage from a `node` image with `npm ci` and `npm run build`, and copy `public/build` into this image. Add a `.dockerignore` with at least `.git`, `.env`, `vendor` and `node_modules`.

## Port and health check

The application listens on port `8080`. Laravel 11 and later register a `GET /up` route in `bootstrap/app.php` that answers `200` when the application boots, so use it as the health check path.

## Connect PostgreSQL

The application and the migration job read the connection string from `DATABASE_URL`. Create PostgreSQL, then expose its connection string under that name at the environment scope, so every service of the environment gets it.

> [tab] Qovery database (development)
>
> 1. In the environment, click **New Service** and pick **PostgreSQL**. Keep the visibility private, then create and deploy it. See [Create a Database](https://www.qovery.com/docs/getting-started/guides/getting-started/connect-database.md).
> 2. Open the **Variables** section of the environment, find the built-in variable `QOVERY_POSTGRESQL_Z<ID>_DATABASE_URL_INTERNAL`, select **Create alias**, and name it `DATABASE_URL`.
>
> From the CLI, once the application exists:
>
> ```bash theme={null} theme={null} theme={null} theme={null} theme={null} theme={null} theme={null}
> # Copy the exact name of the ..._DATABASE_URL_INTERNAL variable
> qovery application env list -n my-app
>
> qovery application env alias create -n my-app \
>   -k "QOVERY_POSTGRESQL_Z1234ABCD_DATABASE_URL_INTERNAL" \
>   --alias DATABASE_URL --scope ENVIRONMENT
> ```
>
> This database runs as a container on your cluster, with no automated backups. Use it for development and testing.

> [tab] Blueprint (production)
>
> 1. In the environment, click **New Service** › **Blueprint** and pick a managed PostgreSQL, such as [Amazon RDS for PostgreSQL](https://www.qovery.com/docs/configuration/blueprints/aws-rds-postgresql.md) or [Scaleway Managed PostgreSQL](https://www.qovery.com/docs/configuration/blueprints/scaleway-managed-postgresql.md). Deploy it.
> 2. The Blueprint publishes its outputs as variables named `QOVERY_OUTPUT_TERRAFORM_Z<ID>_<OUTPUT>`, and by default Qovery also creates an alias for each output, named `<PREFIX>_<OUTPUT>` after the Blueprint name. See [Aliases Qovery creates for outputs](https://www.qovery.com/docs/configuration/environment-variables.md#aliases-qovery-creates-for-outputs) for the naming rules and the cases where no alias is created. Copy the prefix from the **Variables** section, then create an environment secret `DATABASE_URL` that composes the outputs with `{{...}}` interpolation. The output names differ per Blueprint.
>
> Amazon RDS for PostgreSQL:
>
> ```text theme={null} theme={null} theme={null} theme={null} theme={null} theme={null} theme={null}
> postgresql://{{QOVERY_OUTPUT_TERRAFORM_Z1234ABCD_DB_USERNAME}}:{{QOVERY_OUTPUT_TERRAFORM_Z1234ABCD_DB_PASSWORD}}@{{QOVERY_OUTPUT_TERRAFORM_Z1234ABCD_DB_ADDRESS}}:{{QOVERY_OUTPUT_TERRAFORM_Z1234ABCD_DB_PORT}}/{{QOVERY_OUTPUT_TERRAFORM_Z1234ABCD_DB_NAME}}
> ```
>
> Scaleway Managed PostgreSQL:
>
> ```text theme={null} theme={null} theme={null} theme={null} theme={null} theme={null} theme={null}
> postgresql://{{QOVERY_OUTPUT_TERRAFORM_Z1234ABCD_DB_USERNAME}}:{{QOVERY_OUTPUT_TERRAFORM_Z1234ABCD_DB_PASSWORD}}@{{QOVERY_OUTPUT_TERRAFORM_Z1234ABCD_ENDPOINT_IP}}:{{QOVERY_OUTPUT_TERRAFORM_Z1234ABCD_ENDPOINT_PORT}}/{{QOVERY_OUTPUT_TERRAFORM_Z1234ABCD_DB_NAME}}
> ```
>
> Interpolation inserts the values as they are, without URL encoding. Leave the Blueprint's `db_password` input empty so Qovery generates the password, or set one made of letters and digits only: characters such as `#`, `?`, `%` or `:` break the URL.
>
> Make sure the Blueprint is deployed in a [deployment stage](https://www.qovery.com/docs/configuration/deployment/pipeline.md) that runs before the migration job.

See [Aliases](https://www.qovery.com/docs/configuration/environment-variables.md#aliases) and [Variable Interpolation](https://www.qovery.com/docs/configuration/environment-variables.md#variable-interpolation) for the rules.

Laravel reads the `postgresql://` URL as is and maps it to its `pgsql` driver.

## Set the variables

| Variable | Value | Secret |
| - | - | - |
| `DATABASE_URL` | The alias or secret from [Connect PostgreSQL](#connect-postgresql) | Yes |
| `DB_CONNECTION` | `pgsql` | No |
| `APP_KEY` | The output of `php artisan key:generate --show`, starting with `base64:` | Yes |
| `APP_URL` | The URL of the application, for example `https://my-app-z1234abcd.z5678efgh.qovery.io` | No |

The `qovery.io` domain shows in the Console once the application is created. Without `DB_CONNECTION`, Laravel 11 and later use SQLite.

## Run the migrations

Run `migrate` in a [lifecycle job](https://www.qovery.com/docs/configuration/lifecycle-job.md) built from the same repository and Dockerfile, triggered on the **Deploy** event, with these CMD arguments:

```json theme={null}
["php", "artisan", "migrate", "--force"]
```

`--force` is required because `APP_ENV` is `production`. The job runs once per deployment. In the default [deployment pipeline](https://www.qovery.com/docs/configuration/deployment/pipeline.md), jobs run after the databases and before the applications, so the schema is up to date when the new code starts. The default Laravel migrations also create the `sessions`, `cache` and `jobs` tables that the `database` drivers use.

Running `migrate` in the start command instead works for a single instance, but every instance then runs it at boot, and a failed migration leaves the application crashing in a loop.

## Deploy

> [tab] Console
>
> **1. Create a project and an environment**
>
> Follow steps 1 and 2 of [Deploy Your First Application](https://www.qovery.com/docs/getting-started/guides/getting-started/deploy-your-first-application.md#step-1-create-a-project). Pick the cluster the environment runs on.
>
> **2. Add PostgreSQL**
>
> Create the database and the `DATABASE_URL` variable as described in [Connect PostgreSQL](#connect-postgresql).
>
> **3. Create the application**
>
> In the environment, click **New Service** › **Create application**, select **Git Repository**, then your repository and branch. Leave **Root Application Path** empty unless the Dockerfile is in a subfolder.
>
> **4. Set the port**
>
> Add port `8080` with the protocol **HTTP**, and turn on **Publicly Accessible**. Qovery serves it over HTTPS on port 443.
>
> **5. Set the health checks**
>
> Set the readiness and liveness probes to type **HTTP**, path `/up`, port `8080`. See [Service Health Checks](https://www.qovery.com/docs/configuration/service-health-checks.md).
>
> **6. Add the variables**
>
> Click **Create**, without deploying yet. Then open the **Variables** section of the environment and add the other variables listed in [Set the variables](#set-the-variables) at the environment scope, so the migration job gets them too. `DATABASE_URL` already exists from the previous step. Mark keys and passwords as secrets.
>
> **7. Create the migration job**
>
> Click **New Service** › **Create lifecycle job**, select the same repository, branch and Dockerfile, and trigger it on the **Deploy** event (`START`) with the CMD arguments `["php", "artisan", "migrate", "--force"]`. Set the number of restarts to 0. See [Run the migrations](#run-the-migrations).
>
> **8. Deploy**
>
> Deploy the environment. Qovery deploys the database, then the job, then the application, builds the image from your Dockerfile and gives the application a URL on `qovery.io`. Follow the progress in the **Deployment logs** tab.

> [tab] With a coding agent
>
> Install the Qovery skills once:
>
> ```bash theme={null}
> curl -fsSL https://skill.qovery.com/install.sh | bash
> ```
>
> Open your agent in the repository and paste:
>
> claude
>
> Copy
>
> Deploy this Laravel application with Qovery, with a PostgreSQL database and a lifecycle job that runs the migrations.
>
> The agent writes the Dockerfile if there is none, creates the database, the variables, the job and the application, and gives you the URL. See [Agent Skills](https://www.qovery.com/docs/getting-started/quickstart/agent-skills.md).

## Troubleshooting

The CLI commands below use the organization, project and environment selected with `qovery context set`. Run it first, or add `--organization`, `--project` and `--environment` to each command.

> [accordion] Deployment fails on the health check
>
> Apache listens on another port than the one set in Qovery. Check that the `Listen 8080` and `VirtualHost *:8080` lines are in the Dockerfile and that the port in Qovery is `8080`. Read the error lines with `qovery environment deployment logs --environment "<env>" --service "<app>" --errors-only`.

> [accordion] Database file at path database.sqlite does not exist
>
> `DB_CONNECTION` is not set, so Laravel falls back to SQLite. Set it to `pgsql` at the environment scope, so the migration job gets it too, then redeploy.

> [accordion] No application encryption key has been specified
>
> `APP_KEY` is missing or empty. Generate one with `php artisan key:generate --show` and add it as a secret, including the `base64:` prefix.

> [accordion] relation does not exist
>
> The migrations did not run against this database. Check that the job and the application read the same `DATABASE_URL` and `DB_CONNECTION` at the environment scope, and read the job output with `qovery log --job "<job name>"`.

> [accordion] Links and assets use http\:// instead of https\://
>
> Laravel does not trust the forwarded headers of the ingress. Add `trustProxies(at: '*')` in `bootstrap/app.php` and set `APP_URL` to the `https://` URL. A `Vite manifest not found` error means the assets were not built into the image.

For other errors, see [Diagnose a Failed Build or Deployment](https://www.qovery.com/docs/getting-started/troubleshoot/overview.md#diagnose-a-failed-build-or-deployment).

## Next steps

> [card] [Preview environments](https://www.qovery.com/docs/getting-started/guides/use-cases/preview-environments.md)
>
> Get a full copy of the environment for each pull request

> [card] [Custom domain](https://www.qovery.com/docs/configuration/application.md#custom-domains)
>
> Serve the application on your own domain

> [card] [Auto deploy](https://www.qovery.com/docs/configuration/deployment/auto-deploy.md)
>
> Deploy on every push to the branch

> [card] [Other frameworks](https://www.qovery.com/docs/getting-started/guides/frameworks/overview.md)
>
> All framework guides


## Related topics

- [Deploy application](https://www.qovery.com/docs/api-reference/application-actions/deploy-application.md)
- [Deploy a Django Application](https://www.qovery.com/docs/getting-started/guides/frameworks/django.md)
- [Deploy a Go Application](https://www.qovery.com/docs/getting-started/guides/frameworks/go.md)
- [List application deploys](https://www.qovery.com/docs/api-reference/application-deployment-history/list-application-deploys.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.