问题
I want to delete deleteme.txt in the Ubuntu web server.
So I made 4.php do the following:
<?php
unlink('deleteme.txt');
?>
deleteme.txt has the following permission status:
-rwxrwxrwx 1 ubuntu ubuntu 19 Jun 12 06:18 deleteme.txt
When I execute "4.php", this error always occurs
Warning: unlink(deleteme.txt): Permission denied in /var/www/html/4.php on line 2
I already tried chmod 777 deleteme.txt and chown ubuntu /var/www/html on the directory which contains "deleteme.txt"
I also tried chown ubuntu /var/www/ on the parent directory of that file.
回答1:
you need to chown to www-data, thus meaning that the www-data will gain ownership of the file allowing you to delete it through unlink with php.
Like so:
$ chown www-data <file or folder>
来源:https://stackoverflow.com/questions/24187176/unlink-permission-denied-error-trying-to-delete-deleteme-txt