logo
Parslinks
Back to blog
Deploy7 min read

Laravel on a cloud platform: queues, cron and storage without a hand-built server

Laravel is the most popular backend framework in Iran, and much of it still runs on a server whose supervisor and crontab someone configured years ago.

Alireza Tadi

Co-founder, Parslinks · Team, marketing & infrastructure

A clothing shop in Tabriz has a three-year-old Laravel app running on a VPS. The original developer has left, and what remains is a server with Nginx, PHP-FPM, a supervisor config that keeps the queue worker running, and a crontab line that runs schedule:run every minute. None of it is in Git.

One day, after an OS update, supervisor doesn't come back up. The site works and orders are saved, but no order-confirmation SMS goes out to anyone, because the queue worker is off and nobody knows. Three days later, from customer complaints, someone finds the problem. Several thousand SMS messages are waiting in the queue.

This isn't a story about Laravel. It's about the parts of an app that were configured on a server instead of in code.

One app, three processes

The three processes of a Laravel app: web, queue worker and scheduler

The key mental shift when moving Laravel to a platform: the queue worker and the scheduler aren't server add-ons; they're processes of the app itself, with the same code and the same environment variables, just a different start command. On a platform, you define each as its own service:

ProcessStart commandInstances
WebPHP server or php-fpm behind a web server (Laravel preset)As traffic requires
Queue workerphp artisan queue:work --tries=3 --max-time=3600As queue volume requires
Schedulerphp artisan schedule:workExactly one

Two points in that table:

The scheduler must be exactly one instance. Run two and the nightly report is built twice and the reminder email goes out twice. If two could ever overlap (during a deploy, say), use onOneServer() on the scheduled tasks; it takes a cache lock to prevent duplicate runs.

--max-time recycles the worker periodically. A PHP worker left running for days can leak memory. With this flag the worker exits cleanly after an hour and the platform starts it again.

routes/console.php
// routes/console.php in recent Laravel versions
use Illuminate\Support\Facades\Schedule;

Schedule::command('orders:cancel-unpaid')
    ->everyFifteenMinutes()
    ->onOneServer()
    ->withoutOverlapping();

Schedule::command('reports:daily-sales')
    ->dailyAt('23:30')
    ->timezone('Asia/Tehran')
    ->onOneServer();
php12 lines

Queues: the right driver

The database driver is enough to start and needs nothing new. When job volume grows, Redis is faster and takes load off the main database. Don't use the sync driver in production; every job runs inside the user's request and the whole point of the queue is lost.

Don't lose queued jobs during deploys

When a new version ships, the old worker receives a stop signal. queue:work finishes its current job and then exits, provided the platform gives it enough time. Break long jobs (exporting ten thousand orders to Excel, say) into smaller chunks so no job takes more than a few tens of seconds.

One more subtle point: a job queued by the old version may be processed by the new version's worker. If the shape of the data you pass to the job has changed, the new code must also handle the old shape.

Storage and sessions

In Laravel, uploads usually go to storage/app/public and are exposed with storage:link. On a platform, that folder is recreated on every deploy. Switch the default disk to s3 and point it at S3-compatible object storage; code that uses Storage::disk() needs no changes.

.env.example
FILESYSTEM_DISK=s3
AWS_ENDPOINT=https://s3.example-provider.ir
AWS_BUCKET=shop-uploads
AWS_USE_PATH_STYLE_ENDPOINT=true

SESSION_DRIVER=redis
CACHE_STORE=redis
QUEUE_CONNECTION=redis
REDIS_URL=redis://...
bash9 lines

Sessions and cache shouldn't be on disk (file) for the same reason. With two web instances, a user whose second request lands on the other instance gets logged out. Redis or the database is the right answer.

Migrations during deploys

Run php artisan migrate --force as a separate step before switching traffic, not inside the web start command; otherwise with three web instances the migration runs three times concurrently. And write migrations so the previous version still works with the new schema: add columns, don't drop them in the same release.

The Laravel preset handles Composer installs and PHP settings. You define the queue worker and scheduler as separate processes in the same project, with the same environment variables. Every deploy gets its own preview, and if something misbehaves after release, you roll back to the previous version.

More important than any tool: after this move, the worker and scheduler settings live in the repo and project settings, not on a server only one person has the password to.

Frequently asked questions

Join the discussion

No comments yet. Be the first to share your thoughts.