Laravel - The stream or file failed to open stream: Permission denied - laravel

I know this is a common problem on Laravel, but I think I'm having a different issue or else the settings aren't being updated.
I've looked at this Laravel The stream or file "/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied and this How to set up File Permissions for Laravel 5 (and others) but I still have this issue:
The stream or file "/var/www/html/laravelwebapp/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied
When I do this after going into the logs directory: $ ls -l laravel.log
I get this:
-rwxrwxr-x 1 apache apache 0 Feb 8 2018 laravel.log
I'm on CentOS which is why the group/user is apache not www-data. Yet even though the log is created by apache and apache is the owner and group, it can't open the stream? Does this mean Laravel is executing as another user? I'm a bit confused here, sorry :/
I've cleared the cache using artisan and also ran composer dump-autload but I can't seem to progress in my application because the log doesn't get written to.
Update: My php application is running as nobody when I run
echo exec('whoami');
Is this the problem and how do I fix that?

Related

Laravel Sail command does not run in WSL2

I set up an app using Laravel Sail, and hosted it in my C:Users/User/my_app folder, however API endpoints were terribly slow (around 7s to respond).
I decided to move my application to the WSL filesystem. I copied my_app folder to \\wsl$\Ubuntu-20.04\home folder. However, when I type ./vendor/bin/sail up command nothing happens. No error message, no "command not found message", nothing.
I tried changing home/my_app permissions as well as vendor/bin/sail permissions but it has not helped me. I have no idea how to solve this problem as I am not receiving any message from the console.
I think I solved the issue with copying the files from Windows to WSL using cp command run from WSL console (cp /mnt/c/users/..... ).
However I stubmled upon this error Laravel & Docker: The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied which I solved using the answers from this github thread https://github.com/aschmelyun/docker-compose-laravel/issues/49.
Now my endpoint response times are usually under 100ms.

Wordpress Multisite... Warning: fopen(F:\htdocs/wp-content/plugins/1626892348): failed to open stream: Permission denied in~ Apache on windows 10

getting the error message in the wordpress dashboard
"Warning: fopen(F:\htdocs/wp-content/plugins/1626892348): failed to open stream: Permission denied in F:\htdocs\wp-includes\functions.php on line 6333"
this is a wordpress multisite installed on windows 10 using Apache.
been banging my head over this for the last 6 hours and nothing I google seems to help.
The file referenced in your functions.php line 6334 must be accessible to PHP, so you need to ensure that the file access permissions allow this access.

"laravel.log could not be opened" error on Elastic Beanstalk

I've deployed a Laravel application on AWS ElasticBeanstalk (PHP 7.3 running on 64bit Amazon Linux/2.9.7).
The application runs fine when it does, but randomly throws following error for few requests.
PHP Fatal error: Uncaught UnexpectedValueException: The stream or
file "/var/app/current/storage/logs/laravel.log" could not be opened:
failed to open stream: Permission denied in
/var/app/current/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:110\nStack
trace:\n#0
/var/app/current/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(42):
Monolog\Handler\StreamHandler->write(Array)\n#1
/var/app/current/vendor/monolog/monolog/src/Monolog/Logger.php(323):
Monolog\Handler\AbstractProcessingHandler->handle(Array)\n#2
/var/app/current/vendor/monolog/monolog/src/Monolog/Logger.php(541):
Monolog\Logger->addRecord(400, 'Unhandled Excep...', Array)\n#3
/var/app/current/vendor/laravel/framework/src/Illuminate/Log/Logger.php(174):
Monolog\Logger->error('Unhandled Excep...', Array)\n#4
/var/app/current/vendor/laravel/framework/src/Illuminate/Log/Logger.php(87):
Illuminate\Log\Logger->writeLog('error', 'Unhandled Excep...',
Array)\n#5
/var/app/current/vendor/laravel/framework/src/Illuminate/Log/LogManager.php(54
in
/var/app/current/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php
on line 110
I dont understand why it throws error for some requests only and not others. Nonetheless i tried applying the permissions to the storage and bootstrap folders as suggested by few posts through .ebextensions as below but did not get it working.
"/opt/elasticbeanstalk/hooks/appdeploy/post/99_make_storage_writable.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
echo "Making /storage and /bootstrap writeable..."
chmod -R 777 /var/app/current/storage
chmod -R 777 /var/app/current/bootstrap
Can someone please help me here? I'm new to Laravel and AWS both and very confused as to what might be wrong here.
The problem is your setting the owner to root:root and the apache user is ec2-user.
When you delete the existing log, the correct user will create the new log and it'll work as needed. You could also chown the files to the ec2-user and that would work too.

xampp ubuntu laravel The stream or file "/storage/logs/laravel log" could not be opened: failed to open stream: Permission denied

installed laravel on my xampp installation on ubuntu. opened it in browser. got the error:
The stream or file /storage/logs/laravel log could not be opened: failed to open stream: Permission denied
how to fix? (i've already found an answer, will post right now)
the problem is that the user under which the apache runs doesn't have access to the folder. in xampp on ubuntu, the user of main apache process is root. but apache workers run under daemon user. the solution is to grant daemon access to the /storage dir. (if you'll only grant to /storage/logs than you'll fix this error, but the same error will occur with sibling dirs. thus the storage itself folder:
sudo chown -R daemon /path-to-your-project/storage
now the daemon user has access to this folder (and you don't but do you need it?
if you have better solutions, please feel free to share them here!
Add to composer.json
"scripts": {
"post-install-cmd": [
"chgrp -R www-data storage bootstrap/cache",
"chmod -R ug+rwx storage bootstrap/cache"
]
}
Then run composer install or update solve your issue

Persistent Permission Denied Error

I have seen a few posts on this (and tried the recommended solutions) but they are regarding Laravel 4 - And I am on Laravel 5.
For example;
'Failed to open stream: Permission denied' error - Laravel
I get the Command "dump-autoload" is not defined error and the reason for that is explained here;
http://laravel.io/forum/12-08-2014-command-dump-autoload-is-not-defined
In the above post, composer dump-autoload was suggested. I tried it, and again this morning the same error is back;
ErrorException in Filesystem.php line
74:file_put_contents(/vagrant/source/laravel- excel/storage/
framework/sessions/8338f386fc3de7bdc8d1b6dc7ee6790f71516d98): failed
to open stream: Permission denied`
Any suggestions?
Also, try the above comments and do a
composer self update
You Have to set the permission to Read & Write
In Mac We do this by using
**sudo chmod -R o+w storage**
Storage is the name of file U want to change permission
And currently my terminal is in the same folder where my storage folder is present therefore I did not specify its address

Resources