0

I am new in Laravel.

I am trying to delete the data folder which is under /storage/framework/cache/.

I did php artisan cache:clear which produces: Application cache cleared!

But when I go into the directory /storage/framework/cache/data then I see the old cache folders are still there and when I try to delete the folder manually then I get permission issue.

I have followed the below thread to give permissions to the storage folder.

How to set up file permissions for Laravel?

Permission level -

drwxrwsr-x   7  ubuntu   www-data 4096 Apr 24 22:48 storage
   drwxrwxr-x   7  ubuntu   www-data 4096 Apr 28 16:57 framework
     drwxrwxr-x   4  ubuntu   www-data 4096 Apr 29 18:32 cache
        drwxrwxr-x   39 www-data www-data 4096 Apr 29 20:36 data

I am logged in as a user subadmin who is under www-data group. I can though delete the folder manually after login as user ubuntu but not as subadmin

Any help is highly appreciated.

Prithviraj Mitra
  • 11,002
  • 13
  • 58
  • 99
  • What permission error message do you get? Furthermore your directory list shows that all folders are on the same level. Normally, it is `storage/framework/cache`. There seems some folders are not correctly in place. – codedge Apr 29 '20 at 21:56
  • @codedge I get permission denied when I try to delete any folder under data. Sorry for the folder structure here but it is correct as you said ie `storage/framework/cache` in original project directory. – Prithviraj Mitra Apr 29 '20 at 22:00

2 Answers2

2

Make the current user own everything inside the folder (and the folder itself):

sudo chown -R $USER /your/path

maybe you would like to do it for the apache folder like what i did

sudo chown -R $USER /var/www/

this should fix the permissions problem for you

RYOK
  • 473
  • 7
  • 23
0

Why do you want to delete cache/data directory?

I believe that folder is the part of default directory, of laravel

Default Stucture:

https://github.com/laravel/laravel/tree/master/storage/framework/cache

Which I believe by default is used by:

https://github.com/laravel/laravel/blob/master/config/cache.php#L53

If you want to make sure that your clear cache command works see the content of the data directory,

ThatBuffDude
  • 451
  • 4
  • 11
  • On your file permsision issue, are you sure `subadmin` is in `www-data` group? – ThatBuffDude Apr 29 '20 at 22:16
  • Yes subadmin is in www-data group. I also checked the contents of data folder after I issue the command `php artisan cache:clear` and the cache is still there. I actually wanted to delete the contents of `cache/data` directory. – Prithviraj Mitra Apr 29 '20 at 22:36
  • What's the permission of the cache file? – ThatBuffDude Apr 29 '20 at 22:45
  • Hmm that seems off to me, What about the configuration, do you have the right configuration? and are you sure the cached configuration is the one pointed to right cache dir? – ThatBuffDude Apr 29 '20 at 22:48
  • How can I check if the cached configuration is pointing to right cache dir? The permission of cache folder under data directory is - `drwxrwxr-x 3 www-data www-data 4096 Apr 29 17:31 19` Anything under data folder is owned by www-data – Prithviraj Mitra Apr 29 '20 at 22:50
  • No, I mean the cache file under the `cache/data` directory, not the directory – ThatBuffDude Apr 29 '20 at 22:51
  • To check the configuration, you can go to this file in your project, https://github.com/laravel/laravel/blob/master/config/cache.php#L34 , check whether the `stores` key member has the right configuration. If so, go to `/bootstrap/cache/config.php`, check whether the same key is value is correct, if it's not correct, you can regenerate your cahce using `php artisan config:cache` (make sure to use it with the right user though, otherwise your web server can't read it) – ThatBuffDude Apr 29 '20 at 22:55
  • There are several directories under data. For eg one of the folder name is `d7`and under d7 there is another folder `1a` and under this folder the file is - `d71abc6f5c2b4b9af7089bfcf1d25e27447697e4`.The permission is `-rwxrwxr-- 1 www-data www-data 8902 Apr 29 17:31 d71abc6f5c2b4b9af7089bfcf1d25e27447697e4` – Prithviraj Mitra Apr 29 '20 at 22:56
  • OK the file looks good to me, be aware that if the web server is running, your app might create a new cache file, make sure the check the new file timestamp or check whether the old cache file is deleted – ThatBuffDude Apr 29 '20 at 23:00
  • Ok thanks. I will check more deeper tomorrow morning. – Prithviraj Mitra Apr 29 '20 at 23:04
  • I think it's the user `subadmin` who is under `www-data` group has no enough permission to delete the cache/data directory contents which is owned by `www-data`. It's a linux permission issue rather laravel issue but just can't figure out how to let the user subadmin give the permission to delete cache content.. – Prithviraj Mitra Apr 29 '20 at 23:21
  • 1
    File deletion permission is based on your directory permission, check the dir permission that you want to delete, make sure you have `w` in dir permission in group section, can check whether the result `groups` command executed as `subadmin` has the `www-data` ? Do you enable selinux or apparmor? – ThatBuffDude Apr 29 '20 at 23:31
  • 1
    It's fixed now. I had to give the group W permission. Thank you for your help. – Prithviraj Mitra Apr 30 '20 at 07:48