How to recompile Apache, PHP, and IMAP with increased value of file descriptors larger than FD_SETSIZE (1024) on a RedHat-like system


2016-11-16 13:06:39 UTC


2017-08-16 17:18:04 UTC


Was this article helpful?

Have more questions?

Submit a request

How to recompile Apache, PHP, and IMAP with increased value of file descriptors larger than FD_SETSIZE (1024) on a RedHat-like system

Applicable to:

  • Plesk for Linux


RPM packages are compiled by vendors with too few file descriptors (1024), which may cause the following messages to appear in /var/log/httpd/error_log :

Segmentation fault (11)

[warn] make_sock: problem listening on port 443, file descriptor (1068) larger than FD_SETSIZE (1024)

Unable to open logs

Too many open files

httpd dead but subsys locked

This is a common Apache issue on servers where many Virtual Hosts are configured. See this article for more information: .


NOTE: Since Plesk 8.2.0, up to 900 domains can be hosted on the operating system (OS) vendor Apache build without the system packages recompilation described in this article. If the Piped Logs feature is enabled on the Plesk server, see 213393889 .

NOTE: This article is for Linux operating systems that have an RPM package structure, such as RHEL, CentOS.

For details on the Debian system, please see this article .

NOTE: Parallels Plesk requires many server applications that are not Plesk software. For example, the Apache web server, MySQL server, PHP module and binaries, and many other items which are not compiled or provided by Parallels. However, standard system RPM packages from the operating system vendor are used by Plesk "as is." This allows the administrator to upgrade and recompile these packages with their desired options. This article is written to help administrators of Plesk configure their OS and system packages that are not included in the Plesk distributive for use with a large number of hosted domains.

You need to recompile related applications and libraries, such as openssl , apache , imap , PHP , etc., from the source RPMs with an increased "FD_SETSIZE" value. Please follow these steps:

Make sure that the system allows you to open enough files:

# /sbin/sysctl fs.file-max
fs.file-max = 131072

If the value of "fs.file-max"  is small (several thousand or so), it should be changed by adding the following lines to /etc/sysctl.conf :

fs.file-max = 131072

Then, run the shell command:

# /sbin/sysctl -w fs.file-max=131072

NOTE: If you are running Virtuozzo Containers (PVC), you should adjust "fs.file-max"  on the Hardware Node. This will then be applied to all virtual environments.

glibc-kernheaders and glibc-headers packages should be installed. They can be taken from the operating system distributive CD or from your operating system's download sites. Edit the FD_SETSIZE value in the typesizes.h and posix_types.h files, which can be found using:

# find /usr/include/ -name typesizes.h
# find /usr/include/ -name posix_types.h

Then set the value as below:

#define __FD_SETSIZE 65536

Download the following source RPMs that can be found on your operating system's download sites or similar places. You can use RPM search engines such as or :

  • openssl-*.src.rpm
  • httpd-*.src.rpm
  • imap-*.src.rpm
  • php-*.src.rpm
  • libc-client-devel-*.src.rpm (if this RPM is installed)
  • curl-*.src.rpm

Recompile openssl first. For example:

# /usr/bin/rpmbuild --rebuild openssl-0.9.7a-35.src.rpm

Install the compiled openssl RPM with the following command line:

# rpm -Uvh --force /usr/src/redhat/RPMS/i386/openssl-0.9.7a-35.i386.rpm

Repeat the same actions for cURL .

Recompile and install Apache:

# rpmbuild --rebuild httpd-2.0.51-2.9.src.rpm
# rpm -Uvh --force /usr/src/redhat/RPMS/i386/httpd-2.0.51-2.9.i386.rpm
# rpm -Uvh --force /usr/src/redhat/RPMS/i386/httpd-devel-2.0.51-2.9.i386.rpm
# rpm -Uvh --force /usr/src/redhat/RPMS/i386/mod_ssl-2.0.51-2.9.i386.rpm

Recompile and install the libc-client library, which is provided by the imap or libc-client-devel packages (depending on the OS). You must recompile the one that is installed on the system. For example:

# /usr/bin/rpmbuild --rebuild imap-2002d-3.src.rpm
# rpm -Uvh --force /usr/src/redhat/RPMS/i386/imap-devel-2002d-3.i386.rpm


# /usr/bin/rpmbuild --rebuild libc-client-devel.src.rpm
# rpm -Uvh --force /usr/src/redhat/RPMS/i386/libc-client-devel.rpm

Recompile and install PHP . For example:

# rpmbuild --rebuild php-4.3.10-2.4.src.rpm
# rpm -Uvh --force /usr/src/redhat/RPMS/i386/php-*

Add a ulimit -n 65536 command to the /etc/rc.d/init.d/httpd and /usr/sbin/apachectl Apache startup scripts before any other commands.

Replace /usr/sbin/suexec with a Plesk one:

# cp /usr/local/psa/suexec/psa-suexec /usr/sbin/suexec
# /etc/init.d/httpd restart

Use the following commands for Plesk versions earlier than 7.5:

# cp /usr/local/psa/suexec/psa-suexec /usr/sbin/suexec
# chown root:apache /usr/sbin/suexec
# chmod 4510 /usr/sbin/suexec
# /etc/init.d/httpd restart
Have more questions? Submit a request
Please sign in to leave a comment.