“unlink permission denied” error trying to delete

2019-05-20 23:28发布

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条回答
啃猪蹄的小仙女
2楼-- · 2019-05-21 00:00

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>
查看更多
登录 后发表回答