Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
479 views
in Technique[技术] by (71.8m points)

apache2 - Giving PHP write permission in Apache

I'm relatively new to configuring Apache.

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";

?>

I run that code by create an XHR request.

Ally.xhr('/Cream/Foam?do=someCommand');

The page it returns says 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.

What do I need to change to allow PHP to write the file?

(I have pretty much no idea what the block above means.)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to check if the user under which runs apache has permission to write into the directory.

So it's like this:

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 ...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...