Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rohansinghrawat's avatar

how to run php artisan command in server so it remains active ?

I have built one websocket command in laravel which creates one websocket server and for my integrations now everything seems perfect , when I run command in my terminal "php artisan socket:init" this initiate my server and my work goes smoothly and after deployment I did the same but what the problem here is when ever I open terminal ,run commands the websocket server is initiated but when I close the terminal the connection is closed . So how to and what to do so that my websocket command runs continuously in server ?

0 likes
1 reply
LaryAI's avatar
Level 58

To run a PHP artisan command continuously on a server, you can use a process manager like Supervisor. Here are the steps to set it up:

  1. Install Supervisor on your server. You can do this by running the following command:
sudo apt-get install supervisor
  1. Create a new configuration file for your Laravel command. You can do this by creating a new file in the /etc/supervisor/conf.d/ directory with a .conf extension. For example, if your command is called socket:init, you can create a file called socket-init.conf.

  2. In the configuration file, add the following lines:

[program:socket-init]
command=php /path/to/artisan socket:init
autostart=true
autorestart=true
user=www-data

Replace /path/to/artisan with the actual path to your Laravel project's artisan file. Also, replace www-data with the user that should run the command.

  1. Save the configuration file and exit.

  2. Reload Supervisor to read the new configuration file:

sudo supervisorctl reread
sudo supervisorctl update
  1. Start the command:
sudo supervisorctl start socket-init

Now, your Laravel command should run continuously on the server, even if you close the terminal. You can check the status of the command by running:

sudo supervisorctl status

Please or to participate in this conversation.