Resolutions Problems with Laravel on CentOS

I cloned the Laravel repository into my CentOS 7 box. When I try to start it, I get a 500 error, but nothing is displayed.

So I check /var/log/httpd/error_log and see that I have some permission errors:

 [Mon May 16 11:39:32.996441 2016] [:error] [pid 2434] [client 104.156.67.195:39136] PHP Fatal error: Uncaught UnexpectedValueException: The stream or file "/var/www/html/MYSITE/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied in /var/www/html/MYSITE/bootstrap/cache/compiled.php:13701 Stack trace: #0 /var/www/html/MYSITE/bootstrap/cache/compiled.php(13635): Monolog\\Handler\\StreamHandler->write(Array) #1 /var/www/html/MYSITE/bootstrap/cache/compiled.php(13396): Monolog\\Handler\\AbstractProcessingHandler->handle(Array) #2 /var/www/html/MYSITE/bootstrap/cache/compiled.php(13494): Monolog\\Logger->addRecord(400, Object(Symfony\\Component\\Debug\\Exception\\FatalErrorException), Array) #3 /var/www/html/MYSITE/bootstrap/cache/compiled.php(13189): Monolog\\Logger->error(Object(Symfony\\Component\\Debug\\Exception\\FatalErrorException), Array) #4 /var/www/html/MYSITE/bootstrap/cache/compiled.php(13160): Illuminate\\Log\\Writer->writeLog('error', Object(Symfony\\Component\\Debug\\Exception\\FatalErrorException), Array) # in /var/www/html/MYSITE/bootstrap/cache/compiled.php on line 13701 

I did the following to try to overcome the problems:

 chmod -R 775 storage chmod -R 775 vendor chown -R apache:apache storage 

So now it looks like this:

 -rwxrwxr-x. 1 apache apache 2156 May 16 11:41 storage/logs/laravel.log 

But that did not work.

Interestingly, I typed some artisan commands incorrectly before, and they seemed to add logs to the log file ...

I already read / tried:

+20
source share
6 answers

It turns out the problem is with selinux

I found this answer that solved my problem.

Prove that this is a problem by disabling selinux command

 setenforce 0 

This should allow writing, but you have disabled the entire server for additional security. This is bad. Turn SELinux back

 setenforce 1 

Then finally use SELinux to allow writing the file using this command

 chcon -R -t httpd_sys_rw_content_t storage 

And you are gone!

+63
source

I need to make more settings for SELinux than just storage . Especially config dir can solve this problem when loading Laravel.

If you are sudo setenforce permissive , return it to sudo setenforce enforcing and follow below.

SELinux laravel setup:

 sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/site/laravel/storage(/.*)?" sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/site/laravel/bootstrap/cache(/.*)?" 

You may not need the following for config , but I did it. It may be safer not to run this if you don't need:

sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/site/laravel/config(/.*)?"

Then reset the settings after making changes to the directory:

restorecon -Rv /var/www/site/

+3
source

In my case, it was a different Unix user, so this one worked:

 chown -R php-fpm:php-fpm storage 
+1
source

Another solution that works for me

Go to the html directory:

 cd /var/www/html 

If your web service is apache :

 chown -R apache:apache laravel_Folder/ 

If your nginx web service:

 chown -R nginx:nginx laravel_Folder/ 

Then change the mode of the Storge folder:

 chmod -R 775 laravel_Folder/storage/ 
0
source

Apply it for the whole project.

 chcon -R -t httpd_sys_rw_content_t project_folder 
0
source

try it worked for me ...

 sudo find ./storage -type f -exec chmod 666 {} \; sudo find ./storage -type d -exec chmod 777 {} \; 
0
source

All Articles