Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Laravel cache:clear says Failed to clear cache

ErrorFailed 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.

  • Applies to PHP 8.3, Laravel 12
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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/cache
  2. 2Match what you see, then jump to its fix

    1. 1The 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. 2CACHE_STORE=database and the migrations that create the cache table never ran.The database cache driver has no cache tableFix
    3. 3CACHE_STORE=redis or memcached, and the server or the PHP extension is missing.The Redis or Memcached store cannot be usedFix

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)" | head

2Fix

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/cache

3Verify

The clear works.

php artisan optimize:clear

Confirmed by laravel.com

Did this fix it?

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

2Fix

Create the migration if it is missing and run migrations.

php artisan make:cache-table
php artisan migrate

3Verify

The clear works.

php artisan optimize:clear

Confirmed by laravel.com

Did this fix it?

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/predis

2Fix

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=file

3Verify

Clear the configuration cache, then clear the application cache.

php artisan optimize:clear

Confirmed by laravel.com

Did this fix it?

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 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 fix

Back 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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.