Skip to content

Instantly share code, notes, and snippets.

@wallacemaxters
Created July 14, 2025 23:59
Show Gist options
  • Save wallacemaxters/fa57797cd44e8a41845947d52aaecc9b to your computer and use it in GitHub Desktop.
Save wallacemaxters/fa57797cd44e8a41845947d52aaecc9b to your computer and use it in GitHub Desktop.
Laravel command to install queue as Linux service
<?php
use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Process;
Artisan::command('app:queue-service-install', function () {
$content = file_get_contents(base_path('stubs/queue.service.stub'));
$content = strtr($content, ['{{ $dir }}' => base_path()]);
file_put_contents('/etc/systemd/system/laravel-queue.service', $content);
Process::run('systemctl daemon-reload');
Process::run('systemctl enable laravel-queue.service');
Process::run('systemctl start laravel-queue.service');
});
# Laravel queue worker using systemd
# ----------------------------------
[Unit]
Description=Laravel Queue Work
[Service]
User=www-data
Group=www-data
Restart=always
WorkingDirectory={{ $dir }}
ExecStart=/usr/bin/php artisan queue:work --sleep=3 --tries=3
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment