Deploying Laravel Nightwatch on railway

henryo
PRO

18 days ago

I am trying to deploy laravel nightwatch, i have app service currently and now i have a service for the laravel nightwatch with a deploy command ./run-nightwatch.sh ```php artisan nightwatch:agent```

it shows authentication successful but for the past 24 hours i see nothing on the dashboard.

Not sure what i need to do to get it to see the request

Solved$10 Bounty

7 Replies

webappstars
FREE

18 days ago

Laravel Nightwatch Debugging Report

Issue Summary

The Laravel Nightwatch agent shows "Authentication successful," but no data appears on the Nightwatch dashboard after 24 hours of operation.

Root Cause Analysis

1. Nightwatch Package Not Fully Installed

  • Description: Laravel Nightwatch may not be fully set up.

  • Verification:

    • Ensure the package is installed: composer require laravel/nightwatch

    • Run the installation command: php artisan nightwatch:install

    • Check that config/nightwatch.php exists.

2. Missing Event Tracking in Application Code

  • Description: The agent requires the Laravel application to actively send data.

  • Verification:

    • Confirm that event tracking is implemented using:

      use Nightwatch\Facades\Nightwatch;
      
      Nightwatch::track('custom-event', ['key' => 'value']);
      
    • Alternatively, add global middleware:

      protected $middleware = [
          \Nightwatch\Middleware\TrackRequests::class,
      ];
      

3. Incorrect API Key or Endpoint Configuration

  • Description: Missing or incorrect Nightwatch API credentials.

  • Verification:

    • Ensure .env contains:

      NIGHTWATCH_API_KEY=your_api_key_here
      NIGHTWATCH_ENDPOINT=https://api.nightwatch.io
      NIGHTWATCH_ENABLED=true
      
    • Refresh Laravel configuration:

      php artisan config:clear
      php artisan cache:clear
      

4. Network or Firewall Restrictions

  • Description: Outbound connections to Nightwatch API may be blocked.

  • Verification:

    • Test outbound network connectivity.

    • Verify firewall or security group rules allow traffic to Nightwatch servers.

5. Laravel Configuration Cache Issues

  • Description: Laravel may be using outdated cached configurations.

  • Verification:

    • Run:

      php artisan config:clear
      php artisan cache:clear
      

6. No Requests Being Tracked

  • Description: The agent may be authenticated but has no data to report.

  • Verification:

    • Generate application traffic.

    • Manually trigger events using Nightwatch::track().

Debugging Checklist

Step Completed Package installed (composer) Installation command run API key configured in .env Laravel config/cache cleared Event tracking added to code Outbound network verified Laravel logs checked Agent run in verbose mode

Commands Reference

composer require laravel/nightwatch
php artisan nightwatch:install
php artisan config:clear
php artisan cache:clear
php artisan nightwatch:agent --verbose
tail -f storage/logs/laravel.log

Recommendation

  • Ensure active requests to the Laravel application generate Nightwatch events.

  • Use middleware or manual tracking as appropriate.

  • For production, implement authentication, secure .env, and monitor logs regularly.

Assistance

For further help, provide the following:

  1. Hosting environment (e.g., Docker, VPS, Render, etc.)

  2. Sanitized .env configuration

  3. Relevant Laravel log output

Custom deployment scripts, CI/CD integration, or Dockerized setup can be provided upon request.


webappstars

Laravel Nightwatch Debugging ReportIssue SummaryThe Laravel Nightwatch agent shows "Authentication successful," but no data appears on the Nightwatch dashboard after 24 hours of operation.Root Cause Analysis1. Nightwatch Package Not Fully InstalledDescription: Laravel Nightwatch may not be fully set up.Verification:Ensure the package is installed: composer require laravel/nightwatchRun the installation command: php artisan nightwatch:installCheck that config/nightwatch.php exists.2. Missing Event Tracking in Application CodeDescription: The agent requires the Laravel application to actively send data.Verification:Confirm that event tracking is implemented using:use Nightwatch\Facades\Nightwatch; Nightwatch::track('custom-event', ['key' => 'value']);Alternatively, add global middleware:protected $middleware = [ \Nightwatch\Middleware\TrackRequests::class, ];3. Incorrect API Key or Endpoint ConfigurationDescription: Missing or incorrect Nightwatch API credentials.Verification:Ensure .env contains:NIGHTWATCH_API_KEY=your_api_key_here NIGHTWATCH_ENDPOINT=https://api.nightwatch.io NIGHTWATCH_ENABLED=trueRefresh Laravel configuration:php artisan config:clear php artisan cache:clear4. Network or Firewall RestrictionsDescription: Outbound connections to Nightwatch API may be blocked.Verification:Test outbound network connectivity.Verify firewall or security group rules allow traffic to Nightwatch servers.5. Laravel Configuration Cache IssuesDescription: Laravel may be using outdated cached configurations.Verification:Run:php artisan config:clear php artisan cache:clear6. No Requests Being TrackedDescription: The agent may be authenticated but has no data to report.Verification:Generate application traffic.Manually trigger events using Nightwatch::track().Debugging ChecklistStep Completed Package installed (composer) Installation command run API key configured in .env Laravel config/cache cleared Event tracking added to code Outbound network verified Laravel logs checked Agent run in verbose modeCommands Referencecomposer require laravel/nightwatch php artisan nightwatch:install php artisan config:clear php artisan cache:clear php artisan nightwatch:agent --verbose tail -f storage/logs/laravel.logRecommendationEnsure active requests to the Laravel application generate Nightwatch events.Use middleware or manual tracking as appropriate.For production, implement authentication, secure .env, and monitor logs regularly.AssistanceFor further help, provide the following:Hosting environment (e.g., Docker, VPS, Render, etc.)Sanitized .env configurationRelevant Laravel log outputCustom deployment scripts, CI/CD integration, or Dockerized setup can be provided upon request.

henryo
PRO

18 days ago

This looks AI generated tbh, but i have tried all the above.

Thanks for the help though but that did not solve the problem


phoenixauro
HOBBYTop 10% Contributor

18 days ago

My guess would be that nightwatch might be exiting after authenticating and running a loop.
What is inside run-nightwatch.sh?


phoenixauro

My guess would be that nightwatch might be exiting after authenticating and running a loop.What is inside run-nightwatch.sh?

henryo
PRO

17 days ago

No it does not exit i have this

#!/bin/bash

# Make sure this file has executable permissions, run chmod +x run-nightwatch.sh

# This command runs the nightwatch agent.

php artisan nightwatch:agent

and this in my deploy logs

You reached the start of the range → Jun 19, 2025 6:39 PM

Starting Container

2025-06-19 17:41:38 [INFO] Nightwatch agent initiated: Listening on [0.0.0.0:2407]

2025-06-19 17:41:39 [INFO] Authentication successful [1.04s]


phoenixauro
HOBBYTop 10% Contributor

17 days ago

From what you have shown I think your laravel app is the issue and not nightwatch. Can you check for any nightwatch related errors in your laravel apps logs?


phoenixauro

From what you have shown I think your laravel app is the issue and not nightwatch. Can you check for any nightwatch related errors in your laravel apps logs?

henryo
PRO

17 days ago

Everything i did is fine as i followed the documentation.
If there was something wrong wit laravel or nightwatch i will not see authentication successful.


henryo
PRO

17 days ago

But anyways i have solved it
What you need to do is have a proxy and Connect to your service over TCP using a proxied domain and port

Proxy it to 2407

copy the proxy address then have this in all the services that needs it

NIGHTWATCH_INGEST_URI=nightwatch-tcp:proxyIp(given by railway) replace with the actual IP/Hostname

In conclusion do not forget to have this

php artisan nightwatch:agent --listen-on=0.0.0.0:2407

inside the run-nightwatch.sh


Status changed to Solved chandrika 17 days ago