Laravel 4: Failed to open stream: Permission denied

Solution 1:

I think chmod -777 is a bad practice.

To solve permissions issue on Laravel, I've done this (with root user):

cd app/

chown -R www-data:www-data storage

cd storage/

find . -type d -exec chmod 775 {} \; && find . -type f -exec chmod 664 {} \;

And always in app/storage directory :

chown your_user:user_group .gitignore cache/.gitignore logs/.gitignore meta/.gitignore sessions/.gitignore views/.gitignore

Now, exit the root user, and it's ok.

EDIT : this was for Laravel4. This doesn't works for Laravel5 because of a different structure.

Solution 2:

The storage directory needs to be writable by the webserver user.

Solution 3:

It's better that you do not change the permissions, you should just change the owner:group of the storage folder to that of the owner:group of apache by using chown, this is more complicated but is more secure and you'll get used to this soon, you can find this in the httpd.conf

MAMP:

/Applications/MAMP/conf/apache/httpd.conf

XAMMP:

/Applications/XAMPP/xamppfiles/etc/httpd.conf

Open the httpd.conf with your preferred editor then search for User/Group. After searching you will see these lines below that highlighted line you searched:

User someuser
Group somegroup

Once you already know the User and Group, cd to your laravel directory then, do the chown:

chown -R someuser:somegroup app/storage

P.S: If you get permission something error upon doing chown, try this:

sudo chown -R someuser:somegroup app/storage

It will then ask for your password so input it then done.

Solution 4:

Just ran into this problem on centos 7. The blocker wasn't folder permissions, rather it was selinux policy blocking nginx/php to access /var/www. So, if the above doesn't work, try disabling selinux as a test to see if you can re-run composer without any permission issues.