Laravel在CentOS上的权限问题

时间:2016-05-16 15:48:03

标签: linux apache laravel permissions centos

我已经将一个laravel回购克隆到了我的CentOS 7盒子里。当我尝试运行它时,我得到500错误,没有显示任何内容。

所以我查看了/var/log/httpd/error_log,我发现我发现了一些权限错误:

[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

我已经做了以下尝试来克服这些问题:

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

所以它现在显示如下:

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

但那不起作用。

有趣的是,我之前错误地输入了一些artisan命令,而这些命令似乎将日志添加到日志文件......

我已经阅读/试过了:

6 个答案:

答案 0 :(得分:55)

原来问题在于selinux

I found this answer,解决了我的问题。

  

通过使用命令

关闭selinux来证明这是问题所在
setenforce 0
     

这应该允许写作,但你已经关闭了额外的安全性   服务器范围。那很糟。转回SELinux

setenforce 1
     

然后最后使用SELinux来允许使用它来写文件   命令

chcon -R -t httpd_sys_rw_content_t storage
     

你好了!

答案 1 :(得分:1)

我需要对SELinux进行更多调整,而不仅仅是对storage进行调整。尤其是config目录可以在Laravel引导程序中解决此问题。

如果您sudo setenforce permissive可以使用,则将其退回sudo setenforce enforcing,然后按照以下步骤操作。

SELinux laravel设置: 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(/.*)?" sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/site/laravel/config(/.*)?" restorecon -Rv /var/www/site/

答案 2 :(得分:1)

在我的情况下,这是另一个unix用户,因此该用户有效:

chown -R php-fpm:php-fpm storage

答案 3 :(得分:0)

将其应用于整个项目。

chcon -R -t httpd_sys_rw_content_t project_folder

答案 4 :(得分:0)

尝试这些对我有用...

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

答案 5 :(得分:0)

在CentOS 7上,我有类似的权限问题。适用于我的解决方案是:

将用户centos添加到组apache

将用户apache添加到组centos

重新启动httpd

最后一行至关重要,因为否则用户apache不会意识到它现在也位于centos组中!

与用户apache注销并重新登录相同。