I wasn't too keen on changing my folder permissions to 777. Here's how I went about fixing this issue.
First, I changed the user who is running the web server on my local machine(I run nginx, but the principles apply everywhere):
$> sudo vim /etc/nginx/nginx.conf
user <my_user> #inside nginx.conf
service nginx reload
Afterwards, I created another index.php
file under the public/
folder to find out who was running my php-fpm version and where I would go about changing that:
<?php
phpinfo();
?>
Reloading the page, I found out that www-data
was the user(under the environment section). I also found out I was running php 7.1. I proceeded to change the user:
$> sudo vim /etc/php/7.0/fpm/pool.d/www.conf
#Look for www-data or the following variables: user, group, listen.user, listen.group.
Finally, I gave the following permissions to folders:
sudo chmod -R 775 ./storage/
Now, I made sure that I was the owner of the folders by using a simple:
ls -al
If you set the server and php-fpm users to yourself and the folders are owned by root for example, then you will keep encountering this issue. This can happen if you did a sudo laravel new <project>
as root. In that case, make sure you use a recursive chown
command on your project to change the user:group
settings. In most default cases, www-data
is the main setting for the server and php, in that case it's a matter of making sure the folder isn't out of www-data
's reach.
My project is setup in my home directory. On Ubuntu 16.04 and Laravel 5.5.