permission denied on database and file on web server - laravel

ErrorException (E_WARNING)
file_put_contents(/var/www/html/moha/storage/framework/sessions/rGlwXEnWZF6hnlZY9URsoioiFSjnDsHZyzpbJLiV):
failed to open stream: Permission denied

Try this. This command allows you edit your file in without root permission.
sudo chmod -R 777 /var/www/html/moha/storage/

Your webserver (Apache, Nginx or other) should be able to write on the storage directory. Consider that www-data is the webserver user (default), at root of your project, run the following commands:
sudo chown -R www-data. storage/
sudo chmod -R 777 storage/

Related

Laravel Project on local Xampp mysql error : file_put_contents: Failed to open stream: Permission denied

I have developed a laravel project on one laptop using local xampp mysql and want to install it on another laptop. I am having this error: file_put_contents(/Applications/XAMPP/xamppfiles/htdocs/sfms/storage/framework/sessions/VS0cObLn8ItoKMt5HQJOlZ0srelpMLsSwm5ZQcPa): Failed to open stream: Permission:
I have tried the following but they did not work:
php artisan cache:clear
php artisan config:clear
manually deleted vendor\laravel\framework\src\Illuminate\Foundation\Console\ConfigClearCommand.php
among others.
Please, I need your assistance. Thanks in advance.
you can run this command
sudo chown -R www-data:www-data ./storage ./bootstrap
And then use the command
sudo chmod -R 755 ./storage ./bootstrap
Run this two command for permission.
sudo chmod -R 777 ./storage
sudo chmod -R 777 ./bootstrap
I run the following code in the terminal and it worked for me:
chmod -R 777 storage

Laravel 8 is not working correctly, error "file_put_contents"

I'm having some weird problem with Laravel 8.
I installed the framework and started working with it, but when I try to edit / delete some controller, my Ubuntu asks for a password.
Another problem. My controller displays records on a page with paginate(15) pagination, but instead of the usual numbers, I get the Previous & Next direction, and when I try to change something in the html template, I get an error file_put_contents(/var/www/storage/framework/views/c6d615eb91fe3a0edd449165e94d034703bbb84d.php): failed to open stream: Permission denied and this problem can only be cured by clearing the cache, but this should not be the case.
Error #1: Your user does not have write permissions for those files/directories. Did you use sudo while installing or copying anything? Do you have these files outside of your home directory? (/home/username/)
Error #2: Your webserver (nginx, apache, etc.) probably does not have access to the application's /storage/ directory.
SSH into the server.
Navigate to the projects root folder.
Run the following commands to make the directories writable:
sudo chmod -R gu+w storage/
sudo chmod -R guo+w storage/
sudo chmod -R gu+w bootstrap/cache/
sudo chmod -R guo+w bootstrap/cache/

How to fix Error: laravel.log could not be opened Permission denied?

I'm pretty new at laravel,Actually when i create this command php artisan migration so i face this error how can i resolve this issue thanks.
Error
UnexpectedValueException : The stream or file
"/home/zubair/htdocs/project/storage/logs/laravel.log" could not be opened: failed to open
stream: Permission denied
If you run the command with sudo or chmod -R 755 some of the project's folders, you'll have it working.
sudo chmod -R 755 storage bootstrap/cache
Changing entire project folder's permission is probably not a good idea as your project becomes accessible to any user/script which kind of defeats the purpose of securing it behind root.
change a permission of storage folder
sudo chmod -R 775 /var/www/html/your-project/storage
for more info check this link install laravel in apache

Mac Laravel file_put_content fail permission problem

I have a project work in laravel (Mac) but I have a problem:
file_put_content fail () Permission denied.
I try below command
cd /path to htdocs
sudo chgrp -R _www storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
but it's not working
anyone know how to solve this problem. I use XAMPP, is that possible to set my XAMPP htdocs folder permission read&write, so I don't need to worry about this anymore
It's coming from cache. Delete bootstrap > cache > config.php file.
Then use php artisan config:cache.
you need to provide write access to your storage folder too.
try running :
sudo chmod -R 777 storage bootstrap
It will provide read & write and execute permissions to both storage and bootstap folder.

Laravel 5: laravel.log could not be opened: Permission Denied

To stop you from the start, there is NO permission issue. /storage is recursively chmodded 777 and whole project folder is chowned by apache:apache
I even renamed the log file to ...-old and apache created a new one... if it didn't have actual write permissions it would not had been allowed to create it.
Running under CentOS release 6.6 (Final)
Deployed the project from git, the homestead works for my colleague.
Full error:
[Mon May 18 10:17:58 2015] [error] [client 86.124.208.14] PHP Fatal
error: Uncaught exception 'UnexpectedValueException' with message
'The stream or file
"/var/www/vhosts/mapper.pavementlayers.com/storage/logs/laravel-2015-05-18.log"
could not be opened: failed to open stream: Permission denied' in
/var/www/vhosts/mapper.pavementlayers.com/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:84\nStack
trace:\n#0
/var/www/vhosts/mapper.pavementlayers.com/vendor/monolog/monolog/src/Monolog/Handler/RotatingFileHandler.php(88):
Monolog\Handler\StreamHandler->write(Array)\n#1
/var/www/vhosts/mapper.pavementlayers.com/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37):
Monolog\Handler\RotatingFileHandler->write(Array)\n#2
/var/www/vhosts/mapper.pavementlayers.com/vendor/monolog/monolog/src/Monolog/Logger.php(265):
Monolog\Handler\AbstractProcessingHandler->handle(Array)\n#3
/var/www/vhosts/mapper.pavementlayers.com/vendor/monolog/monolog/src/Monolog/Logger.php(543):
Monolog\Logger->addRecord(400, 'exception 'Symf...', Array)\n#4
/var/www/vhosts/mapper.pavementl in
/var/www/vhosts/mapper.pavementlayers.com/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php
on line 84
It could be that SElinux is preventing Apache from creating this file.
To test this you could disable SElinux temporally with the following command:
setenforce 0
This will place SElinux in permissive mode. This means that you still receive an error message in your SElinux log file but SElinux will not block the command.
To activate SElinux again you can type:
setenforce 1
Or reboot your CentOS server.
Unfortunately, I had also problems with Laravel 5 on CentOS and the cause was SElinux.
I ended up with disabling SElinux. I know it is not the right thing to do but I haven't had time to get the two working together yet!
Update
So I finally had sometime to investigate this further and I got SELinux working together with Laravel 5. I have just updated this post for people that might run into this issue cause. Disabling SELinux is not the best strategy as mentioned above.
Three things need to be done:
The folders Storage and Bootstrap/Cache need to have the right SELinux context. This can be achieved via the following commands:
semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/<Laravel Site>/storage(/.*)?"
semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/<Laravel Site>/bootstrap/cache(/.*)?"
The SELinux context needs to be applied on the directories:
restorecon -Rv "/var/www/<Laravel Site>/storage"
restorecon -Rv "/var/www/<Laravel Site>/bootstrap/cache"
The Apache user needs to have the rights to create files in both directories. This can be achieved via a ACL in CentOS 7:
setfacl -R -m u:apache:rwX storage/
setfacl -R -m u:apache:rwX bootstrap/cache/
The last thing you need to do is to enable SELinux again.
Try those commands for laravel 5
$ php artisan cache:clear
$ sudo chmod -R 777 app/storage
$ composer.phar dump-autoload
This happens because laravel do not have the permissions to write to the log file, at least for my case.
This worked for me, Laravel 5.4 and above
$ sudo chmod -R 755 storage/
$ sudo chown -R www-data storage/
$ sudo chgrp -R www-data storage/
$ php artisan cache:clear
$ php artisan config:cache
$ composer dumpautoload
Not all steps necessary.
You have to make sure the storage folder exists. If you're deploying from git, make sure the storage folder itself is tracked and created automatically.
ON Laravel 5.7
$ cd /var/www/html/
$ php artisan cache:clear
Application cache cleared!
for centos 7
# ausearch -c 'httpd' --raw | audit2allow -M my-httpd
# semodule -i my-httpd.pp
Since laravel.log is in the storage folder, so I will suggest you run this command on your terminal on Mac.
chmod -Rf 0777 storage

Resources