Laravel cache:clear says Failed to clear cache
Failed to clear cache. Make sure you have the appropriate permissions.Short answer
The cache clear could not reach or write to the store set in CACHE_STORE. For the file driver that is a folder under storage the current user cannot write to. For the database, Redis or Memcached drivers it is a missing table, extension or server. Find your store first, then fix that one.
Fix it fast
1Find out which cause you have
See which cache store is configured and who owns the folders Laravel writes to.
grep -E '^CACHE_(STORE|DRIVER)' .env ls -ld storage storage/framework/cache bootstrap/cache2Match what you see, then jump to its fix
- 1
The store is file and ls shows the folders owned by another user (often root or the web server) without group write.The user running artisan cannot write to storage or bootstrap/cacheFix - 2
CACHE_STORE=database and the migrations that create the cache table never ran.The database cache driver has no cache tableFix - 3
CACHE_STORE=redis or memcached, and the server or the PHP extension is missing.The Redis or Memcached store cannot be usedFix
- 1
What does the error look like?
Failed to clear cache. Make sure you have the appropriate permissions.
Cause 1 of 3
The user running artisan cannot write to storage or bootstrap/cache
1Check
Laravel writes to bootstrap/cache and storage, so whoever runs the command and the web server process both need permission. Running artisan with sudo once creates files that your normal user cannot later delete.
whoami
find storage bootstrap/cache ! -user "$(whoami)" | head2Fix
Give your deploy user and the web server user write access to both folders. The group name below is an example for Debian-based servers.
sudo chown -R "$USER":www-data storage bootstrap/cache
chmod -R ug+rwX storage bootstrap/cache3Verify
The clear works.
php artisan optimize:clearConfirmed by laravel.com
Cause 2 of 3
The database cache driver has no cache table
1Check
The database driver stores entries in a table, normally created by the default cache-table migration. If your project lacks that migration, Laravel has a command that generates it.
php artisan migrate:status2Fix
Create the migration if it is missing and run migrations.
php artisan make:cache-table
php artisan migrate3Verify
The clear works.
php artisan optimize:clearConfirmed by laravel.com
Cause 3 of 3
The Redis or Memcached store cannot be used
1Check
Redis needs the PhpRedis extension or the predis/predis package. Memcached needs the Memcached PECL package, and the servers are listed in config/cache.php. If the server at that host and port is down, a clear cannot go through.
php -m | grep -i -E 'redis|memcached'
composer show predis/predis2Fix
Install the missing client, point the host settings at a running server, or switch CACHE_STORE to a store you actually have.
# .env
CACHE_STORE=file3Verify
Clear the configuration cache, then clear the application cache.
php artisan optimize:clearConfirmed by laravel.com
How do I stop it coming back?
- Run artisan and deploys as one deploy user; avoid sudo for artisan.
- Create storage and bootstrap/cache with the right group in your provisioning script.
- Keep the cache store the same in .env on every server, and check its prerequisites on a new one.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Composer says the gd extension is missing on a Laravel project
composer install or composer update stops on a package that requires ext-gd
Composer refuses to install a package that requires ext-gd when the PHP binary running Composer has no GD extension.
4 causes, each with a fixBack end
composer require maatwebsite/excel fails to install
Composer says the package needs an older PHP than the one installed
Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.
3 causes, each with a fixBack end
composer install says the lock file is not compatible and asks for update
Your lock file does not contain a compatible set of packages. Please run composer update.
composer install checked the locked packages against this machine's PHP and extensions and found a conflict.
3 causes, each with a fixBack end
composer require laravel/horizon fails: ext-pcntl is missing
laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system
Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.
3 causes, each with a fixBack end
composer require laravel/passport stops with 'requirements could not be resolved'
... but these were not loaded, likely because it conflicts with another require.
Composer found no Passport release that fits your project at once.
4 causes, each with a fixBack end
Composer says the root composer.json requires a PHP version your PHP does not satisfy
Your requirements could not be resolved to an installable set of packages.
Composer compares the php constraint in your composer.json, or in a package, with the PHP that runs Composer.
3 causes, each with a fix