How to run supervisor for Laravel Queue Worker on Plesk
The supervisor will take care of restarting your queue worker whenever its stopped. It’s necessary to restart queue worker on each deploy, so it reflects the code changes.
Setup
Login via SSH with root or any user with sudo rights. Install supervisor:
sudo apt-get install supervisor
Create a Supervisor configuration file for your Laravel queue worker. For example, create a file named laravel-worker.conf
in the /etc/supervisor/conf.d/
directory:
sudo nano /etc/supervisor/conf.d/laravel-worker.conf
Add the following configuration, adjusting the paths and options as needed:
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=/opt/plesk/php/8.2/bin/php /var/www/vhosts/yourdomain.com/httpdocs/artisan queue:work
autostart=true
autorestart=true
user=your-username
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/vhosts/yourdomain.com/httpdocs/storage/logs/worker.log
- Replace
your-username
with the username that owns the Laravel project files. - Ensure that
artisan
and thestorage/logs
directory paths are correct. - Ensure that your PHP version is correct
Save the file and exit the text editor. Update Supervisor to read the new configuration:
sudo supervisorctl reread
sudo supervisorctl update
Start the Laravel worker process with Supervisor:
sudo supervisorctl start laravel-worker
You can check the status of the worker:
sudo supervisorctl status
Add to deploy script
Add a supervisorctl restart command in your deploy script. Assuming you using PLESK GIT Deploy tool, you would add it here:
However, your deployment script will be called from the user of your web subscription (which is good, because your vendor folder etc. should have same access rights). THe supervisorctl is by default only runnable if you have sudo rights.
To do this, edit the configuration file from supervisor (mine is at /etc/supervisor/supervisord.conf)
In the [unix_http_server]
section of the configuration, you can use the chown
directive to control access to the UNIX domain socket. For example:
[unix_http_server]
chown=youruser:yourgroup
Save the changes to the Supervisor configuration file. Restart the Supervisor service to apply the changes:
sudo service supervisor restart
Now your deployment script should work. Enjoy!