I’ve recently updated my .env file and modified some blade templates, but the changes aren't reflecting on my production server. I suspect it's a caching issue within the framework. Could someone list the specific PHP Artisan commands required to clear the application, route, config, and view caches all at once to ensure my environment is running the latest code?
3 answers
To perform a comprehensive cache clear, you should run a series of specialized commands. The most common ones are php artisan cache:clear for the application cache, php artisan config:clear for configuration, php artisan route:clear for routes, and php artisan view:clear for compiled Blade templates. If you are on a production environment, it’s often better to use php artisan optimize after clearing, as this re-caches your configuration and routes into single files for better performance. I’ve found that forgetting to clear the 'config' cache after an .env change is the most frequent cause of deployment errors in Laravel 10 and 11 applications.
Are you using a specific caching driver like Redis or Memcached, or are you just relying on the default file-based caching provided by Laravel out of the box?
The fastest way is just one command: php artisan optimize:clear. This single command clears every single cache mentioned—config, route, and views—in one go.
I agree with Barbara. The optimize:clear command is a lifesaver. It’s significantly more efficient than typing four individual commands and is now the industry standard for a quick "refresh" of the framework state during the development cycle or after a quick patch.
Joshua, that's a vital distinction. If Kimberly is using Redis, php artisan cache:clear will attempt to flush the Redis store defined in her configuration. However, if she has other data in Redis not managed by Laravel, she might need to be careful. For those using shared hosting where SSH access is limited, I usually recommend creating a temporary route in web.php that calls Artisan::call('cache:clear') via a browser request, though this should be deleted immediately after use for security reasons.