'file_put_contents() failed to open stream: Permission denied on CentOS

I'm deploying a Laravel app on CentOS. I've following the following steps:

  1. Cloned my repo
  2. Installed composer
  3. Setup config

Now I'm getting the following error message when I open my website:

file_put_contents(/var/www/portal/storage/framework/sessions/IDElrNpsn0hu9hjiXAzZRUTHyzm2fqvPHSLy0ZVN): failed to open stream: Permission denied

On ubuntu I used the following command to resolve the issue:

sudo chown -R $USER:www-data storage
sudo chown -R $USER:www-data bootstrap/cache
chmod -R 775 storage
chmod -R 775 bootstrap/cache

Now on CentOS above 2 commands are not working and I'm getting ErrorException. Can anyone tell me which command should I run in CentOS 7 to resolve this error? Thanks



Solution 1:[1]

The issue is resolved. The solutions for centOS is to use apache instead of www-data.

sudo chown -R $USER:apache storage
sudo chown -R $USER:apache bootstrap/cache

Solution 2:[2]

this was the only solution for me!! After 3 days and nothing to do whit permisions, chmod chown... it was the ffffff server!!

semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/bagisto/bootstrap/cache(/.)?' semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/bagisto/storage(/.)?' restorecon -Rv '/var/www/bagisto'

see more here! https://laracasts.com/discuss/channels/general-discussion/file-put-contents-2

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rizwan Saleem
Solution 2 Hugo Ramon Mayorga Barria