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

Neeraj1005's avatar

Laravel queue:work setup in background Cpanel

In my project I've made a simple newsletter system where I want to send an email to all subscriber. But the problem I faced in production (cpanel hosting) I have to run laravel queue:work command in terminal. Can anyone tells me how to handle queue:work in background in cpanel hosting... It would be very appreciable...can anyone tell me how to handle this problem?

ANd using the laravel queue database connection For sending the mail I'm using the shared hosting email smtp. Not using the mailchimp or mailgun etc...

0 likes
22 replies
martinbean's avatar

@neeraj1005 You need to SSH into your server, and run php artisan queue:work as a detached process. You’ll also want to use something like Supervisor to make sure the process is restarted if it’s terminated for whatever reason.

However, if you’re using cPanel and this is a shared host, this will most likely not be possible. The reason being, with shared hosting, you share the resources of that server with other customers, so hosting company doesn’t want you triggering long-running processes and hogging up those resources. In which case, you’ll need to look at something “more”, like a dedicated host, VPS, or something.

Neeraj1005's avatar

@martinbean So, in cpanel I have to install supervisor and SSH? Do you have any idea how this can be resolve...? SO instead of database should I have to use sync

QUEUE_CONNECTION=sync

tykus's avatar

sync @neeraj1005, not smtp

QUEUE_CONNECTION=sync

Shared hosting providers will almost never allow you to SSH into, install services, or have long running processes.

martinbean's avatar

SO instead of database should I have to use sync

@neeraj1005 No, because sync executes queue jobs synchronously, i.e. within a request, so it’s essentially not using a queue at all.

So, in cpanel I have to install supervisor and SSH? Do you have any idea how this can be resolve...?

Google it.

Neeraj1005's avatar

@tykus ohh thank you! its sync i mispelled this.

install services

Which services I've to installed. supervisor?

tykus's avatar

Can you first check that you can SSH into, or otherwise install a service like supervisor with your cPanel host?

jeevamugunthan's avatar

@neeraj1005 make it

QUEUE_CONNECTION=database

and run this commend in your cpanel terminal

php artisan queue:work

it should be work

or you can set cron job in your cpanel

Neeraj1005's avatar

php artisan queue:work

I want to get rid of this instead of using terminal. I want run this command automatically in background.

martinbean's avatar

@neeraj1005 You’ve been told about three times now that this usually isn’t possible on shared hosting. So check with your host whether you can execute long-running processes like a queue worker, as I’m guessing not.

There’s no point continually asking how if it’s not possible.

1 like
traceback's avatar

in my case i create a command called Run:jobs and add two Artisan command inside

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Log;

class runJobs extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'Run:Jobs';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Run Job in queue';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        Artisan::call('queue:restart');
        Artisan::call('queue:work');
    }
}

then schedule Run:jobs everyMinute

        $schedule->command('Run:Jobs')->everyMinute();

this will work for single queue with single worker for small prjects

og-neth's avatar

@Snapey This is exactly what I was hoping to find, I am on godaddy cpanel hosting, its been working well thus far for all my needs for my laravel back-end for my portfolio, but having the ability to have a contact form so people can reach out to me for work I think is a good UX for visitors to my portfolio, but alas this feature has been difficult to setup on the cpanel server due to SMTP restrictions and non root/sudo permissions, but when there is a know how and a will to find a way, alas you encounter it. This is very good stuff sir thank you for sharing this link. Surprised it does not have more likes, but I guess only a few of us use shared hosting with cpanel....

vanvangka's avatar

simple bro, in your controller just write this code:

exec("php {your dir path to artisan} queue:work > /dev/null &");

example: exec("php /home/u1606688/public_html/filemscrapper/artisan queue:work > /dev/null &");

why /dev/null ? it's for not waiting for the outputs.. simple :)

usman350's avatar

$schedule->command('queue:work')->everyMinute()->withoutOverlapping();

So whats happening is, the first time it runs, it will start the queue worker in daemon mode, then on every minute, it will basically use the withoutOverlapping to only run it again if the previous one crashed/exited/no longer running. This essentially produces a supervisor like functionality. At worst case it will take a minute before the queue worker comes back up in case of a failure / memory limit hit, but in most cases the first thread will stay alive and work through the queue. This is a better way to accomplish queue:listen like functionality without supervisor.

The caveat is of course, you need to run queue:restart whenever you deploy new code so that the daemon worker will restart and get fresh app code.

Hope this helps.

Also you can read from here https://laracasts.com/discuss/channels/laravel/free-queue-solution-for-shared-hosting?page=1&replyId=903925

daproduction's avatar

if you are using shared hosting you don’t have root access to install Supervisor. However, you can achieve a similar result using Cron Jobs in cPanel to run background tasks.

🔹 Step 1: Access Cron Jobs in cPanel

- Log in to cPanel.

- Go to Advanced > Cron Jobs.

- Scroll down to "Add a New Cron Job".

🔹 Step 2: Add a Cron Job for Laravel, In the Command field, add:

php /home/your-cpanel-username/public_html/artisan queue:work --tries=3

Please or to participate in this conversation.