Skip to main content

Laravel Queue Setup on Shared Hosting

Laravel Queue Setup on Shared Hosting

Laravel queues allow you to defer time-consuming tasks like sending emails or processing uploads. But on shared hosting, there’s no supervisor tool like on VPS. Don’t worry — with cPanel and cron, you can still run queues efficiently.

๐Ÿ› ️ Prerequisites

  • Laravel project already deployed on shared hosting (via cPanel)
  • Queueable jobs created using php artisan make:job
  • Basic understanding of Laravel's queue system

⚙️ Step 1: Configure Your Laravel Queue

By default, Laravel uses the sync driver, which runs jobs immediately. Update the driver to database (or Redis, if supported):


QUEUE_CONNECTION=database
    

In your .env file, set the queue driver. If using database, run:

php artisan queue:table && php artisan migrate

This creates the necessary table for storing queued jobs.

๐Ÿ“ Step 2: Locate the Laravel Project Path

Find your full Laravel path on the server. It usually looks like:

/home/your-cpanel-user/your-laravel-folder

You’ll need this to run Artisan commands via cron jobs.

⏱️ Step 3: Add a Cron Job to Process Queues

  1. Log in to your cPanel account.
  2. Go to the Cron Jobs section.
  3. Add a new cron job with a schedule like: Every minute (* * * * *).
  4. Use the command:
    cd /home/your-cpanel-user/your-laravel-folder && php artisan queue:work --tries=3 >> /dev/null 2>&1

This starts Laravel’s queue worker every minute and processes jobs if any are pending.

๐Ÿง  Optional: Use queue:listen vs queue:work

On shared hosting, you should prefer queue:work since queue:listen keeps running and won’t be handled properly by cron jobs.

๐Ÿ” Step 4: Test Your Setup

  • Dispatch a job using dispatch(new YourJob()).
  • Wait a minute and check if the task completed (e.g. email sent, file processed).
  • Check storage/logs/laravel.log for any errors.

๐Ÿงช Troubleshooting Tips

  • Ensure php artisan commands work via terminal or cron.
  • If needed, use the full PHP path (e.g., /usr/local/bin/php).
  • Verify that jobs and failed_jobs tables exist if using the database queue.

๐ŸŽ‰ Done!

Even without root access or Supervisor, you can run Laravel queues reliably on shared hosting using cron jobs. This setup works great for small to medium apps.


If this helped you get your Laravel queues running on cPanel, feel free to share it or drop a link to your project!

Comments

Popular posts from this blog

How to Display Flash Messages in EJS using Node.js and Express

Displaying Flash Messages in EJS with Node.js and Express Flash messages are a great way to give users quick feedback — like "Login successful!" or "Please enter all fields!" . In this guide, you’ll learn how to implement them using: express-session connect-flash EJS templating ๐Ÿ“ฆ Step 1: Install Required Packages npm install express express-session connect-flash ejs ⚙️ Step 2: Setup Express App and Middleware const express = require('express'); const session = require('express-session'); const flash = require('connect-flash'); const app = express(); // Set view engine app.set('view engine', 'ejs'); // Middleware app.use(express.urlencoded({ extended: true })); app.use(session({ secret: 'yourSecretKey', resave: false, saveUninitialized: true })); app.use(flash()); // Make flash messages available to all views app.use((req, res, next) => { res.lo...

Realtime Device Tracker using Node.js, Socket.IO & Leaflet

Realtime Device Tracker using Node.js, Socket.IO & Leaflet In this tutorial, you’ll learn how to build a realtime location tracking application that uses the browser’s GPS, Socket.IO for live communication, and Leaflet.js to display users on a map. ๐Ÿš€ Project Overview Backend: Node.js, Express.js, Socket.IO Frontend: HTML, Leaflet.js, Socket.IO client Features: Live GPS tracking, multi-user map, disconnect cleanup ๐Ÿ“ Folder Structure project-root/ ├── app.js ├── package.json ├── src/ │ ├── public/ │ │ ├── css/ │ │ │ └── style.css │ │ └── js/ │ │ └── script.js │ ├── routes/ │ │ └── routers.js │ ├── socket/ │ │ └── socketHandler.js │ └── views/ │ └── index.ejs ๐Ÿง  How It Works Each user shares their location using the browser's navigator.geolocation API. Location is sent to the server via Socket.IO . The server broadcasts each user’s position to all clien...

How to Send Emails in Node.js using Nodemailer and Ethereal

How to Send Email in Node.js using Nodemailer Email functionality is essential in modern web applications. Whether you're sending confirmation emails, password resets, or notifications, Node.js with Nodemailer makes this simple. In this blog, we'll walk through setting up email sending using Node.js , Express , and Ethereal Email for testing. ๐Ÿงพ Prerequisites Node.js installed Basic knowledge of Express.js Internet connection ๐Ÿ“ Project Structure project-folder/ ├── index.js ├── .env ├── package.json └── app/ └── controller/ └── emailSendController.js ๐Ÿ“ฆ Step 1: Install Dependencies npm init -y npm install express nodemailer dotenv npm install --save-dev nodemon ๐Ÿ” Configure nodemon (Optional but Recommended) Update your package.json with a custom start script: "scripts": { "start": "nodemon index.js" } ๐Ÿ” Step 2: Create a .env File Create a .env file a...