Laravel interview question · Most asked
How do you deploy a Laravel application with zero downtime?
Summary
Build each release in a new directory (dependencies installed, assets built, config cached), run backward-compatible migrations, switch a symlink atomically, reload PHP-FPM/OPcache, and restart queue workers. Tools such as Envoyer, Deployer or Forge automate this.
Longer Answer
Steps for a typical server deploy:
- Clone to
releases/<timestamp>; link shared.envandstorage/. composer install --no-dev --optimize-autoloader, build front-end assets.php artisan optimize.php artisan migrate --force(expand-only changes).- Atomically switch the
currentsymlink; reload PHP-FPM so OPcache picks up the new files. php artisan queue:restart(orhorizon:terminate), andoctane:reloadif used.- Health check; keep the previous release for instant rollback.
In containers the same ideas apply: an immutable image, migrations as a separate step, rolling updates with readiness probes, and graceful worker shutdown (SIGTERM handling).
Key Points
- New release directory + atomic symlink switch.
- Migrations compatible with old code.
- Reload FPM/OPcache; restart workers.
- Keep the previous release for rollback.
More most-asked Laravel questions
- How do you validate requests in Laravel? Why use Form Requests?
- Gates or policies: how does authorization work in Laravel?
- What is mass assignment, and how do $fillable and $guarded protect against it?
- How do database transactions work in Laravel, and what pitfalls should you know?
- Which Artisan commands would you run when deploying Laravel to production, and why?
- What is the service container, and how does dependency injection work in Laravel?
- What is the N+1 query problem in Eloquent and how do you prevent it?
- How do queues work in Laravel?