您需要配置 /opt/lampp/htdocs 目录,以便您登录的用户具有写入权限。您还需要确保您在其中写入的内容可以被 LAMPP 使用的任何 Web 服务器读取(不幸的是,我不熟悉 LAMP。)
首先您需要查看谁拥有 /opt/lampp/htdocs:
$ ls -lah /opt/lampp/htdocs
应该返回类似:
drwxr-xr-x 4 lampp www 4096 2015-05-22 12:43 /opt/lampp/htdocs
第一位(dwrxr-xr-x)是文件权限。 “lampp”是目录的所有者,“www”是目录的组所有者。您需要注意这一点。
首先让我们对组进行排序。如果该组是除“root”之外的任何内容,那么一切都很好,您可以跳过此部分:
如果它是“root”,则需要更改为更明智的东西。为它创建一个新组。然后更改目录上的组:
$ sudo groupadd www
$ sudo chgrp -R www /opt/lampp/htdocs
现在你需要让 web 服务器作为 www 组运行。如果 Web 服务器是 Apache,那么您应该检查 /etc/apache/httpd.conf 文件并相应地编辑“组”设置
sudo gedit /opt/lampp/etc/httpd.conf
我们需要解决目录的权限问题。我们想使用“setgid”位。
$ sudo chmod 2775 /opt/lampp/htdocs
$ ls -ld /opt/lampp/htdocs
drwxrwsr-x 4 lampp www 4096 2015-05-22 12:43 /opt/lampp/htdocs
您会看到权限现在发生了一些变化。让我们解释一下。
The first letter is the file type. In this case "d" is for Directory.
The next three, "rwx" are the permissions the owner (lampp) has on the directort. r = read, w=write and x=see the directory contents.
The next three, "rws" are for the group-owner (www), but you notice the x in this case is actually an s - we will come to that in a moment.
The last three, "r-x", are for everybody else. That is read, and see the content of the directory. No writing.
组权限中的“s”称为“setgid”位。这是一个特殊权限,它使目录中创建的任何文件都从目录本身继承组所有者。因此,如果“users”组中的用户“fred”在其中创建了一个文件,则该文件将归“www”组中的“fred”所有。这对于多人读取和写入相同文件的共享区域非常有用。
现在,您需要将您的用户添加到组中
$ sudo usermod -aG www malyy
将“www”替换为您在开头附近记下的 /opt/lampp/htdocs 目录的组所有者。
您需要注销并重新登录才能使此更改生效 - 您的群组成员资格在登录时被读取