run php artisan websockets:serve automatically without supervisor

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

Running PHP Artisan Commands Automatically: The No-Supervisor Solution for Laravel WebSockets

Running development or long-standing server processes in a production environment requires a robust process management system. When working with frameworks like Laravel, which rely on persistent background services—such as websockets servers—the ability to keep these processes alive and restart them automatically is critical.

You are facing a common challenge: you need to execute php artisan websockets:serve continuously in production but lack the access or permission to install system-level process managers like Supervisor. While Supervisor is indeed the gold standard for managing services on Linux, there are viable, pragmatic workarounds that allow you to achieve persistence using built-in operating system features.

This post will explore how you can run your Laravel websockets server automatically without Supervisor, focusing on reliable methods suitable for environments where direct system management tools are limited.

The Challenge: Persistence Without Supervision

The php artisan websockets:serve command starts a long-running process that continuously listens for connections. If you simply execute this in a standard shell session, the process will terminate as soon as your SSH session closes, or if the script encounters an error, it will stop running entirely.

Since you cannot install Supervisor on the Apache server, we must rely on methods that force the PHP process to detach from the terminal and continue executing in the background.

Solution 1: Using nohup for Background Execution

The most straightforward method available on almost any Linux system is using the nohup command combined with the ampersand (&) operator. This combination tells the operating system to ignore the hangup signal (which occurs when you log out) and run the command in the background.

How nohup Works

The nohup command ensures that the command continues to run even if the invoking user logs out or the terminal session is closed. The output is typically redirected to a file named nohup.out by default, which serves as a log for the process’s execution.

Implementation Steps:

  1. Navigate to your Laravel project root directory in your production environment.
  2. Execute the command using nohup.

Code Example:

# Navigate to your project directory
cd /var/www/html/your_laravel_app

# Run the websockets serve command persistently
nohup php artisan websockets:serve &

Monitoring and Logging

After running this command, the process will start immediately in the background. You can verify it is running using ps aux | grep websockets. All output generated by the server will be appended to a file named nohup.out in your current directory.

To monitor the status of your websocket server:

tail -f nohup.out

This allows you to stream the live logs, ensuring that if any errors occur within the websockets service, you can immediately see them. This practice aligns with best practices for application deployment, regardless of whether you are building complex applications on Laravel or other frameworks.

Solution 2: Scripting for Enhanced Robustness (The Advanced Approach)

While nohup is effective, for true production-grade reliability, a dedicated shell script offers more control over error handling and process monitoring than a single command execution. You can wrap the command within a custom script that handles logging explicitly.

Example Shell Script (start_websockets.sh):

#!/bin/bash

# Define the path to your project directory
PROJECT_DIR="/var/www/html/your_laravel_app"
LOG_FILE="${PROJECT_DIR}/websocket_serve.log"

echo "Starting Laravel WebSockets service at $(date)" >> ${LOG_FILE}
echo "Running command: php artisan websockets:serve" >> ${LOG_FILE}

# Execute the command in the background, redirecting both stdout and stderr to the log file,
# and ensuring it ignores hangup signals.
nohup php artisan websockets:serve >> ${LOG_FILE} 2>&1 &

echo "Websockets service started successfully and running in background."

Execution Steps:

  1. Save the content above as start_websockets.sh.
  2. Make the script executable: chmod +x start_websockets.sh
  3. Run the script: ./start_websockets.sh

This script provides a single, traceable entry point for starting your service and ensures that all output (both standard output and errors) is cleanly written to a dedicated log file (websocket_serve.log). This level of meticulous logging is essential when deploying services, especially when ensuring the stability of applications built on robust foundations like those provided by the Laravel ecosystem.

Conclusion

When faced with infrastructure constraints, developers must pivot from ideal solutions (like Supervisor) to practical ones that leverage existing OS capabilities. For running a long-lived process like a Laravel websockets server without access to a dedicated process manager, using nohup or a custom shell script executed in the background is a reliable and effective workaround. By prioritizing robust logging and background execution, you can successfully deploy and maintain your application, ensuring that your services remain operational even under challenging production constraints.