在 Apache 中授予 PHP 写入权限 [英] Giving PHP write permission in Apache
问题描述
我对配置 Apache 比较陌生.
I'm relatively new to configuring Apache.
我有一个 PHP 脚本,它根据从 $_GET
检索到的值编写一个 JSON 文件.
I have a PHP script that writes a JSON file based on values retrieved from $_GET
.
<?php
file_put_contents('State.json', "{ do: '" . $_GET['do'] . "' }");
echo "Success";
?>
我通过创建 XHR 请求来运行该代码.
I run that code by create an XHR request.
Ally.xhr('/Cream/Foam?do=someCommand');
它返回的页面显示 failed to open stream: Permission denied on line 3.
<Directory "~/Dropbox/Web">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
这些是授予根服务器文件夹的权限.
Those are the permissions given to the root server folder.
我需要更改什么才能允许 PHP 写入文件?
What do I need to change to allow PHP to write the file?
(我几乎不知道上面的块是什么意思.)
(I have pretty much no idea what the block above means.)
推荐答案
需要检查运行apache的用户是否有权限写入目录.
You need to check if the user under which runs apache has permission to write into the directory.
所以是这样的:
您的 apache 服务器正在运行.该过程在某个用户(例如 www)下运行.PHP 在 apache 下运行.因此,如果您尝试在 PHP 中写入目录,则与用户 www 登录服务器并尝试在同一目录中创建文件是相同的.因此,请检查谁是该目录的所有者以及它具有哪些权限.你可以这样做,例如通过 ls -la
命令.如果 www
将是该目录的所有者,您将 100% 安全......
Your apache server is process. The process runs under some user (say www). The PHP runs under apache. So if you try to write into a directory in PHP it is the same as if the user www logs into the server and tries to create a file in the same directory. So check who is owner of that directory and which permission do it have. You can do it e.g. via ls -la
command. If www
will be owner of that directory, you will be 100% safe ...
这篇关于在 Apache 中授予 PHP 写入权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!