How to Free Up Disk Space on a cPanel Server

Disk space issues are quite common in cPanel accounts and servers. It can be mainly because of the website users eats up the entire disk or the log files fills up or the backup fills up the entire folders.

At the time of installation, we separate some of the folders to partitions, that helps a lot to keep the data safe if the disk space fills up.

The following command will show you the disk space usage of all mounted partitions in the server – this also give you an idea how much percentage of disk space each partitions has used up.

df -h

We will see different scenarios in a cPanel server, the disk space in different partitions can get filled up.


1. /tmp Getting Filled Up

In cPanel servers, unless configured, the PHP uses the /tmp for temporary file uploads as well as to save sessions. If they are not properly managed, there are chances to get this filled up.  So, it is good to keep an eye on this partition constantly. If it fills up, we can use this command to clear the files in the /tmp.

SSH to the server as root and then:

cd /tmp; find . -type f -exec rm -f {} ;

This command will only delete the regular files and the MySQL socket will still be there as opposed to issuing the command

rm -rf /tmp/*


2. /usr Getting Filled Up

This is mainly because of the Apache or cPanel logs or bandwidth data takes all the disk space.

1. Enable log rotation from WHM -> Apache configuration.

2. Empty the log files.

3. Connect to the server  through SSH as root and issue the following commands:

cd /usr/local/apache/logs

This command will display the files in descending order of disk space usage:

ls -alhS

This command will empty the file error_log without changing the ownership or permission of the file.

:> error_log

Apply the above command to all files which are taking large disk space. You may also wish to do the same steps at /usr/local/apache/domlogs as well.

If cPanel folders are taking the disk space, you need to check the following folders:

  • /usr/local/cpanel/logs
  • /usr/local/cpanel/bandwidth (this is a monthly rotatting one, you can clear this folder at the begining of the month).

3. /var Getting Filled Up

In linux, /var is the location of the logs and email spool location. If you have a high amount of emails in your delivery queue, there are chances that the disk space usage in your /var gets occupied.

To clear the logs, ssh to the server as root and change directory to /var/log:

cd /var/log

This command will display the files in descending order of disk space usage:

ls -alhS

Empty the exim log file:

: > exim_mainlog

Apply the above command to all log files which are taking large disk space.

Another possibility is the /var/lib/mysql folder. If it is filling up, check for the log file , normally /var/lob/mysql/hostname.err  and you need to clear that file.

4. /backup Getting Filled Up

Use this simple script to clear the backups of the terminated users.

cd /backup/cpbackup/daily; for USERNAME in *; do if [  -f /var/cpanel/users/$USERNAME ]; then echo  $USERNAME is valid, not removing ; else rm -fr /backup/cpbackup/*/$USERNAME/ ; fi ;done

Another possibility is that the backup folders will contain incomplete backups, which you can remove safely. Navigate to /backup/cpbackup/daily/ and look for folders with username.0 username.1 etc

6. /home Getting Filled Up

This happens in 2 cases:

  1. Number of users increases;
  2. One or more users consume high disk space

For the first case, we need to add more disk or need to upgrade to a server with higher specifications so we shall discuss the second case.

Initially, we need to identify which users are overusing disk space and then establish why they are using so much space:

  1. They are storing high amount of emails. 
  2. This happens when:
    • The cpanel account have the catch all enabled and their default email accont is accpting all mails. You need to change the default email account to ” :fail: ” and then clear the default mailbox.
    • They use the server to save emails – probably IMAP users – ask them to clear the mail boxes or limit the mail box storage to a lesser MB.
  3. Their public_html is heavily used.
  4. They have probably logging enabled, or have temorary cache files not purging too often. Other wise they can be legit – ask the user to upgrade to consider a disk upgrade or plan upgrade.
  5. They store backups. 
  6. This is the case most of the time that the user generates the backup from cpanel and saves in the home folder.  You can delete such files and save the disk from getting filled up.

If the disk is still getting filled up in a n alarming rate, you must consider upgrading the disk in your server or migrate to a new server with better specs.

2 thoughts on “How to Free Up Disk Space on a cPanel Server”

  1. zamaan says:

    very useful thank you

Leave a Reply

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