简体   繁体   中英

Error if not clearing cache after deployment

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?

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()));
        });
    }
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM