I have installed apache server on a linux fedora machine
and I put the following test.php and test.html on var/www/html
but when I open the 127.0.0.1/test.html on firefox
the test.php doesn’t create the text.txt file, let alone write the string to the file
and the there is also no output for “echo $var”
the error is
Warning: file_put_contents(test.txt): failed to open stream: Permission denied in /var/www/html/getdata.php on line 7
the permission for the directory is:
drwxr-xr-x. 2 root root 4096 Nov 6 14:14 html
test.php:
<?php
$v="x";
$fname='test.txt';
$rv=file_put_contents($fname,$v);
echo $rv;
echo $v;
?>
the test.html is so complex coz I planned to write something complex to a file on the server, but since there is some problem, I simplified the test.php
test.html:
<!DOCTYPE html>
<html>
<body>
<form id="yourFormID" method="POST" action="/getdata.php" ></form>
<script>
function sendArray( theArray )
{
var frm = document.getElementById('yourFormID');
fld = document.createElement("INPUT");
fld.name ="data";
fld.type = "hidden";
fld.value = JSON.stringify(theArray);
frm.appendChild(fld);
frm.submit();
}
var yourArray = [0.000023323,0.00001292,0.00003323];
sendArray( yourArray );
</script>
</body>
</html>
The html directory is currently owned by root, but under Fedora the web server runs as the “apache” user. (see “Apache File Security” section of https://fedoraproject.org/wiki/Administration_Guide_Draft/Apache?rd=Docs/Drafts/AGBeta/Apache )
So, as root, do:
The first makes the web server own the directory. The second makes sure that only users in the “apache” group can read/write files. It also says that no other users on the machine can even read them.
If you ever need another user to be able to write files into your web tree, add them to the “apache” group.