Ubuntu - 使用file_put_contents的正确权限

时间:2021-06-12 16:47:32

In my PHP application I am using file_put_contents() to create a file to display comprising of a blob retrieved from a table in my database. However, currently, in order to get the function to work on my Amazon EC2 Ubuntu instance, I had to give the folder it's writing to 777 permissions. However, I know this is extremely bad and I want to change this, but I don't know what to.

在我的PHP应用程序中,我使用file_put_contents()来创建要显示的文件,其中包含从数据库中的表中检索的blob。但是,目前,为了让函数在我的Amazon EC2 Ubuntu实例上运行,我必须给它写入777权限的文件夹。但是,我知道这非常糟糕,我想改变这一点,但我不知道该怎么做。

I'm a novice at Linux and I'm currently navigating around my instance through the help of Google. This is part of a university assignment, so I can't just hire a Linux expert (just in case one of you says I shouldn't be using such an instance if I don't know Linux!)

我是Linux的新手,我目前正在Google的帮助下浏览我的实例。这是大学任务的一部分,所以我不能只聘请一位Linux专家(以防万一你说如果我不懂Linux就不应该使用这样的实例!)

1 个解决方案

#1


1  

Assuming that you are using this from a browser with normal http requests, you need to find out what the user is that is running the web-server. Probably something like apache, www-user or something similar.

假设您在具有正常http请求的浏览器中使用此功能,则需要找出运行Web服务器的用户。可能像apache,www-user或类似的东西。

Then you can do 2 things:

然后你可以做两件事:

  • Change the ownership of the directory where you want to save the file to the web-server user and then it can have permissions 755
  • 将要保存文件的目录的所有权更改为Web服务器用户,然后它可以具有权限755
  • Change the group of the directory to the group of the web-server and then the directory needs 775.
  • 将目录组更改为Web服务器组,然后目录需要775。

#1


1  

Assuming that you are using this from a browser with normal http requests, you need to find out what the user is that is running the web-server. Probably something like apache, www-user or something similar.

假设您在具有正常http请求的浏览器中使用此功能,则需要找出运行Web服务器的用户。可能像apache,www-user或类似的东西。

Then you can do 2 things:

然后你可以做两件事:

  • Change the ownership of the directory where you want to save the file to the web-server user and then it can have permissions 755
  • 将要保存文件的目录的所有权更改为Web服务器用户,然后它可以具有权限755
  • Change the group of the directory to the group of the web-server and then the directory needs 775.
  • 将目录组更改为Web服务器组,然后目录需要775。