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

# Manually Configure Laravel Nightwatch on Cloud

<Note>This guide is for Laravel applications.</Note>

Follow these steps to manually configure [Laravel Nightwatch](https://nightwatch.laravel.com) in your Laravel application and run the agent as a background process in your Cloud environment. For more details, see the [Nightwatch Getting Started Guide](https://nightwatch.laravel.com/docs/getting-started/start-guide).

<Tip>
  You can easily connect all your App compute and Worker clusters by [automatically integrating Nightwatch with your app environment](/environments#nightwatch-integration).
</Tip>

## Configure Nightwatch on Cloud

<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 `composer require laravel/nightwatch` on your local machine to update your composer.json and composer.lock files before deploying.
    </Note>
  </Step>

  <Step title="Add your Nightwatch token">
    Add your Nightwatch environment's `NIGHTWATCH_TOKEN` to your `.env` file:

    ```
    NIGHTWATCH_TOKEN=your-api-token
    ```

    <Tip>
      You will find this value in your Nightwatch dashboard when you create an application.
    </Tip>
  </Step>

  <Step title="Configure the agent as a background process">
    To ensure the Nightwatch agent is always running and sending data, configure it as a background process in your Cloud environment:

    1. Go to your **App cluster** in the Cloud dashboard.

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

    2. Click **New background process**.

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

    3. Choose **Custom worker**.

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

    4. Enter the following command:

    ```bash theme={null}
    php artisan nightwatch:agent
    ```

    5. Save your changes and redeploy your application.

    <Tip>
      If you're using a dedicated [worker cluster](/compute#worker-clusters), repeat these steps for the worker cluster so it also runs the agent.
    </Tip>
  </Step>

  <Step title="Monitor the agent">
    To check the health of the running agent, use the following command:

    ```bash theme={null}
    php artisan nightwatch:status
    ```

    The `nightwatch:status` command will exit with a non-zero status code if there is an error. This command will ensure the agent is able to accept connections and send data to Nightwatch.
  </Step>
</Steps>

## Use Cloud and Nightwatch logs

To send your logs to both [Laravel Cloud Logs](/logs) and [Nightwatch](https://nightwatch.laravel.com/docs/agent/logging), use Laravel's [log stacks](https://laravel.com/docs/12.x/logging#building-log-stacks) feature. Update your `.env` file as shown below to enable logging to both services:

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

## Frequently asked questions

**Why would I want to run Nightwatch manually?**
If you only want the Nightwatch agent to run on specific instances, you can manually set up the background process for each one.

**Can I log to both Nightwatch and Cloud Logs?**

Yes, you can use [Laravel Cloud Logs](/logs) simultaneously with [Nightwatch Logging](https://nightwatch.laravel.com/docs/agent/logging) by [setting a log stack in your .env in your Cloud environment settings](#use-cloud-and-nightwatch-logs).

**Do you need a background process running for each worker cluster?**

Yes, you should configure a background process for each worker cluster that needs to run the Nightwatch agent.

**Can you run the command from the Commands dashboard of Laravel Cloud?**

No, the Nightwatch agent must run as a background process to continuously collect and send data. Running it from the Commands dashboard will not keep the agent running.
