0

I have a problem with a php script on my webserver (Apache/2.4.10 on Raspbian), I can't generate a new file on it. I have tried chmod 777 (which is really bad practice) and it still didn't work. I have been struggling with this for a few days and even after extensive research I couldn't find a solution to this problem. Below is my code and the error messages generated by it:

<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
$newwish = fopen("newfile.txt", "w+");
$txt = "LALALA";
fwrite($newwish, $txt);
fclose($newwish);
?>

Warning: fopen(newfile.txt): failed to open stream: Permission denied in /var/www/html/handlers/wish.php on line 4

Warning: fwrite() expects parameter 1 to be resource, boolean given in /var/www/html/handlers/wish.php on line 6

Warning: fclose() expects parameter 1 to be resource, boolean given in /var/www/html/handlers/wish.php on line 7

R P
  • 1,173
  • 2
  • 11
  • 20

1 Answers1

-2

I tried your script in the CLI and works well.

Try to make www-data the owner of the folder and the content that contain the script:

chown -R www-data:www-data phpscript/

and then give to the php script file permissions:

chmod 644 index.php