“unlink permission denied” error trying to delete deleteme.txt

旧巷老猫 提交于 2019-12-08 01:52:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!