Linux – Not able to delete file from server with permissions of 644 via PHP script

linuxpermissionsPHPUbuntu

I am trying to delete JPEG files that were uploaded to the server via FTP. The files are uploaded and written with permissions of 644. The owner and group of the upload directory are mike and mike.

I have tried changing the owner and group to www-data, but that does not seem to work.

I am trying to delete the files with a PHP script using unlink(). This works on the production server (which is a hosting service), but not my development server, which is a LAMP setup. This leads me to believe it has something to do with permissions on my development server.

Do you think this has something to do with PHP or Apache configuration?

Best Answer

To delete a file on Unix-like systems, you need write permission on the directory containing it, not the file itself. This is because the underlying operation is actually modifying the directory by removing (unlinking) an entry from it.

In order to do what you want to do, the directory containing the file you want to delete must be writable by www-data.