Skip to main content

Introduction

A Laravel Cloud application can have many environments, such as “production”, “staging”, or even short-lived environments for trying out new features you’re developing. Each environment has its own compute infrastructure, resources, and deployment settings, so you can tune each environment for its purpose. For example, you might give your staging environment small Flex compute instances that scale to zero, and give your production environment larger, always-on compute instances.

Build and deploy commands

You may define how your application is built during deployment from the Deployments section of your environment settings.

Build commands

Build commands let you customize how Laravel Cloud builds your application during deployment.
Typically, your Laravel build command will install your Composer and npm dependencies and compile your application’s assets:
Run php artisan optimize or php artisan config:cache during the build process, not during the deploy process.

Private Composer packages

To install private Composer packages, configure your application’s Composer HTTP authentication credentials for each package using the composer config command. Add this command to your build commands before composer install:
Build commands time out if they do not complete within 15 minutes.

Dynamic environment variables

For Laravel and Symfony applications, Laravel Cloud writes your environment’s variables to a .env file in the build context. You may append a derived value for your application to read:
JavaScript, Go, Python, Ruby, and Rust applications receive variables through the process environment during builds and at runtime. Appending to a .env file does not configure their runtime variables. Add persistent values under your environment’s environment variables instead.

Deploy commands

Laravel Cloud runs your environment’s “Deploy Commands” on your infrastructure just before a new deployment goes “live”. Typically, you use these commands to migrate your environment’s database. Unlike build commands, deploy commands do not persist their filesystem changes to your application.
Deploy commands time out if they do not complete within 15 minutes.
For Rails applications using a database, run bin/rails db:prepare as a deploy command. If you have kept the default deploy command, attaching a database uncomments it. See Rails database preparation.

Unnecessary build and deploy commands

This section applies to Laravel applications.
Laravel Cloud either handles the following commands automatically, or they should not run during deployment:
  • php artisan queue:restart: Laravel Cloud restarts queue workers automatically after each deployment.
  • php artisan horizon:terminate: Laravel Cloud manages Horizon processes automatically during deployments.
  • php artisan optimize:clear: This command clears the cache and can cause unexpected behavior, especially with the queue.
  • php artisan storage:link: The symbolic link won’t persist, because Laravel Cloud does not save changes that deploy commands make. Use Laravel Object Storage for persistent file storage instead.
Typically, your deploy commands should only include database migrations and other essential post-deployment tasks.

Environment settings

Environment variables

The environment variables section of your environment’s settings lets you customize the variables available to your environment.
In addition to your custom environment variables, Laravel Cloud automatically injects a variety of environment variables for you. These include any credentials needed to connect to Laravel Cloud resources like databases, key-value storage, or object storage.
For sensitive values that should be shared across multiple environments, use Secrets Manager to create encrypted organization-level secrets and link them to the environments that need them.
Custom environment variables take priority and override any automatically injected environment variables.
After you change an environment’s variables, redeploy the environment for the changes to take effect.

How variables reach your application

Laravel Cloud delivers your environment’s variables differently depending on the runtime:
Laravel Cloud writes your variables to a .env file in your application’s root directory before your application starts, so the framework reads them the same way it does locally.
Laravel Cloud also makes your environment’s variables available during builds. Laravel and Symfony builds include a .env file for the framework to read. JavaScript, Go, Python, Ruby, and Rust build commands receive exported process variables.

HTTP basic authentication

HTTP basic authentication lets you protect an environment with a username and password before traffic reaches your application. Basic authentication is useful for staging environments, private demos, preview environments, or sleeping environments that should not wake up because of unauthorized requests or automated bot traffic. You may enable HTTP basic authentication in the Security section of your environment’s General Settings page. Once you enable it, users can access the environment with the username admin and the password you set. Passwords must be between 5 and 32 characters and cannot contain the : character.
HTTP basic authentication is available on the Growth plan or higher. After you enable it, disable it, or change the password, redeploy the environment for the changes to take effect.

Runtime

PHP runtime

You may select an environment’s PHP version on the environment’s General Settings page. After you change the PHP version, redeploy the environment for the change to take effect. See Runtimes for the supported PHP versions.

Node.js, Bun, and Deno runtimes

Next.js, Nuxt, TanStack Start, Express, and Hono applications run on the Node.js, Bun, or Deno runtime. Laravel Cloud detects the runtime automatically from the configuration files in your repository. See Runtimes for detection rules and supported versions. You may select the Node.js, Bun, or Deno version on the environment’s General Settings page. After you change it, redeploy the environment for the change to take effect.

Go and Python runtimes

Laravel Cloud detects Go and Python applications automatically from your repository: a go.mod file for Go, or a pyproject.toml, requirements.txt, Pipfile, or setup.py file for Python. Rather than using a dashboard setting, Laravel Cloud reads the language version straight from your repository. For Go, it reads the go directive in go.mod. For Python, it reads a .python-version file or the requires-python constraint in pyproject.toml. See Runtimes for supported versions and what happens when a detected version isn’t one Laravel Cloud publishes.

Ruby runtime

Laravel Cloud reads Ruby version declarations from your deployment’s commit. When the repository does not declare a version, you may select one in General Settings. See Ruby versions for the supported release lines and declaration order.

Rust runtime

Laravel Cloud detects Rust applications automatically from a Cargo.toml file at the root of your repository. Rather than using a dashboard setting, Laravel Cloud builds with a recent stable Rust release, or with the toolchain pinned by your rust-toolchain.toml file. See Rust versions for details.

PHP extensions

PHP extensions are only available for PHP runtime environments (Laravel and Symfony).
Laravel Cloud currently supports the following PHP extensions:
You can also list the loaded extensions by running php -m with Laravel Cloud’s “Command” feature in your environment dashboard.

PHP memory limit

This section applies to PHP runtime environments (Laravel and Symfony).
Laravel Cloud allocates PHP memory dynamically based on a percentage of your instance’s total memory. If your application needs a specific amount, you can override the default by defining a new memory_limit. You can override the default memory limit by adding configuration directly in your application code. The most common method is to update your public/index.php and your artisan file:
Or, you can set the memory limit in your build commands to avoid modifying your project’s source code:
Adjust memory early in your application’s lifecycle. Excessive memory usage can slow your whole application. Setting the memory limit to -1 removes all memory restrictions, but it can lead to unpredictable behavior, so use it with caution, especially in production environments. For more information about PHP memory configuration, consult the official PHP documentation.

Cloud domains

Laravel Cloud assigns each environment a free laravel.cloud domain the first time it deploys successfully. You can use this domain to test and build your application before attaching a custom domain. Laravel Cloud builds these domains from your application and environment names. If you change either name, Laravel Cloud updates the domain to match. Redeploy the environment for the new domain to take effect.

Custom domains

Of course, before shipping your application to the world, you will likely want to assign your own custom domain name to your production environment. Laravel Cloud guides you through DNS configuration, verifies domain ownership, and issues an SSL certificate automatically. For DNS records, verification paths, wildcards, provider-specific guides, and plan limits, see Domains.
If your domain verification is taking longer than expected, check out our docs on verifying domains.

Stop and restart

To stop an environment, click the ”…” button next to the environment’s “Deploy” button. Then, click “Stop”. When you stop an environment, Laravel Cloud shuts down all App and Worker clusters in the environment. All web traffic, background processes, and scheduled tasks stop. You are not charged for the environment’s compute, but you are still charged for any attached resources. You can restart the environment from the same dropdown menu. Restarting an environment runs a full deployment.

Replicate

Environments in the same application often have similar or identical resources and settings. So when you create a new environment, it is often more convenient to clone an existing one and make changes than to start from scratch. To replicate an environment, click the ”…” button next to the environment’s “Deploy” button. Then, click “Replicate”. Confirm you are replicating the correct environment and Git branch, then enter a name for your new environment. By default, Laravel Cloud duplicates all General, Environment, and Deployment settings. You can optionally edit the default replication settings for compute and resources. The default replication behavior is:
  • Compute: duplicate all clusters at a smaller size, with Scale-to-Zero enabled
  • Database: create a new database cluster that scales to zero, or a new database within the same cluster if your database does not support scale-to-zero replication
  • Cache: create a new cache that scales to zero, or a new cache at the smallest available size if your cache does not support scale to zero
  • Object storage: create a new bucket
  • WebSockets: create a new WebSocket server
If you choose to share the cache instead, Cloud adds a REDIS_PREFIX environment variable set to application:environment: so each environment’s keys stay separate. If the environment runs Laravel Horizon, Cloud also sets HORIZON_PREFIX.
Review and edit the “Replication options” as needed before deploying your new environment. The defaults balance cost and performance, but they may not be right for your application. Take extra care when you replicate a production environment. Reusing its resources can hurt performance or interfere with queued jobs, sessions, or other application data.
To generate an isolated environment automatically for every pull request, use preview environments instead.

Commands

Laravel Cloud lets you run arbitrary shell commands directly in your environment. Navigate to your environment’s Commands tab to run one-time commands for any supported framework or runtime. For example, php artisan cache:clear in a Laravel application, php bin/console cache:clear in a Symfony application, node script.js in a Node.js application, ./app migrate in a Go application, migrate in a Rust application, or python manage.py shell in a Django application.
Commands must be non-interactive and may not run for more than 30 minutes.
Laravel Cloud runs commands on any available instance in your environment.

Filesystem

Environment filesystems are ephemeral, meaning files may not persist across requests or jobs. New deployments and redeployments reset the filesystem. In addition, each replica of your compute cluster has its own filesystem. Treat the filesystem as temporary, unshared disk space that stays consistent only during a single request or job. The total disk space available on each replica is proportional to the cluster’s RAM. Every 1GB of RAM gives 512MB of disk space. For example, a cluster with 2GB of RAM will have 1GB of ephemeral disk space available to it. If you exceed the available disk space, your application may crash and the deployment may need to restart. For persistent cache and session storage, PHP applications should use the redis or database drivers with a cache or database resource. JavaScript applications should use their framework’s equivalent persistent session and cache adapter backed by one of these resources. Go, Python, and Rust applications should connect directly to a cache or database resource using the injected REDIS_URL or DATABASE_URL connection string. For persistent file storage, use Laravel Cloud Object Storage.

Nightwatch integration

Nightwatch integration is currently available for Laravel applications only.
Laravel Cloud environments have built-in support for Laravel Nightwatch monitoring. Nightwatch shows your environment’s performance, exceptions, logs, and overall health.
1

Install Nightwatch package

Install the Laravel Nightwatch package in your application locally using Composer:
Run composer require laravel/nightwatch on your local machine to update your composer.json and composer.lock files before deploying.
2

Connect Nightwatch

Click the Connect Nightwatch button in your environment dashboard.
3

Enable monitoring

Toggle Enable monitoring to activate Nightwatch for your environment.
4

Enter your Nightwatch token

Enter your Nightwatch token, which you can find in your Nightwatch application settings.
When you enable Nightwatch, Laravel Cloud runs the agent on all App and Worker clusters in the environment. You can set up Nightwatch manually if you want the agent to run on specific instances.
When you enable Nightwatch, Laravel Cloud automatically injects the following environment variables into your environment:
You can override these variables in your environment variable settings if needed.
If you have previously configured Nightwatch manually with a background process, remove that process from every cluster before you enable the built-in integration. Otherwise, your environment may run into issues.