How do I clear config and route cache safely after deploying updates?

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 optimize

Complete Cache Clear:

For a fresh start, clear all caches:

php artisan optimize:clear

Individual 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:

  1. Deploy your code
  2. Run composer install --no-dev
  3. Run php artisan migrate
  4. Clear and rebuild caches
  5. 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