Greetings,
I'm using Ubuntu Linux v5.10, Apache2, and PHP5.
I am the only user of the computer.
/etc/apache2/sites-available/default.txt is configured to use /var/www/testdir/ as the document root.
I am simply trying to write to a text file located in /var/www/testdir/test.txt
/var/www/testdir/ contains: test.txt and test.php
Here is my PHP script:
<?php
$testfile = "/var/www/testdir/test.txt";
$filehandle = fopen($testfile, "w");
$stringData = "Write this stuff to file\n";
fwrite($filehandle, $stringData);
$stringData = "Then write this stuff to file too\n";
fwrite($filehandle, $stringData);
fclose($filehandle);
?>
Here is the error being returned after the PHP script is ran:
Warning: fopen(/var/www/testdir/test.txt) [function.fopen]: failed to open stream: Permission denied in /var/www/testdir/test.php on line 4
Warning: fwrite(): supplied argument is not a valid stream resource in /var/www/testdir/test.php on line 7
Warning: fwrite(): supplied argument is not a valid stream resource in /var/www/testdir/test.php on line 10
Warning: fclose(): supplied argument is not a valid stream resource in /var/www/testdir/test.php on line 12
I have a feeling this has to do with file permissions and unfortunately I'm a bit of a newbie to Linux. I have not changed any directory or file permissions so they should all be set to the default. I am the only user of this computer.
Any suggestions on getting this to work would be very much appreciated.
Thank you for your time,
Nick