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

This article is for RedHat-like operation systems.
For the details on Debian system please follow this article.
For the details on FreeBSD system please follow this article. 

RedHat RPMs packages are compiled by vendor with too small (1024) number of file descriptors and it might cause the following issues: in /var/log/httpd/error_log multiple strings could be seen with

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

or
Unable to open logs
or
Too many open files

In this case you need to recompile OpenSSL, Apache, Imap and PHP from source RPM to increase FD_SETSIZE value. Please follow through the steps below.

Add the following lines to /etc/sysctl.conf:

fs.file-max =
131072

Run the following shell command:


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


Edit __FD_SETSIZE value in /usr/include/bits/types.h for RedHat 7.x or /usr/include/bits/typesizes.h and /usr/include/linux/posix_types.h for RedHat 9, Fedora Core, RHEL 2.1, 3, 4 (glibc-kernheaders and glibc-headers package has to have been installed before). If your system uses NPTL, you can find it with:

$ getconf GNU_LIBPTHREAD_VERSION

NPTL 2.3.4


then /usr/include/nptl/bits/typesizes.h header file also should be modified.


#define __FD_SETSIZE
131072

Download the following source RPM that could be found in other places such as http://rpm.pbone.net or
 http://rpmfind.net:
openssl-*.src.rpm
httpd-*.src.rpm
imap-*.src.rpm
php-*.src.rpm
libc-client-devel-*.src.rpm (if such RPM installed)
curl-*.src.rpm

Recompile OpenSSL first. For example:

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

Install 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 libc-client library which is provided by imap or libc-client-devel packages (it depends on OS) . You have to recompile one that is installed in the system:

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

or

# /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:

# rpmbuild --rebuild php-4.3.10-2.4.src.rpm

# rpm -Uvh --force /usr/src/redhat/RPMS/i386/php-*

Add 'ulimit -n
131072' command to /etc/rc.d/init.d/httpd and /usr/sbin/apachectl apache startup scripts before other commands.

Replace /usr/sbin/suexec with Plesk one:

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

Since Plesk 7.5:

# cp /usr/local/psa/suexec/psa-suexec /usr/sbin/suexec
# /etc/init.d/httpd restart
  • 3 Users Found This Useful
Was this answer helpful?

Related Articles

Domain Name Prices

TLD Price Min Term...

Helm Support Manuals

 Helm 3 Documentation View and download Helm 3 documentation.  Helm...

How can I change a Name-based site to an IP-based?

To upgrade a site from name-based to IP-based use the following command in SSH as root....

How can I install CDONTS on Windows 2003 Server?

Microsoft Windows Server 2003 does not install Collaboration Data Objects (CDO) for NTS...

Powered by WHMCompleteSolution