Laravel 8 permission denied in shared hosting - laravel

I have my laravel 8 app hosted in hostinger hpanel but for hours I have trying to fix this error.
UnexpectedValueException There is no existing directory at "There is no existing directory at "/Users/macbookpro/Documents/Theodory/projectName/storage/logs" and it could not be created: Permission denied" and it could not be created: Permission denied missing folder is from my machine instead of cpanel path.
I have tried find and delete ../bootstrap/cache/config.php but there is no such a file and I have tried to delete all storage/logs but am still getting that error and I have tried to add manually in web.php
Route::get('/optimize',function(){
Artisan::class('optimize:clear');
});
But when I hit /optimize am still getting the same error.
I have decided to use hostinger ssh so that I can be able to run artisan commands but am still getting same error even after hitting artisan commands successful.
What can I make it work in hostinger hpanel to which is similar to traditional cpanel.

try the following commands and hit again /optimize
php artisan route:clear
php artisan config:clear
php artisan cache:clear

try these artisan commands
php artisan optimize:clear
after that, you should run this command
php artisan optimize

you are facing this issue because your application doesn't have proper permissions for the storage directory.
Use this command to grant required permissions to the storage directory, and this should resolve the issue.
chmod 777 -R storage/

Related

Please provide a valid cache path error in Laravel 9

I'm working with Jetstream library with Laravel 9, And I've deleted the storage folder by the wrong, and then it shows the following error.
Please provide a valid cache path.
What should I do? I tried the command composer install, and I faced the same error! So how can I return back to the storage folder?
create the following
storage/app
storage/app/public
storage/framework
storage/framework/cache
storage/framework/cache/data
storage/framework/views
storage/framework/session
storage/logs
And use git to manage your code so that accidents like this are easily recovered
Open your terminal.
Run cd YOUR_LARAVEL_PATH to navigate to the Laravel directory.
Run mkdir storage/framework/{cache,sessions,views} to create missing directories.
Run php artisan cache:clear
Run php artisan config:clear
Run php artisan view:clear
Run chmod -R 777 storage to set write permissions (depends on your system).

Laravel Failed to open stream error with Sail

I'm attempting to run Sail within my Laravel project and it all starts as expected but when I go to https://localhost I get an error 500 in the browser and this error in the log
PHP Fatal error: Uncaught ErrorException: file_put_contents(/home/harry/booker/storage/framework/views/31194b376a867d7e5a56653be65b2bc7a5c4040b.php): Failed to open stream: No such file or directory in /var/www/html/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:187
I know the directory /storage/framework/views exists as I can see it in my code editor. I've tried deleting my bootstrap/cache/config.php, running php artisan config:clear && php artisan config:cache but with no luck? The bootstrap config.php file has the correct reference to the views folder. I've also made sure the permissions are correct by running sudo chmod -R 755 storage/
You mention the /storage/framework/views directory exists, but does it contain the requested file 31194b376a867d7e5a56653be65b2bc7a5c4040b.php?
Also, can you try running the following in your terminal:
php artisan optimize:clear
php artisan view:cache
This should empty all Laravel caches and rebuild the views cache.

Accidentally deleted laravel.log from Laravel 8; now, the engine wouldn't populate the it with error messages

I wanted to free up the space stored in laravel.log under storage\logs. But when I did, it stopped working, and so I manually removed the laravel.log into the trash bin hoping that laravel would generate a new log file, but it didn't. So, I created a new laravel.log manually. I ran php artisan config:cache and php artisan view:clear to help solve this issue.
Without having to reinstall the whole thing, are there ways to fix this?
To resolve in Windows 10:
Navigate to your project directory, to storage\logs and create a file called laravel.log
Then run php artisan view:clear and php artisan config:cache
deleting storage/logs/laravel.log shouldn't create any issue, you can recreate the file by the name of laravel.log then add permission to the log file (in ubuntu) by running sudo chmod -R a+rwx /var/www/html/appplication-name/storage/logs and then run php artisan cache:clear, php artisan config:cache.

Laravel showing "Failed to clear cache. Make sure you have the appropriate permissions"

Laravel was displaying to me "Access denied for user 'homestead'#'localhost' (using password: YES)". One solution for this was clearing the cache and the config cache stored, all this with these three commands:
php artisan cache:clear
php artisan config:clear
php artisan config:cache
After php artisan cache:clear, terminal says:
Failed to clear cache. Make sure you have the appropriate permissions. (with red background)
Doing the second and third code (php artisan config:clear and php artisan config:cache) works fine! But it still gives me the error when typing the first line. Can anyone explain why?
If the data directory doesn't exist under (storage/framework/cache/data), then you will have this error.
This data directory doesn't exist by default on a fresh/new installation.
Creating the data directory manually at (storage/framework/cache) should fix this issue.
Try deleting these cached files under bootstrap folder:
/bootstrap/cache/packages.php
/bootstrap/cache/services.php
/bootstrap/cache/config.php
Then run php artisan cache:clear
Calling
php artisan config:cache
before
php artisan cache:clear
fixed the issue.
Just only add folder named data in storage/framework/cache/ and try:
php artisan cache:clear
First try:
Check if there is a "data" folder inside "storage/framework/cache/".
If there is not, then create it manually. (create a new folder with name "data")
Option 2:
If there is a "data" folder inside "storage/framework/cache/".
Remove ALL existing folders inside there.
Then final, running this:
php artisan cache:clear
This should fix this issue: "Failed to clear cache. Make sure you have the appropriate permissions."
Calling the following 4 commands should fix most of the permission issues on laravel.
sudo chown -R $USER:www-data storage
sudo chown -R $USER:www-data bootstrap/cache
chmod -R 775 storage
chmod -R 775 bootstrap/cache
Basically, chown -R $USER:www-data what this does is it set current user $USER as owner and www-data as group and chmod -R 775 gives 7 to user,7 to group and 5 to other.
#PS: You need to run above command from the laravel project directory, else, you need to provide full path like /var/www/project_name/storage
In Laravel 8 I solved my issue by first running composer dump-autoload and then used php artisan config:cache
Deleting and adding back the ./storage/framework/cache/data folder worked for me.
You should update the permission using the below steps:
Check user using command "whoami" then let output is "ironman"
Run below command if "data" folder exists in the cache directory
sudo chown -R ironman:ironman storage/framework/cache/data/
This will resolve your below issue
Delete all subfolders under:
storage/framework/cache/data/
I ran my project in a docker container, then later tried accessing it via laragon, I had similar issue, this was due to compiled configurations in /bootstrap/cache/config.php.
I fixed fit by running php artisan config:clear, this deletes the /bootstrap/cache/config.php file automatically.
I had the same problem but noticed if you run php artisan config:clear it also by default runs cache:clear right after it so when you run it again there is not cache in it and gives that error. you only need to run php artisan config:clear. I am not sure why cache:clear fails when its ran alone but running the config:clear is a good alternative.
Here is a helpful alias i use to clear everything in the app.
laraclear='php artisan config:cache && php artisan config:clear && php artisan view:clear && php artisan route:clear && php artisan telescope:clear && php artisan debugbar:clear'
Remove any unwanted commands that you do not use in it.
(For MAC Users)
Sometimes, it means current user don't have sufficient permission to the storage/framework/cache/data/ folder. Run
sudo chmod -R ug+rwx storage/framework/cache/data/
then
php artisan cache:clear
Hope sometimes it work for you.
In my case the problem was I had 'CACHE_DRIVER=memcached' in .env but didn't have memcached installed. Switching to the file driver or installing memcached fixed the problem for me.
You may need to clear the autoloader with
composer dump-autoload
If that doesn't work you can manually remove the following non-tracked (usually) files to clear the autoloader and cache if they get jammed up:
/bootstrap/cache/packages.php
/bootstrap/cache/services.php
Can't this solve it?
$php artisan optimize:clear
Compiled views cleared!
Application cache cleared!
Route cache cleared!
Configuration cache cleared!
Compiled services and packages files removed!
For Laravel Homestead on Windows:
In your .env file, change your CACHE_DRIVER from file to memcached.
Run php artisan cache:clear.
Had the same problem on my vagrant/homestead VM. All the other things in this thread didn't help.
The solution was vagrant reload --provision
Giving 775 permission to the storage directory solved this problem for me.
sudo chmod -R 775 storage
I am running my project in Homestead.
My environment :
Ubuntu1~20.04+
Laravel 6.20.26
My output
display real fatal info
Edit src/Illuminate/Filesystem/Filesystem.php 598:14
original code:
if (! $preserve) {
#rmdir($directory);
}
debug code
if (! $preserve) {
rmdir($directory);
}
Then re-execute php artisan cache:clear
The output changed:
Then, I just resolve Text file busy
Ensure APP_URL is properly set on .env file. Changing http to https in the APP_URL variable on .env file solved it for me.
Solution :
update the permission :
get user name by this command : whoami
Run command if "data" folderexists in the cache directory.
sudo chown -R YourUSERName:YourUSERName storage/framework/cache/data/
In my case, there is no cache available that's why the artisan is unable to delete or reset the cache.
First browse the website and allow it to create some cache then try to clear it.
You can check whether the cache is available or not in directory storage/framework/cache/*
got the same error. try giving chmod 777 permission in the concerned folder
My guess is you have a permission/ownership problem. Either set up the permissions correctly or recursively delete the cache folder manually and re-create it:
sudo rm -Rf storage/framework/cache
mkdir storage/framework/cache
maybe you need to chmod 777 -R storage folder.
and i think it can also chown www-data:www-data
Incase non of these works for you, simply run your php artisan cache:clear command with sudo.
e.g. sudo php artisan cache:clear
Thank me later~!

laravel cache failed to open stream: No such file or directory framework/views

I use laravel 5.4. a clear cache after update config file. that appear like this error.
ErrorException in Filesystem.php line 111:
file_put_contents(/home/web_user/webhosts/mufer/backend.mufer.local/storage/framework/views/318a49f22562be3fc1c86c88ecc141c22e`8fed4e.php): failed to open stream: No such file or directory`
Then i try to fixed using following command:
php artisan route:cache
php artisan view:clear
php artisan config:cache
and:
file_put_content...fail to open stream:Permission denied in Laravel 5
Some answer are said craete /storage/framework sub folders and then composer update. but that also not working.
screen shot
Then i run composer dump-autoload
andcomposer update`.
But problem not solved..
Perhaps you are using Homestead?
I ran into this problem when using Homestead. Basically, when you are using Homestead and run the php artisan config:cache command out of your virtual machine, the cache paths get broken.
I solved it login via ssh to Homestead vagrant ssh and running php artisan config:cache from there.
My solution was to chmod /storage/framework/views directory to 777.
I had this same problem and my mistake was so simple it's hilarious.
I forgot to git add one of my files. So on the backend, it was trying to get this file.php but it didn't exist. It's usually quite descriptive in the error, except, I was running a job that jumps on a queue. All of a sudden, that helpful exception no longer exists :D
So in order to fix it, I had to:
git add -A
git commit -m "blah blah"
git push
On the server, I needed to:
git pull
composer dump-autoload
It's worked for me gently:
php artisan view:cache

Resources