Post deploy commands
Published
Updated
✅
Execute tasks after deployment.
Post deploy commands run after a deployment has copied the new code into the environment. Database migrations, cache clearing and applying project config belong here, as they need the new code and the live database.
When the repository contains a deploy file, this setting is managed there and cannot be edited in the dashboard.
About post deploy commands
Build commands prepare the code before it goes live. Post deploy commands run after the code is copied into the environment, in the deployment container. They run in order, one after the other.
Typical tasks:
- Database migrations
- Clearing or warming caches
- Applying project config, such as in Craft CMS
- Rebuilding a search index
Software template commands
The software templates set post deploy commands for Laravel, Symfony, Craft CMS and others, such as php artisan migrate --force for Laravel. The software templates page lists the commands of every template.
Failed post deploy commands
When a post deploy command fails, the deployment shows as failed, while the new code is already live. The deploy log shows which command failed. Fix the command or the code, and deploy again.
Best practices
- Idempotent commands: a command can run again on the next deployment without harm, as migrations do.
- Caches: clearing all caches on every deployment makes the first requests slow while they rebuild. Clear what the new code needs.
- Short commands: long tasks, such as a full import, belong in a job.