I have tried the following:
1.The php that directly writes the file on the same directory (/home/pi/www/test).
2. Navigate with the browser to the directory http://myserver/test and the file is not created and php gives the error:
Warning: fopen(file.txt): failed to open stream: Permission denied in /home/pi/www/html/test/index.php on line 6
Unable to open file!
3. Then I give "rwx" permission to others:
chmod o+wx /home/pi/www/test
4. Then going to the same directory http://myserver/test the file gets created
The php file (index.php)
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$myfile = fopen("file.txt", "w") or die("Unable to open file!");
$txt = "writing test\n";
fwrite($myfile, $txt);
fclose($myfile);
?>
I have done the tests with lighttpd.
Launching the creation of the file directly with the script gives more information.
You must have permission issues.