If you’re testing Laravel Nightwatch and start the agent manually using:
php artisan nightwatch:agent
…and then later add it to Supervisor to keep it running in the background, you might run into an annoying error:
Here’s why this happens and how to avoid it
What’s Going On?
Laravel Nightwatch runs a WebSocket server internally and listens on a specific port — usually 2407. If you start the Nightwatch agent manually, it binds to that port and stays running until stopped.
Later, when Supervisor tries to start the same agent, it fails because:
- The manual instance is still running.
- The port is already bound, so Nightwatch can’t start again.
Solution: Stop the Manual Process First
Before enabling Supervisor, make sure no manual Nightwatch agents are still running
Step 1: Find the Process Using Port 2407
sudo lsof -i :2407
or:
sudo netstat -tulnp | grep :2407
or:
sudo ss -lptn 'sport = :2407'
You’ll see something like:
php 12345 davidvandertuijn 12u IPv4 1234567 TCP *:2407 (LISTEN)
Step 2: Kill the Process
Use the PID (in this case 12345) to stop it:
sudo kill 12345
Now Start via Supervisor
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start davidvandertuijn_nightwatch
Your Laravel Nightwatch agent should now start cleanly without any port conflicts.