I have recently learnt that to be able to increase the amount of virtualhosts that we can serve via Apache depends on file-descriptors.

they say the value should be added to /etc/sysctl.conf as

fs.file-max = 65536

What is the correlation between amount of RAM I have with the number above ?

Could you tell me like;

"You should have X GB RAM and Y GHz CPU to be able to set fs.file-max to Z"

I basically want to know X - Y - Z relationship to be able to make the setting.

Server is an Ubuntu 8.04 and I can increase the RAM or CPU to virtually any number through my cloud server provider.

ps: or why should I care about this? Is there a way that I can set up my system that it will serve as my memory permits it to serve ?

this is the tutorial (official plesk doc)

  1. Add the following line to /etc/sysctl.conf:

    $ fs.file-max = 65536
  2. Run the following shell command:

    $ /sbin/sysctl -w fs.file-max=65536

    Note that the value fs.file-max can be equal up to 220=1048576).

  3. Add the following line to beginning of /etc/init.d/apache2 and /usr/sbin/apache2ctl:

    $ ulimit -n `cat /proc/sys/fs/file-max`
  4. Change __FD_SETSIZE value in /usr/include/bits/typesizes.h and /usr/include/nptl/bits/typesizes.h files. It should be like:

    $ define __FD_SETSIZE 65536
  5. Download and rebuild packages:

    $ apt-get install apt-src
    $ apt-src --build install openssl
    $ dpkg -i libssl*.deb openssl*.deb
    $ apt-src --build install apache2
    $ dpkg -i libapr*.deb apache2_*.deb apache2-common*.deb apache2-mpm-prefork*.deb apache2-utils*.deb
    $ cp /opt/psa/suexec/psa-suexec2 /usr/lib/apache2/suexec2
    /etc/init.d/apache2 restart
    $ apt-src --build install libc-client2002edebian
    $ dpkg -i libc-client-dev_2002edebian1-*.deb libc-client2002edebian*.deb
    $ apt-src --build install php4
    $ dpkg -i `ls *deb|grep php4|grep -v apache-mod`

1 Answer 1


I'd be surprised if your installation of Ubuntu didn't have by default more than 65536 available. Check your current setting with

$ sudo sysctl fs.file-max

The general rule of thumb is that you can increase the fs.file-max parameter by 64 for every 1MB of RAM.

e.g. 2 gigabytes = 2048 * 1MB
                 = 2048 * 64
                 = 131072

That's double 65536. I would hesitate using that if you don't actually need to use it, because in some cases it could decrease your performance. Just as important as the sysctl setting though is the __FD_SETSIZE because that is what your applications use when they use the system select(2) call.

My advice in general though is that >1000 VirtualHosts on one instance of Apcahe is too much of a nightmare to manage on one machine. One compromised host, any downtime etc. and you've got lots more sites screaming at you.

I worked in web hosting for more than 7 years, and my advice is to stump up for another machine for many reasons, performance being one of them, ease of maintenance another, all your eggs in one basket being another etc. etc.

  • Thanks Phil, we did set it up to maximum value 1,048,576 what sort of performance decrease should we expect ? And yes, we will offload vhosts, databases etc to other servers essentially but we want this machine not to crash but be slower in the meanwhile as we burst its RAM and CPU.
    – Devrim
    Dec 10, 2009 at 0:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.