cPanel & WHM

How to clear space on a cPanel Server

cPanel is great for managing your websites, it’s stable, easy to use and a trusted name. Unfortunately, the servers we see tend to waste a lot of space, especially in log files and incomplete backups. We’ve put together this guide for people who are looking to clear up space inside their cPanel VPS Server and get some of their resources back. First, to clear space on a cPanel server let’s look at backups and what you should and should not do.

Before starting to clear any space in your cPanel server. Run the df -h command to see how much space you are using.

df -h

Local Backups

If you have cPanel backups configured to save to your server then this should be changed straight away. Not only will you be using double the space you need, if the backups are being stored locally and your hard drive was to fail you would lose all your data and backups.

You should purchase a separate backup server to host your backups on and consider using a program like Jetbackup which allows incremental backups.

Log Rotation

Logs on a cPanel server can become quite large. WHM has specific settings to change the threshold at when to rotate your logs. Before you do this select which logs you want to rotate

Home » Service Configuration » cPanel Log Rotation Configuration

Select Logs To Rotate;

access_log
api_tokens_log
build_locale_databases_log
cpbackup_transporter.log
cpdavd_error_log
cpdavd_session_log
cphulkd.log
cphulkd_errors.log
cpwrapd_log
dnsadmin_log
error_log
incoming_http_requests.log
license_log
login_log
queueprocd.log
safeapacherestart_log
session_log
spamd_error_log
splitlogs_log
stats_log
tailwatchd_log

Once you have selected the logs to rotate change the threshold via the “Tweak Settings” interface. The specific setting is “Log rotation size threshold” the default is 300MB, a setting of 100MB would be sufficient. 

Find and reduce the size of Error_log Files

Each account on the server will have error_log files. These files are used by applications to log errors. Badly written scripts can easily fill these files until they become GBs in size taking up valuable space. So, the below command will search the /home directory for these error_log files, list them and reduce the size of these log files to 0MB

find /home/ -name error_log -type f -print -exec truncate --size 0 "{}" \;

Apache Zipped log files

Apache Linux VPS Servers will package up log files into a zip file when they become a certain age and or size, these log files are rarely needed and can consume a fair amount of space. You can remove these log files with the following command

rm -fv /usr/local/apache/logs/archive/*.gz

Delete cPanel File Manager Temp Files

When users upload files in File Manager within cPanel, File Manager creates a temporary file that may or may not get removed upon upload. So, you can remove these files using this command;

rm -fv /home/*/tmp/Cpanel_*

Remove cPanel update archives

cPanel and Easy Apache updates leave behind files that you don’t need. The following folders can be deleted or moved to a backup server to free up a little bit of space:

/usr/local/apache.backup*

Clean up Yum files

Yum updates leave package cache files on the server. So, you can clean up all unneeded yum files by running:

yum clean all

Remove pure-ftp partials

When your users upload files to the server via FTP and when your server runs pureFTP as an FTP daemon, the FTP server creates temporary files starting with .pureftpd-upload* that get renamed the the actual filename when the upload completes. If the upload doesn’t complete, these files are left on the server. You can find and delete all of these files by running:

locate .pureftpd-upload | xargs rm -fv

Leave a Reply

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

Back to top button