How to free up disk space on a cPanel server
Publisher: Psychz Networks, July 14,2021Over a period of time, your servers can become cluttered with old and sometimes unwanted files. Eventually, data keeps accumulating until it fills the server's storage devices. When there's no space to store new stuff, the performance takes a hit, and some software will stop working altogether.
Keeping at least 20 percent of the server's storage free at all times is highly recommended. This means you will occasionally have to perform disk checks and cleanups to find and delete unused data. The following guide covers freeing up disk space on your cPanel server to keep it healthy.
- Delete user backups
- Move or archive logs
- Delete temp files of File Manager
- Remove update archives
- Remove unwanted accounts
- Clean up Yum files
- Remove pure-ftp partials
Following are some of the steps that you can follow regularly
1. Delete user backups
If you have enabled the backup feature on your cPanel server, it is highly advisable to remove these promptly. Most users tend to download these backup files at their end but forget to delete them from the server. Implement a system where the backups will automatically be removed from the server after a certain period or on specific dates.
You can mass-delete all user cPanel backups on the server with this command via SSH:
# rm -fv /home/$user/backup-*$user.tar.gz
2. Move or archive logs
Log files are constantly generated and are stored in /var/log on the server. The total size of the records can get enormous if the number of users on the system is high. You can create a cron job to move these log files to your backup server periodically.
You can also amend the length of time, frequency of the log rotation in the /etc/logrotate.conf file. You can also apply compression to the generated log file to reduce the space required.
Following is the sample logrotate.conf file
# keep 4 weeks worth of backlogs
rotate 4
# create new (empty) log files after rotating old ones
create
# use date as a suffix of the rotated file
dateext
# uncomment this if you want your log files compressed
#compress
# RPM packages drop log rotation information into this directory
include /etc/logrotate.d
# system‐specific logs may be also be configured here.
3. Delete temp files of File Manager
cPanel allows users to upload files in File Manager, which creates a temp file that tends to stay on the server. Using a simple command via SSH, you can remove these files during your monthly server maintenance.
# rm -fv /home/*/tmp/Cpanel_*
4. Remove update archives
When EasyApache is run, it will leave the file behind, which were used for Apache/PHP build, which can be removed if space is needed.
EasyApache files can be removed with the following command.
# rm -rfv /home/cpeasyapache
5. Remove unwanted accounts
As your business grows, the number of users on your servers will grow too, and some will leave too. Regularly, you must keep checking the list of suspended accounts that you no longer need and remove the same, freeing up a good amount of space.You can use the WHM dashboard and look for List Suspended Accounts. You can also use the following command to list all suspended accounts.
# ls /var/cpanel/suspended
To terminate an account using the WHM dashboard, look for "Terminate an Account" or use the following command.
# /scripts/killacct <user> <y/n> (y or n will indicate whether to save the DNS records)
6. Clean up Yum files
When a package is downloaded, installed, and is removed, there is a chance that the package may still be saved/stored in the yum's cache. So to clean all the cached packages from the enabled repository cache directory, log in as root and execute the following:
# yum clean all
7. Remove pure-ftp partials
You need to find and delete your users' uploaded files via FTP when your server runs pure FTP as an FTP daemon. Next, the FTP server creates temporary files starting with .pureftpd-upload* that rename the actual filename when the upload is complete.
# locate .pureftpd-upload | xargs rm –fv
You have successfully learned how to free up space on your cPanel server. If you have any feedback or comments, please let us know. We are here to help in the best ways we can.