在Apache中授予PHP写权限

在Apache中授予PHP写权限

本文介绍了在Apache中授予PHP写权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对配置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写权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-27 10:49