> ## 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

> Manually configure Laravel Nightwatch on Laravel Cloud and run its monitoring agent as a background process in your environment.

> [!NOTE]
>
> This guide is for Laravel applications.

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 connect all your App and Worker clusters by [automatically integrating Nightwatch with your app environment](/docs/environments#nightwatch-integration).

## Configure Nightwatch on Cloud

**1. 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.

**2. Add your Nightwatch token**

Add your Nightwatch environment's `NIGHTWATCH_TOKEN` to your `.env` file:

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

> [!TIP]
>
> You can find this value in your Nightwatch dashboard when you create an application.

**3. Configure the agent as a background process**

To keep the Nightwatch agent running and sending data, configure it as a background process in your Cloud environment:

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

![Select the app cluster](https://mintcdn.com/cloud/MkfTsQSKGENWqY-2/images/knowledge-base/nightwatch-laravel-cloud-step-1.png?fit=max\&auto=format\&n=MkfTsQSKGENWqY-2\&q=85\&s=7fa5e72d0a1e186917bace475d377514)

2. Click **New background process**.

![Select “New Background Process”](https://mintcdn.com/cloud/MkfTsQSKGENWqY-2/images/knowledge-base/nightwatch-laravel-cloud-step-2.png?fit=max\&auto=format\&n=MkfTsQSKGENWqY-2\&q=85\&s=31f7c7af9e4914394c970f168b4a129e)

3. Choose **Custom worker**.

![Add a custom worker that runs the \`nightwatch:agent\` command](https://mintcdn.com/cloud/MkfTsQSKGENWqY-2/images/knowledge-base/nightwatch-laravel-cloud-step-3.png?fit=max\&auto=format\&n=MkfTsQSKGENWqY-2\&q=85\&s=49a47db4447bdb5e40998772c4b10513)

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](/docs/workers#worker-clusters), repeat these steps for the worker cluster so it also runs the agent.

**4. 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 exits with a non-zero status code if there is an error. The command checks that the agent can accept connections and send data to Nightwatch.

## Use Cloud and Nightwatch logs

To send your logs to both [Laravel Cloud Logs](/docs/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. To log to both services, update your `.env` file:

```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](/docs/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. 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 collect and send data continuously. Running the agent from the Commands dashboard does not keep it running.
