Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

anupambista's avatar

Laravel Cache does not store cache file on production server

have a problem with the Laravel Cache system (I use Laravel 5.6).

On my local server, the "app/storage" folder where Laravel store cache's files is with 755 permission. On my production server, the same folder has the same permission code. On my local server, when I cache datas using the Laravel's Cache Class, it works. So If I go within the "app/storage" folder, I can see the files created. On my production server, it doesn't.. Files aren't created in the cache folder within "app/storage" whereas session and views folders (present in app/storage) has files stored. I can confirm it cause it always go inside my if statement using has method even if I put my $datas using the put method of Cache Class.

app/config/cache.php

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Default Cache Store
    |--------------------------------------------------------------------------
    |
    | This option controls the default cache connection that gets used while
    | using this caching library. This connection is used when another is
    | not explicitly specified when executing a given caching function.
    |
    | Supported: "apc", "array", "database", "file", "memcached", "redis"
    |
    */

    'default' => env('CACHE_DRIVER', 'file'),

    /*
    |--------------------------------------------------------------------------
    | Cache Stores
    |--------------------------------------------------------------------------
    |
    | Here you may define all of the cache "stores" for your application as
    | well as their drivers. You may even define multiple stores for the
    | same cache driver to group types of items stored in your caches.
    |
    */

    'stores' => [

        'apc' => [
            'driver' => 'apc',
        ],

        'array' => [
            'driver' => 'array',
        ],

        'database' => [
            'driver' => 'database',
            'table' => 'cache',
            'connection' => null,
        ],

        'file' => [
            'driver' => 'file',
            'path' => storage_path('framework/cache'),
        ],

        'memcached' => [
            'driver' => 'memcached',
            'persistent_id' => env('MEMCACHED_PERSISTENT_ID'),
            'sasl' => [
                env('MEMCACHED_USERNAME'),
                env('MEMCACHED_PASSWORD'),
            ],
            'options' => [
                // Memcached::OPT_CONNECT_TIMEOUT  => 2000,
            ],
            'servers' => [
                [
                    'host' => env('MEMCACHED_HOST', '127.0.0.1'),
                    'port' => env('MEMCACHED_PORT', 11211),
                    'weight' => 100,
                ],
            ],
        ],

        'redis' => [
            'driver' => 'redis',
            'connection' => 'default',
        ],

    ],

    /*
    |--------------------------------------------------------------------------
    | Cache Key Prefix
    |--------------------------------------------------------------------------
    |
    | When utilizing a RAM based store such as APC or Memcached, there might
    | be other applications utilizing the same cache. So, we'll specify a
    | value to get prefixed to all our keys so we can avoid collisions.
    |
    */

    'prefix' => 'laravel',

];
0 likes
6 replies
martinbean's avatar

@anupambista What cache driver are you using in production? What happens if you try and cache something? Do you get an error message?

anupambista's avatar

@martinbean I am using file driver. It doesnot show any error but cache file is not created


$data['testimonies'] = Cache::remember('testimonies', 60*60*24, function () {
    return Feedback::join('users', 'users.id','=','feedbacks.user_id')
                                      ->select(['feedbacks.title','feedbacks.description','users.name','users.image'])
                                      ->where('feedbacks.read_status', 1)
                                      ->orderBy('feedbacks.updated_at', 'desc')
                                      ->get();
});
LoaiDev's avatar

Just a guess but your permissions for the specific folder "storage/framework/cache" might not be set correctly or has the wrong user owenrship (www-data:www-data on ubuntu), but this should have given you a "permission denied" error so i am not really sure.

anupambista's avatar

@LoaiDev I tried to create file in cache folder with fopen() and it successfully created the file

Snapey's avatar

I tried to create file in cache folder with fopen() and it successfully created the file

This in itself means nothing.

If you do is from the CLI or from an artisan command then you are using whatever account you are logged in as.

When you do this from within a web request, you are using the service account that the webserver uses (often www-data)

Its not sufficient to know the permissions, you also need to know the owner and group of both the directory and the files.

if you use ls -la this will show the owner and group

anupambista's avatar

@Snapey when i run the command ls -la in terminal, its shows

total 108
drwxr-xr-x 5 entrance entrance  4096 Jun  1  2019 .
drwxr-xr-x 5 entrance entrance  4096 Jun  1  2019 ..
-rw-r--r-- 1 entrance entrance   103 Apr  4  2018 .gitignore
drwxr-xr-x 2 entrance entrance  4096 Sep 16 22:45 cache
drwxr-xr-x 2 entrance entrance 69632 Sep 22 08:53 sessions
drwxr-xr-x 2 entrance entrance 20480 Sep 11 21:07 views

Please or to participate in this conversation.