How to fix files that won’t delete from Apache server

So you’ve tried to delete some files from your server, but the next time you log in, they’re still there. This issue is most commonly caused by files left over after uninstalling scripts that were installed via a 1-click installer such as Softaculous. It can also be caused by the sticky bit being set on the directory; the sticky bit prevents anybody except root or the owner from deleting files inside of it. So the first thing you should do is check the directory’s permissions and ensure the sticky bit isn’t set on it; chmod -t /path/to/directory will unset it.

If sticky bit isn’t the issue, then the next problem that often prevents the files from being deleted is the file or directory permissions – you are trying to delete a file that you don’t have permission to delete. Browser-based file manager applications on managed hosting service accounts will sometimes run as a different user than the one you are using in your FTP client, resulting in this issue. If you have access to a sudo account or the root account, open an SSH console and use sudo rm -i /path/to/filename to delete the file.

If you’re using your webhost’s file browser interface instead of FTP or SSH, with a host such as Bluehost, then you may have to use an alternate method – set the file’s permissions to 777 and then delete it normally.

Note: If the file in question contains sensitive data, such as a config file containing database credentials, you should first try using SSH and the sudo rm -i filename command. Setting permissions such as 777 can result in anybody who comes across the file (or their bots/web scrapers) being able to see its contents.