How to Stop Your Files from Being Deleted in cPanel (Complete Guide)

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:

  1. Go to cPanel → Files → Backups
  2. Enable Automatic Backups (if offered by your host)
  3. Download Full Account Backups regularly
  4. 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:

  1. Go to cPanel → File Manager
  2. Right-click a file/folder → Change Permissions
  3. Set:
  • Folders: 755 (Owner: Read/Write/Execute | Others: Read/Execute)
  • Files: 644 (Owner: Read/Write | Others: Read)
  1. 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:

  1. Open File Manager → Go to your website’s root folder (usually public_html)
  2. Create/edit .htaccess
  3. 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>
  1. 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:

  1. Go to cPanel → FTP Accounts
  2. Edit the FTP user → Set “Directory” access to “Read Only”
  3. 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):

  1. Connect via SSH (Terminal/PuTTY)
  2. Run:
   chattr +i /home/user/public_html/important-file.txt
  1. 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:

  1. Use cPanel’s “Track Disk Usage”
  2. Set up Cron Job Monitoring (e.g., find /home/user -mtime -1 to check recent changes)
  3. Install Malware Scanners (Imunify360, ConfigServer eXploit Scanner)

3. What to Do If Files Are Already Deleted?

  1. Check Trash (cPanel File Manager sometimes has a recycle bin)
  2. Restore from Backup (cPanel → Backups or JetBackup)
  3. Contact Host Support (Some hosts keep backups for 7-30 days)
  4. 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! 🚀

Leave a Reply

Your email address will not be published. Required fields are marked *