Scott Robinson Technical Lead

Run PHP Script as Daemon Using Supervisord

This short post is just a reminder for myself when writing supervisord configuration files, it’s extremely useful for running daemon workers (such as Laravel’s queue workers). You’ll need the supervisor Ubuntu package installed.

Create a file at /etc/supervisor/conf.d/bob-program.conf and enter the file contents:

[program:bob-worker]
command=php /home/bob/worker.php
autostart=true
autorestart=true
user=bob
redirect_stderr=true
stdout_logfile=/home/bob/logs/worker.log

Then restart supervisor with service supervisor restart and your program should launch.

Found this useful? Everything here is free and stays that way. If it saved you an afternoon, you can buy me a coffee.