How do I clear config and route cache safely after deploying updates?
Answer: Run the appropriate artisan commands to clear and regenerate caches after deployment to ensure your application uses the latest configuration.
Cache Clearing Commands:
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan optimizeComplete Cache Clear:
For a fresh start, clear all caches:
php artisan optimize:clearIndividual Cache Commands:
- Config cache: php artisan config:cache
- Route cache: php artisan route:cache
- View cache: php artisan view:cache
- Application cache: php artisan cache:clear
- Session cache: php artisan session:clear
Deployment Best Practices:
- Deploy your code
- Run composer install --no-dev
- Run php artisan migrate
- Clear and rebuild caches
- Test your application
Automated Deployment:
Create a deployment script:
#!/bin/bash
git pull origin main
composer install --no-dev --optimize-autoloader
php artisan migrate --force
php artisan optimize:clear
php artisan optimize