How to fix Error: laravel.log could not be opened?
Solution 1:
Never set a directory to 777. you should change directory ownership. so set your current user that you are logged in with as owner and the webserver user (www-data, apache, ...) as the group. You can try this:
sudo chown -R $USER:www-data storage
sudo chown -R $USER:www-data bootstrap/cache
then to set directory permission try this:
chmod -R 775 storage
chmod -R 775 bootstrap/cache
Update:
Webserver user and group depend on your webserver and your OS. to figure out what's your web server user and group use the following commands. for nginx use:
ps aux|grep nginx|grep -v grep
for apache use:
ps aux | egrep '(apache|httpd)'
Solution 2:
Never use 777 for directories on your live server, but on your own machine, sometimes we need to do more than 775, because
chmod -R 775 storage
Means
7 - Owner can write
7 - Group can write
5 - Others cannot write!
If your webserver is not running as Vagrant, it will not be able to write to it, so you have 2 options:
chmod -R 777 storage
or change the group to your webserver user, supposing it's www-data
:
chown -R vagrant:www-data storage
Solution 3:
To fix this issue, you need to change the ownership of the directory to the unix user that the webserver uses.
- Get out of the VM
- Using the console, go to your synced folder (vagrant)
- sudo chown -R $USER:www-data storage
- chmod -R 775 storage
Even though I created the project within the VM using the VM user, the folder belonged to the user in the real computer; so, when trying to
Now it's working.
Thanks to all those that helped me figure this thing out
EDIT:
Actually, it still wasn't working, it still gave me a "permission denied" problem.
Here's what I did, I modified my Vagrantfile like this:
config.vm.synced_folder "./app","/var/www/", create:true,
:owner => "vagrant",
:group => "www-data",
:mount_options => ["dmode=775","fmode=664"]
Solution 4:
It also may be SELinux. (Centos, RedHat)
Determine status of SElinux on terminal:
$ sestatus
If status is enabled, write command to disable SElinux
$ setenforce Permissive
Or you may execute this command
$ sudo setenforce 0
Solution 5:
You need to adjust the permissions of storage
and bootstrap/cache
.
-
cd
into your Laravel project. sudo chmod -R 755 storage
sudo chmod -R 755 bootstrap/cache
You can try 777 if 755 doesn't work. 777 is not secure though!
Depending on how your web server is setup, you may be able to be more specific with your permissions, and only grant them to your web server user. Google WEB SERVER NAME Laravel file permissions
for more information.
At the time of writing, this is for Laravel 5.4