LaraflareDocsPackages13.x

Docs / Getting Started / Deployment

Deployment

Introduction

A Laraflare application runs as a Cloudflare Worker: one Worker per environment, named after the application (example-app for production, example-app-staging for staging), with its D1 database and R2 bucket named the same way.

Requirements

Deploying With Wrangler

An application goes live with wrangler, from a clean commit. First open the environment's encrypted env file with the application's ENV_ENCRYPTION_KEY, which writes .env.production beside it:

npx artisan env:decrypt --env=production --key=<ENV_ENCRYPTION_KEY>

The D1 migrations are SQL files in database/d1, the migrations_dir of the database in wrangler.toml. Write them from your migrations, and commit them, before you deploy:

npx artisan d1:migrations

Then apply the migrations and upload the Worker. The env file's values are sent as the Worker's secrets, and BUILD_COMMIT is the commit the health route reports:

npx wrangler d1 migrations apply DB --remote --config wrangler.toml
npx wrangler deploy --config wrangler.toml --secrets-file .env.production --var BUILD_COMMIT:$(git rev-parse HEAD)

The Worker starts from bootstrap/cache/packages.ts, the main of wrangler.toml: your application with the service providers of the packages it requires, since a Worker has no node_modules folder to discover them in. The package:discover Artisan command writes the file, and runs after every npm install, so a fresh checkout has it once its dependencies are installed:

npx artisan package:discover

Staging is the same with --env=staging, .env.staging and wrangler.staging.toml. Delete the decrypted env file when the deploy is done; only the encrypted one is committed.

Debug Mode

The debug option in your config/app.ts configuration file determines how much information about an error is actually displayed to the user. By default, this option is set to respect the value of the APP_DEBUG environment variable, which is stored in your application's env files.

Warning

In your production environment, this value should always be false. If the APP_DEBUG variable is set to true in production, you risk exposing sensitive configuration values to your application's end users.

The Health Route

The application includes a health check route at /up. It answers with the commit the Worker runs (BUILD_COMMIT), so you can confirm that the new version is live.

Adapted from Laravel's documentation, Copyright (c) Taylor Otwell, used under the MIT License.