Unfortunately there is no libapache2-mod-bw for Ubuntu, so limiting bandwidth used by apache isn’t possible by default. Follow these steps to enable it.
wget http://ivn.cl/files/source/mod_bw-0.8.tgz
tar xvzf mod_bw-0.8.tgz
cd mod_bw
apxs2 -i -a -c mod_bw.c
You will probably get this error
apxs:Error: Activation failed for custom /etc/apache2/httpd.conf file..
apxs:Error: At least one `LoadModule’ directive already has to exist..
It’s safe to ignore this.
vi /etc/apache2/mods-available/mod-bw.load
LoadModule bw_module /usr/lib/apache2/modules/mod_bw.so
vi /etc/apache2/mods-available/mod-bw.conf
BandWidthModule On
BandWidth all 40000
MinBandWidth all 10000
ForceBandWidthModule On
Set permissions
chown www-data /etc/apache2/mods-available/mod-bw*
Activate the module
a2enmod mod-bw
(To deactivate use: a2dismod mod-bw)
Restart apache2
/etc/init.d/apache2 force-reload
Download a file (I suggest doing it remotely to test it), and you should be limited to around 40 kilobytes/second total, with each user guaranteed 10 kilobytes/second. Change this number accordingly.
These instructions worked without a hitch on my installation. I didn’t have apxs2, but the package manager told me it was in one of the apache2-dev meta-packages. This module works great, and I’m planning to use it as a “dial-up simulator” because most web developers are DIAL-UP UNFRIENDLY! >:(
The correct way to load the module would be to add the LoadModule line to /etc/init.d/apache2/mods-available/bandwidth.load, and then enable it with “a2enmod bandwidth” (you can then disable with “a2dismod bandwidth”). Then reload apache with /etc/init.d/apache2 force-reload
Ben, you have many excellent points so I’ve updated the article. Thanks. 🙂
For those that stumble across this and don’t use debian (or don’t have mods-available / mods-enabled) just put the contents of mod-bw.load and mod-bw.conf into /etc/apache2/apache2.conf