Home > Mobile >  Error if not clearing cache after deployment
Error if not clearing cache after deployment

Time:09-10

In my Laravel app, I sometimes want to pull the latest version from GitHub without clearing the cache first.

So I just do:

git pull origin staging

But every time I do this and then open the page in the browser, I get this error:

ErrorException (E_WARNING)
file_put_contents(/path/to/laravel/storage/framework/cache/data/30/6c/306cbe845aa9840ab0c14a1cd4b5d83fd6728839): failed to open stream: Permission denied

However, if I just do php artisan cache:clear this issue doesn't happen.

This isn't ideal because I'd sometimes like to keep the cache when I pull changes from Git. We use caching extensively (on every request) and it's a performance issue if we have to clear it on every update.

For example, the last time this happened, my only change was to a View file. No need to mess with the existing cache.

How can I pull changes from Git without clearing the cache and without encountering errors?

CodePudding user response:

My storage folder lives outside the laravel folder. That way I can keep the cache and log files when I update my project.

For this I'm using a custom app where the storage path is defined in the .env.

<?php
namespace App;

use Illuminate\Foundation\Application;

class CustomApp extends Application
{
    public function __construct($basePath = null)
    {
        parent::__construct($basePath);

        $this->afterLoadingEnvironment(function () {
            $this->useStoragePath(env('STORAGE_PATH', storage_path()));
        });
    }
}

CodePudding user response:

The issue may be someone committed a logfile into the repository. Follow these

  1. Give Permission to storage file.

    Navigate to project folder in terminal
    And run chmod -R 755 storage/*

  2. check .gitignore contains /storage/logs path.

Not only on your side on everyone who works in the same repository.

  • Related