02 November 2026 · 2 min read
Zero-downtime Laravel deployments
#laravel#devops
Deploys that overwrite files in the live folder are risky: there is a window where files are half replaced, migrations are running, or caches are missing. A symlink-based release pattern closes that window.
Directory layout
Each release lives in its own folder, while data that must persist (storage and .env) is shared through symlinks.
/var/www/app
├── current -> releases/20261128-1030
├── releases/
│ ├── 20261128-0900/
│ └── 20261128-1030/
└── shared/
├── .env
└── storage/
Deploy steps
- Fetch the code into a new release folder and run
composer install --no-dev --optimize-autoloader. - Link
.envandstoragefromshared/. - Run
php artisan migrate --force, thenconfig:cache,route:cache, andview:cache. - Switch the
currentsymlink to the new release atomically. - Reload PHP-FPM and restart the queue workers.
ln -sfn "$RELEASE" /var/www/app/current.tmp
mv -Tf /var/www/app/current.tmp /var/www/app/current
sudo systemctl reload php8.5-fpm
php artisan queue:restart
Safe migrations
Because the old code keeps serving requests during a migration, split schema changes into two phases. Add the new column first (compatible with the old code), deploy the new code, then drop the old column in the following release.
Rollback
If something goes wrong, point current back at the previous release. Rollback takes seconds. Keep the last 3 to 5 releases and prune the rest so the disk does not fill up.