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

# Laravel Cloud

> Get started with Nightwatch on Laravel Cloud

## Prerequisites

First, follow the regular steps in our [quick start guide](/start-guide) to begin.

## Automatic integration (recommended)

Laravel Cloud offers built-in support for Nightwatch. Get set up in minutes:

<Steps>
  <Step title="Install Nightwatch package">
    Install the Laravel Nightwatch package in your application locally using [Composer](https://packagist.org/packages/laravel/nightwatch):

    ```bash theme={null}
    composer require laravel/nightwatch
    ```

    <Note>
      Run <code>composer require laravel/nightwatch</code> on your local machine to update your <code>composer.json</code> and <code>composer.lock</code> files before deploying.
    </Note>
  </Step>

  <Step title="Connect Nightwatch">
    Click the <b>Connect Nightwatch</b> button in your environment dashboard.
  </Step>

  <Step title="Enable monitoring">
    Toggle <b>Enable monitoring</b> to activate Nightwatch for your environment.

    <Frame>
      <img src="https://mintcdn.com/nightwatch/Qtc1X91BNDsWQmmd/images/nightwatch-laravel-cloud-environment.png?fit=max&auto=format&n=Qtc1X91BNDsWQmmd&q=85&s=59685adfa8b911b351ff4cb50add3fe1" alt="Integrate Nightwatch with Laravel Cloud" width="672" height="436" data-path="images/nightwatch-laravel-cloud-environment.png" />
    </Frame>
  </Step>

  <Step title="Enter your Nightwatch token">
    Enter your Nightwatch token, which you can find in your Nightwatch application settings.
  </Step>
</Steps>

Once complete, Laravel Cloud will automatically inject the following environment variables into your environment:

```bash theme={null}
NIGHTWATCH_TOKEN=
NIGHTWATCH_REQUEST_SAMPLE_RATE=0.1
LOG_CHANNEL=stack
LOG_STACK=laravel-cloud-socket,nightwatch
```

You can override these variables in your environment variable settings if needed.

<Note>
  Enabling Nightwatch will automatically run the agent across all the App
  compute and Worker clusters in the environment. You can{" "}
  <a href="#manual-integration">setup Nightwatch manually</a> if you want the
  agent to run on specific instances.
</Note>

<Warning>
  If you have previously configured Nightwatch manually using background
  processes, you must remove these processes from every cluster before enabling
  the built-in integration to avoid issues with your environment.
</Warning>

## Manual integration

You can also [manually integrate Nightwatch with Laravel Cloud](https://cloud.laravel.com/docs/guides/nightwatch-on-cloud) by adding a background process to each App compute and Worker cluster.

### Add your environment variables

Before running the agent, you'll need to add environment variables to your Cloud environment. Follow Laravel Cloud's guide on [managing environment variables](https://cloud.laravel.com/docs/environments#environment-variables) to get started.

```bash theme={null}
NIGHTWATCH_TOKEN=your-api-key
NIGHTWATCH_REQUEST_SAMPLE_RATE=0.1 #recommended
NIGHTWATCH_COMMAND_SAMPLE_RATE=1.0
NIGHTWATCH_EXCEPTION_SAMPLE_RATE=1.0
```

### Running the agent

To run the agent in your Cloud application cluster, follow these simple steps:

**Steps**

1. Select your **application cluster**
2. Click **New background process**
3. Choose **Custom worker**
4. Enter `php artisan nightwatch:agent` as the command
5. Save your changes and redeploy

<Tip>
  Note: If you're using a dedicated **worker cluster**, please repeat the same
  steps for the worker cluster so that it also runs the agent.
</Tip>

### Visual guide

<Frame caption="Select the App cluster">
  <img src="https://mintcdn.com/nightwatch/Qtc1X91BNDsWQmmd/images/nightwatch-laravel-cloud-step-1.png?fit=max&auto=format&n=Qtc1X91BNDsWQmmd&q=85&s=dc0c69c2bb906c66b90207d4b8df8605" alt="Select the app cluster" width="3168" height="2361" data-path="images/nightwatch-laravel-cloud-step-1.png" />
</Frame>

<Frame caption="Select “New Background Process”">
  <img src="https://mintcdn.com/nightwatch/Qtc1X91BNDsWQmmd/images/nightwatch-laravel-cloud-step-2.png?fit=max&auto=format&n=Qtc1X91BNDsWQmmd&q=85&s=78bcd5574dae6d4071ab583bd3a47312" alt="Select “New Background Process”" width="3168" height="2361" data-path="images/nightwatch-laravel-cloud-step-2.png" />
</Frame>

<Frame caption="Add a custom worker that runs the `nightwatch:agent` command">
  <img src="https://mintcdn.com/nightwatch/Qtc1X91BNDsWQmmd/images/nightwatch-laravel-cloud-step-3.png?fit=max&auto=format&n=Qtc1X91BNDsWQmmd&q=85&s=c4ac76755d85a32818f560c52689f98c" alt="Add a custom worker that runs the `nightwatch:agent` command" width="3168" height="2361" data-path="images/nightwatch-laravel-cloud-step-3.png" />
</Frame>
