Limiting/throttling bandwidth for cPanel user accounts

Introduction

Some cPanel accounts may consume a large amount of server bandwidth, which can affect other websites hosted on the same server.

This guide explains how to limit or throttle bandwidth for a specific cPanel account using Apache bandwidth modules and cPanel’s virtual host configuration.

Prerequisites

Before starting, make sure you have:

  1. cPanel/WHM access.
  2. Root access to the server.
  3. Apache bandwidth modules installed.

Check whether the required modules are available:

/usr/local/apache/bin/apachectl -M |grep bw

Expected output:

bwlimited_module (shared)
bw_module (shared)

Implementation

Step 1: Create a Configuration Directory

Create a custom Apache userdata directory for the cPanel account and domain:

mkdir -p /usr/local/apache/conf/userdata/std/2_4/username/domain.tld/

Replace:

  • username with the cPanel account username.
  • domain.tld with the domain name.

Step 2: Change to the Configuration Directory

Navigate to the newly created directory:

cd /usr/local/apache/conf/userdata/std/2_4/username/domain.tld/

Step 3: Create the Bandwidth Configuration File

Create a configuration file:

vi cp_bw_all_limit.conf

Add the following configuration:

<IfModule mod_bw.c>

  BandWidthModule On

  BandWidth all 512000

</IfModule>

<IfModule mod_bandwidth.c>

  BandWidthModule On

  BandWidth all 512000

</IfModule>

The BandWidth all 512000 setting defines the bandwidth limit applied to the account.

Step 4: Ensure the Virtual Host Includes

Run the following command to apply the custom configuration to the user’s virtual host:

/scripts/ensure_vhost_includes --user=username

Replace username with the cPanel account username.

Step 5: Verify the Virtual Host Configuration

Verify that the Apache virtual host includes are correctly configured:

/scripts/verify_vhost_includes

Make sure there are no configuration errors before restarting Apache.

Step 6: Restart Apache

Restart the Apache service:

service httpd restart

The bandwidth configuration should now be applied to the specified cPanel account.

Conclusion

Apache bandwidth modules can be used to control the bandwidth consumed by individual cPanel accounts. By creating a custom userdata configuration and applying it to the required virtual host, you can throttle bandwidth without modifying the main Apache configuration.

This approach is useful on shared hosting servers where one account is consuming significantly more bandwidth than other hosted accounts.

FAQs

1. How can I check whether the bandwidth modules are installed?

Run:

/usr/local/apache/bin/apachectl -M |grep bw

This displays the installed Apache modules matching bw.

2. Can I limit bandwidth for only one cPanel account?

Yes. The userdata configuration can be created specifically for the required cPanel username and domain.

3. Where should the bandwidth configuration file be created?

Create it under:

/usr/local/apache/conf/userdata/std/2_4/username/domain.tld/

4. What does BandWidth all 512000 do?

It applies the configured bandwidth value to all traffic handled by the corresponding Apache virtual host.

5. Do I need to restart Apache after making the change?

Yes. After applying and verifying the virtual host configuration, restart Apache:

service httpd restart

Configure Multiple PHP with LiteSpeed cPanel Server

Learn how to configure and manage multiple PHP versions on a cPanel server running LiteSpeed.

https://pheonixsolutions.com/blog/configure-multiple-php-litespeed-cpanel-server/

Install mod_evasive Module on cPanel EasyApache

Learn how to install and configure the Apache mod_evasive module on a cPanel server to help handle excessive requests.

https://pheonixsolutions.com/blog/install-mod-evasive-module-cpaneleasy-apache-4/

Talk to our experts

Looking for the right technology solution for your business? Our team of experts can help you with development, cloud, DevOps, design, and a wide range of other technology needs. Get in touch with our team here.

admin

Writes about Cloud & AWS at Pheonix Solutions.

Leave a Reply

Scroll to Top