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:
- Install Supervisor on your server. You can do this by running the following command:
sudo apt-get install supervisor
-
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.confextension. For example, if your command is calledsocket:init, you can create a file calledsocket-init.conf. -
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.
-
Save the configuration file and exit.
-
Reload Supervisor to read the new configuration file:
sudo supervisorctl reread
sudo supervisorctl update
- 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