I have this odd error that only happens when I try to upload a new blade,
or update an already working blade file.
The error I get I've tried to remedy by trying to use chmod 777, but I'm to believe there is something with the actual blade file (not the code)
In short, I get this error:
So the odd thing is that the current project loads fine with each blade, but as soon as I make a change (or try to create a new blade) it gets this error.
I did see that there was a discrepancy in the file encoding but have changed that part now.
I tried to be specific on a fuzzy issue that I can't really get my head around
Edit:
Actual error message:
" UnexpectedValueException
The stream or file "/var/www/html/nu_web/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied"
If you're using CentOS 7, it could also be SELinux that makes it impossible to write to the log file.
If you have SELinux installed, you may want to know whether SELinux is on and which mode it is in. It is pretty straightforward.
Run the following command to check the current status & mode of SELinux:
$ sestatus
You can run the following command to set SELinux to permissive mode temporarily:
$ sudo setenforce 0
You may permanently disable SELinux on CentOS 7 if you want.
Run the following command to edit /etc/selinux/config SELinux configuration file:
$ sudo nano /etc/selinux/config
Now change SELINUX=enforcing to SELINUX=disabled
Now reboot your computer with the following command:
$ sudo reboot
Try running
sudo chmod -R 664 storage
sudo chmod -R 664 bootstrap/cache
in the route folder of your application, this will allow for errors to be added to the log file.
Run in your terminal
sudo chmod -R 777 /var/www/html/your_project name
I used 'composer update', which updated a few packages. During the updating process the website still functions. However, after it says 'The compiled services file has been removed', the website doesn't load and instead says:
Exception in ProviderRepository.php line 190:
The bootstrap/cache directory must be present and writable.
The weirdest thing is, when I run 'composer update' again, the website starts to work again, until the compiled services file is removed, at which point it throws the same error again. I have already tried the usual things that should be done when this error appears (chown -R everything to the right user/group and chmod all the files and folders 664 and 775 respectively).
I don't know what to do anymore, as the error doesn't seem 'correct'..
Try this after you have run the composer update:
php artisan cache:clear
On your Laravel directory file, run:
sudo chmod -R 777 bootstrap/cache/
The best way to resolve this error is:
Open your project folder
Move to the bootstrap directory
Create an empty folder named as cache
Then do PHP artisan cache:clear
This will work for sure
Short version: If uploading using something like AWS eb cli Verify if bootstrap/cache folder (not talking about its contents) is being deployed.
Some background behind my answer
I am using Amazon Web Services' Elastic Beanstalk to host my Laravel project. As I just started using Laravel I do not have much idea about its functioning. Two days back My new deployments were all crashing midway with OP's error message.
Earlier that day, I realised that I was not using
php artisan config:cache
to cache configurations to make things faster. And I added the same in composer.json's "post-install-cmd" and "post-update-cmd" clauses.
And I also added statement in .ebignore file to not upload the content of /bootstrap/cache (as its content is environment dependent a.k.a my localhost configurations have no meaning on my production server)
And facepalm I did not realise that this will stop the bootstrap/cache folder from being uploaded (as Like git, eb cli ignores empty folders).
So, when I started to deploy at night The deployments were meant to crash.
So, now I have just placed empty-placeholder (say) .gitkeep file in bootstrap/cache. And deployments are working once again :)
(Though the problem was so simple I realised the reason after ssh-ing and digging an EBS EC2 instance for some sweet sleep hours ~.~ )
For me, I manually created the cache folder inside bootstrap.
Try this too after you have run the composer update:
php artisan config:clear
Im using cmder on windows 10 in non elevated mode (Non-Admin).
command php artisan cache:clear did not work for me.
The folder bootstrap/cache did not exist.
I created the folder and removed readonly from both bootstrap and bootstrap/cache folder.
Both composer install and composer update are working now.
sudo chmod -R ug+rwx storage bootstrap/cache
hopefully, this will solve the problem.
it work for me run in project folder
sudo chmod -R 777 bootstrap/cache
than run
composer update
than run
cache:clear
First make sure bootstrap/cache dir is exist if not create a new one
mkdir -p bootstrap/cache/
Then run php artisan config:cache
Simple. There are applications that can block the directory. Like google drive synchronizer, One driver synchronizer, or any other application that is using windows explorer.
Delete cache folder. Create this again.
Try executing the following commands in your project root directory
composer update
then do
composer dumpautoload
this will avoid the necessity of messing with cache files
which may lead to whole new sort of issues
I don't imagine what I got done wrong with that before and no games around with that cashclearings had sense. But as it claims there was no 'cache' folder inside /bootstrapp . Had to have create it manually. Now it all rocks ok again
I had to create these five folders to be able to run artisan again.
mkdir bootstrap/cache
mkdir storage/framework
mkdir storage/framework/cache
mkdir storage/framework/views
mkdir storage/framework/sessions
Answer was found in this related question:
"Please provide a valid cache path" error in laravel
In my case, I've found out that the bootstrap/cache is missing in my project during a fresh clone.
Re-adding the cache directory manually solved my issue.
Then running composer install now works fine.
If a web server (e.g. Apache or Nginx) is being used as a front-end the solution is to make the directory bootstrap/cache owned by web server group. For Nginx:
$ sudo chgrp -R nginx bootstrap/cache
I am trying to set up symfony. I am running ubuntu, I have apache2, phpmyadmin and phpstorm installed. I am getting this error under config.php of my project:
MAJOR PROBLEMS Major problems have been detected and must be fixed
before continuing: Change the permissions of either "app/cache/" or
"var/cache/" directory so that the web server can write into it.
Change the permissions of either "app/logs/" or "var/logs/" directory
so that the web server can write into it.
so I went to /var
I tried a few things:
sudo thunar and then changed all the permissions to writeable. This didn't work and the permissions changed right after.
I went on this site, it says to use certain commands to fix permissions: sudo chmod 754 /var/cache and sudo chmod 754 /var/log and sudo chmod -R 775 /var/cache and sudo chmod -R 775 /var/log
This also did not work
I should also note that I have cleared my cache and restarted apache2.
Glad you figure it out by your self.
In any case you can read more about it here: Setting up Permissions / Symfony2
Let me know. Ciao!
I figured it out. The cache and log are within the app themselves. This did not make much sense to me initially considering that the permissions of the folder they are in (the root, the www folder) had already had all their permissions set appropriately. All I did was set chmod -R 755 on those folders IN my app.
This question already has answers here:
How to fix Error: laravel.log could not be opened?
(28 answers)
Closed 3 years ago.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Original close reason(s) were not resolved
I have setup Laravel homestead on a local OSX machine, everything seemed to be going smoothly until I tried to open example.app:8000 and got this error:
Error in exception handler: The stream or file "/home/vagrant/Code/example/app/storage/logs/laravel.log" could not be opened: failed to open stream: Protocol error in /home/vagrant/Code/example/bootstrap/compiled.php:8671
I followed the Laravel docs as well as a Laracast about setting up homestead, so I am not sure what would be causing this. I can see that /home/vagrant/Code/example/app/storage/logs/laravel.log doesn't exist, but I assume that is something that should be created automatically?
All files and folders under app/storage should be writable by you and group www-data (the webserver).
Error in exception handler: The stream or file "laravel/app/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied in laravel/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:77
If you get this error (or a similar error) in the browser when accessing your site, then the group www-data can't write to app/storage. If you get this error when you execute certain php artisan commands, then you (the user) can't write to app/storage. Therefore both you and the www-data group must have write permission.
To ensure the files and folders have the correct permissions:
Go to the root of your Laravel installation (where composer.json and artisan live).
Change the owning user and group, where yourusername is your username:
sudo chown -R yourusername:www-data app/storage
This recursively (-R) sets the user:group owners to yourusername:www-data in all files and folders from app/storage onward.
Add the write permission for both you and the www-data group:
sudo chmod -R ug+w app/storage
This recursively (-R) adds (+) the write flag (w) to the user (u) and group (g) that own the files and folders from app/storage onward.
Additionally, some suggest you may need to flush the application cache.
php artisan cache:clear
Finally, you may want to regenerate Composer's autoload files.
composer dump-autoload
As for me I had changed my storage permission with chmod -R 777 storage and it's work well.
However, setting 777 permissions is incredibly dangerous and should not be done on any server other than your local machine.
I had checked for this configuration at here.
You need to run one of the following:
sudo chmod -R 644 app/storage
sudo chmod -R 755 app/storage
If changing the file permissions as described in the other answers didn't work and you're using CentOS 7 or RHEL then the issue may be a security program called selinux. I struggled with all kinds of permissions and groups before noticing user3670777 answer to Laravel 4: Failed to open stream: Permission denied
Hope this helps others.
If All Above suggestions not working disable your selinux and try again
im pretty new on laravel. May be I could not explain it in depth but that command fixed my problem.
chmod -R 777 storage/
I am new to Laravel. I was trying to open http://localhost/test/public/ and I got
Error in exception handler.
I googled around and changed the permission of storage directory using chmod -R 777 app/storage but to no avail.
I changed debug=>true in app.php and visited the page and got Error in exception handler:
The stream or file "/var/www/html/test/app/storage/logs/laravel.log"
could not be opened: failed to open stream: Permission denied in
/var/www/html/test/bootstrap/compiled.php:8423
Then I changed the permissions of storage directory using the command chmod -R 644 app/storage and the 'Error in exception handler' error was gone and a page is loaded. But in there I am getting this:
file_put_contents(/var/www/html/laravel/app/storage/meta/services.json):
failed to open stream: Permission denied
Suggestion from vsmoraes worked for me:
Laravel >= 5.4
php artisan cache:clear
chmod -R 775 storage/
composer dump-autoload
Laravel < 5.4
php artisan cache:clear
chmod -R 775 app/storage
composer dump-autoload
For those facing this problem with Laravel 5, this is a permission issue caused by different users trying to write at the same log file within the storage/logs folder with different permissions.
What happens is your Laravel config probably is setup to log errors daily and therefore your web server (Apache/nginx) might create this file under a default user depending on your environment it can be something like _www on OSX or www-data on *NIX systems, then the issue comes when you might have run some artisan commands and got some errors, so the artisan will write this file but with a different user because PHP on terminal is executed by a different user actually your login user, you can check it out by running this command:
php -i | grep USER
If your login user created that log file your web server you will not be able to write errors in it and vice-versa because Laravel writes log files with 655 permissions by default which only allows the owner to write in it.
To fix this temporary you have to manually give permissions for the group 664 to this file so both your login user and web server user can write to that log file.
To avoid this issue permanently you may want to setup a proper permissions when a new file is create within the storage/logs directory by inheriting the permissions from the directory this answer https://unix.stackexchange.com/a/115632 can help you to tackle with that.
You should not give 777 permissions. It's a security risk.
To Ubuntu users, in Laravel 5, I sugest to change owner for directory storage recursively:
Try the follow:
sudo chown -R www-data:www-data storage
In Ubuntu based systems, www-data is apache user.
For everyone using Laravel 5, Homestead and Mac try this:
mkdir storage/framework/views
some times SELINUX caused this problem;
you can disable selinux with this command.
sudo setenforce 0
NEVER GIVE IT PERMISSION 777!
go to the directory of the laravel project on your terminal and write:
sudo chown -R your-user:www-data /path/to/your/laravel/project/
sudo find /same/path/ -type f -exec chmod 664 {} \;
sudo find /same/path/ -type d -exec chmod 775 {} \;
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
This way you're making your user the owner and giving privileges:
1 Execute, 2 Write, 4 Read
1+2+4 = 7 means (rwx)
2+4 = 6 means (rw)
finally, for the storage access, ug+rwx means you're giving the user and group a 7
Problem solved
php artisan cache:clear
sudo chmod -R 777 vendor storage
this enables the write permission to app , framework, logs Hope this will Help
For vagrant users, the solution is:
(in vagrant) php artisan cache:clear
(outside of vagrant) chmod -R 777 app/storage
(in vagrant) composer dump-autoload
Making sure you chmod in your local environment and not inside vagrant is important here!
Try again with chmod -R 755 /var/www/html/test/app/storage. Use with sudo for Operation not permitted in chmod. Use Check owner permission if still having the error.
As per Laravel 5.4 which is the latest as I am writing this, if you have any problem like this, you ned to change the permission.
DO NOT LISTEN TO ANYONE WHO TELLS YOU TO SET 777 FOR ANY DIRECTORY.
It has a security issue.
Change the permission of storage folder like this
sudo chmod -R 775 storage
Change bootstrap folder permission like this
sudo chmod -R 775 bootstrap/cache
Now please make sure that you're executing both commands from your application directory. You won't face problems in future regarding permission. 775 doesn't compromise any security of your machine.
Suggest the correct permission, if for Apache,
sudo chown -R apache:apache apppath/app/storage
FOR ANYONE RUNNING AN OS WITH SELINUX: The correct way of allowing httpd to write to the laravel storage folder is:
sudo semanage fcontext -a -t httpd_sys_rw_content_t '/path/to/www/storage(/.*)?'
Then to apply the changes immediately:
sudo restorecon -F -r '/path/to/www/storage'
SELinux can be a pain to deal with, but if it's present then I'd STRONGLY ADVISE you learn it rather than bypassing it entirely.
If you have Laravel 5 and looking permanent solution , applicable both php artisan command line usage and Apache server use this:
sudo chmod -R 777 vendor storage
echo "umask 000" | sudo tee -a /etc/resolv.conf
sudo service apache2 restart
See detailed explanation here.
I had the same issue and the below steps helped me fix the issue.
Find out the apache user - created a test.php file in the public folder with the code
<?php echo exec('whoami'); ?>
And run the file from the web browser. It would give the apache user. In my case, it is ec2-user as I was using the aws with cronjob installed in /etc/cron.d/. It could be different user for others.
Run the below command on the command line.
sudo chown -R ec2-user:<usergroup> /app-path/public
You need to identify and use the right "user" and "usergroup" here.
I had the same problem but in the views directory:
file_put_contents(/var/www/app/storage/framework/views/237ecf97ac8c3cea6973b0b09f1ad97256b9079c.php): failed to open stream: Permission denied
And I solved it cleaning the views cache directory with the following artisan command:
php artisan view:clear
Xampp for use:
cd /Applications/XAMPP/htdocs
chmod -R 775 test/app/storage
From Setting Up Laravel 4.x on Mac OSX 10.8+ with XAMPP
Any time I change app.php I get a permission denied writing bootstrap/cache/services.json so I did this to fix it:
chmod -R 777 bootstrap/cache/
rm storage/logs/laravel.log
solved this for me
Setting permission to 777 is definitely terrible idea!
... but
If you are getting permission error connected with "storage" folder that's what worked for me:
1) Set "storage" and its subfolders permission to 777 with
sudo chmod -R 777 storage/
2) In browser go to laravel home page laravel/public/ (laravel will create necessary initial storage files)
3) Return safe 775 permission to storage and its subfolders
sudo chmod -R 775 storage/
If using laradock, try chown -R laradock:www-data ./storage in your workspace container
In my case solution was to change permission to app/storage/framework/views and app/storage/logs directories.
After a lot of trial and error with directory permissions I ended up with an epiphany...there was no space left on the disk's partition. Just wanted to share to make sure nobody else is stupid enough to keep looking for the solution in the wrong direction.
In Linux you can use df -h to check your disk size and free space.
This issue actually caused by different users who wants to write/read file but denied cause different ownership. maybe you as 'root' installed laravel before then you login into your site as 'laravel' user where 'laravel' the default ownership, so this is the actually real issue here. So when user 'laravel' want to read/write all file in disk as default, to be denied, cause that file has ownership by 'root'.
To solving this problem you can follow like this:
sudo chown -hR your-user-name /root /nameforlder
or in my case
sudo chown -hR igmcoid /root /sublaravel
Footnote:
root as name first ownership who installed before
your-user-name as the default ownership who actually write/read in site.
namefolder as name folder that want you change the ownership.
If you use Linux or Mac, even you can also run in ssh terminal. You can use terminal for run this command,
php artisan cache:clear
sudo chmod -R 777 storage
composer dump-autoload
If you are using windows, you can run using git bash.
php artisan cache:clear
chmod -R 777 storage
composer dump-autoload
You can download git form https://git-scm.com/downloads.
If anyone else runs into a similar issue with fopen file permissions error, but is wise enough not to blindly chmod 777 here is my suggestion.
Check the command you are using for permissions that apache needs:
fopen('filepath/filename.pdf', 'r');
The 'r' means open for read only, and if you aren't editing the file, this is what you should have it set as. This means apache/www-data needs at least read permission on that file, which if the file is created through laravel it will have read permission already.
If for any reason you have to write to the file:
fopen('filepath/filename.pdf', 'r+');
Then make sure apache also has permissions to write to the file.
http://php.net/manual/en/function.fopen.php
Just start your server using artisian
php artisian serve
Then access your project from the specified URL:
I have the same issue when running vagrant on mac. solved the problem by changing the user of Apache server in https.conf file:
# check user for php
[vagrant] ubuntu ~ $ php -i | grep USER
USER => ubuntu
$_SERVER['USER'] => ubuntu
[vagrant] ubuntu ~ $
Run apache under php user instead of user daemon to resolve file access issue with php
# change default apache user from daemon to php user
sudo sed -i 's/User daemon/User ubuntu/g' /opt/lampp/etc/httpd.conf
sudo sed -i 's/Group daemon/Group ubuntu/g' /opt/lampp/etc/httpd.conf
now, php created cache file can be read and edit by apache without showing any access permission error.
I got same errors in my project...
But found out that I forgot to put enctype in my form.
<form method="#" action="#" enctype="multipart/form-data">
Hopes it helps somewhere somehow...
While working on Windows 10 with Laragon and Laravel 4, it seemed to me there was no way to change the permissions manually, since executing chmod-commands in the Laragon-in-built-terminal had no effect.
However, it was possible in this terminal to go to the storage folder and manually add the desired folders like this:
cd app/storage
mkdir cache
mkdir meta
mkdir views
mkdir sessions
The cd-command in the terminal brings you to the folder (you might need to adjust this path to suit your file structure).
The mkdir-command will create the directory with the given name.
I did not have the opportunity to test this approach in Laravel 5, but I expect that a similar approach should work.
Of course there might be a better way, but at least this was a reasonable workaround for my situation (fixing the error: file_put_contents(/var/www/html/laravel/app/storage/meta/services.json): failed to open stream).
First, delete the storage folder then again create the storage folder.
Inside storage folder create a new folder name as framework.
Inside framework folder create three folders name as cache, sessions and views.
I have solved my problem by doing this.