user3734451
user3734451

Reputation: 21

"unlink permission denied" error trying to delete deleteme.txt

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.

Upvotes: 2

Views: 5068

Answers (1)

annoymous
annoymous

Reputation: 11

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>

Upvotes: 1

Related Questions