Accidental file deletion in cPanel can lead to website downtime, lost data, and security risks. This comprehensive guide covers multiple methods to protect your files from deletion, whether due to human error, malware, or automated processes.
1. Understanding Why Files Get Deleted in cPanel
Before implementing protection measures, it’s important to know common causes of file deletion:
✅ Human Error – Mistakenly deleting files via File Manager or FTP
✅ Malware/Hacking – Attackers deleting or corrupting files
✅ Automated Scripts – Cron jobs or CMS updates gone wrong
✅ Hosting Cleanup – Some hosts delete “unused” files
✅ Account Suspension – Hosts may wipe data if your account is terminated
2. Best Ways to Prevent File Deletion in cPanel
🔒 Method 1: Enable Automatic Backups
Why? Even if files are deleted, you can restore them.
How to Set Up:
- Go to cPanel → Files → Backups
- Enable Automatic Backups (if offered by your host)
- Download Full Account Backups regularly
- Use JetBackup (if available) for versioned backups
Pro Tip: Store backups offsite (Google Drive, Dropbox, or a remote server).
🔒 Method 2: Restrict File Permissions
Why? Incorrect permissions allow unauthorized deletion.
How to Set Up:
- Go to cPanel → File Manager
- Right-click a file/folder → Change Permissions
- Set:
- Folders:
755
(Owner: Read/Write/Execute | Others: Read/Execute) - Files:
644
(Owner: Read/Write | Others: Read)
- For extra security, set sensitive files to
400
(Read-only for owner).
Warning: Avoid 777
permissions—this allows anyone to delete files!
🔒 Method 3: Use .htaccess to Block Deletion
Why? Prevents PHP scripts or hackers from deleting files.
How to Set Up:
- Open File Manager → Go to your website’s root folder (usually
public_html
) - Create/edit
.htaccess
- Add:
# Prevent file deletion via PHP/Scripts
<FilesMatch "\.(php|html?|js|css|jpg|png)$">
Order Allow,Deny
Deny from all
<LimitExcept GET POST>
Require all denied
</LimitExcept>
</FilesMatch>
- Save & test if files are still accessible.
Note: This may break some CMS functions—test carefully.
🔒 Method 4: Disable FTP/SFTP Delete Permissions
Why? Limits who can delete files via FTP.
How to Set Up:
- Go to cPanel → FTP Accounts
- Edit the FTP user → Set “Directory” access to “Read Only”
- For existing connections, use:
chmod -R 555 /home/user/public_html
(Makes files read-only for FTP users)
Alternative: Use SFTP with SSH keys instead of passwords for better security.
🔒 Method 5: Use CHATTR (Immutable Files)
Why? Makes files undeletable even by root (until unlocked).
How to Set Up (via SSH):
- Connect via SSH (Terminal/PuTTY)
- Run:
chattr +i /home/user/public_html/important-file.txt
- To unlock later:
chattr -i /home/user/public_html/important-file.txt
Warning: Only use this for critical files, as it can break updates.
🔒 Method 6: Enable cPanel’s “File Protection” (If Available)
Some hosts offer:
- “File Locking” (prevents modifications)
- “Snapshot Backups” (rollback deleted files)
Check under cPanel → Security → File Protection
🔒 Method 7: Monitor Files for Unauthorized Changes
Why? Detect deletions before they cause damage.
How to Set Up:
- Use cPanel’s “Track Disk Usage”
- Set up Cron Job Monitoring (e.g.,
find /home/user -mtime -1
to check recent changes) - Install Malware Scanners (Imunify360, ConfigServer eXploit Scanner)
3. What to Do If Files Are Already Deleted?
- Check Trash (cPanel File Manager sometimes has a recycle bin)
- Restore from Backup (cPanel → Backups or JetBackup)
- Contact Host Support (Some hosts keep backups for 7-30 days)
- Use Data Recovery Tools (e.g.,
extundelete
on Linux servers)
4. Extra Security Tips
✔ Use Cloudflare (Blocks malicious bots that delete files)
✔ Disable Unused PHP Functions (like exec()
, system()
)
✔ Enable cPanel’s “ModSecurity” (Prevents exploit-based deletions)
✔ Disable Directory Indexing (Prevents attackers from seeing files)
Final Thoughts
By combining permissions, backups, monitoring, and file locking, you can greatly reduce the risk of accidental or malicious file deletion in cPanel.
Which method are you using? Let me know if you need help setting any of these up! 🚀