【问题标题】:Laravel unable to write in the directory on CentOs7Laravel 无法写入 CentOs7 上的目录
【发布时间】:2018-12-21 16:27:10
【问题描述】:

我创建了 laravel 项目,可以在我的本地 Windows 电脑上正常工作。一旦我上传到 Centos7 服务器(通过 SSH),上传图像时出现问题,无法写入该目录。 (项目文件结构https://ibb.co/5MLcFtd

  Unable to write in the "upload/register/picture."

已经试过了:

  chown apache:apache -R /var/www/html/srp/upload
  chmod -R 755 /var/www/html/srp/upload

  chown apache:apache -R /var/www/html/srp/upload/register/picture
  chmod -R 755 /var/www/html/srp/upload/register/picture

这是上传代码。

if(Request::hasFile('picture')){
        $file = Request::file('picture');
        if( in_array($file->getClientOriginalExtension(), $extension_picture) ){
            $new_name = str_random(10).".".$file->getClientOriginalExtension();
            $file->move('upload/register/picture' , $new_name);
            $new->picture = "upload/register/picture/".$new_name;
        }
    }

两者都不起作用。非常感谢所有答案。

【问题讨论】:

  • apache 用户是否也在运行 web 服务器?
  • 嗨 Autista_z,它是 CentOs7,应该是 apache,就像这张图片一样 ibb.co/t4zXYrx
  • Unable to write in the "upload/register/picture." 不是真正的错误消息。你看到的错误是什么,究竟是什么?是来自storage/logs/laravel.log,还是Apache日志?
  • 另外,请向我们展示upload/ 和子目录的权限。

标签: laravel


【解决方案1】:

我认为您使用的 ssh 用户没有写入权限。在这种情况下,您应该通过root(与ssh root@your_server 连接)用户上传或向您正在连接的用户授予写入权限。 (要做到这一点,无论如何你都需要 root 用户访问权限)

【讨论】:

  • 嗨,一些开发人员,ssh 已经是 root 了。顺便说一句,在向服务器提交数据时发生错误。
  • 硬盘可能已满,权限可能有误。您需要提供更多信息。 ls -al 如何在上传目录中查找。网络服务器以什么用户身份运行?您提供的信息越多,调试起来就越容易。
  • 嗨 larsemil ,我删除了上传文件夹并重试,然后它工作了。感谢您的指导。
猜你喜欢
  • 2018-04-30
  • 2016-04-22
  • 1970-01-01
  • 2021-06-07
  • 2013-10-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-15
相关资源
最近更新 更多