How to recompile Apache,PHP and IMAP with increased value of file descriptors larger than FD_SETSIZE (1024) on RedHat-like systems.
* Plesk for Linux/Unix
SYMPTOMS
RPM packages are compiled by vendors with too small (1024) number of file descriptors and it might 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
This is common Apache issue on the servers with many Virtual Hosts configured, see for more information http://httpd.apache.org/docs/2.0/misc/descriptors.html.
RESOLUTION
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.
Note, Plesk does not rebuild system RPM packages but use them ‘as is’. This allows packages upgrading and compiling with the options administrator wish. This article is written to help administrators of Plesk to configure their OS and system packages, that are not included into by Plesk distribution, to use with large amount of domains in Plesk.
You need to recompile related applications and libraries, such as openssl, apache, imap, PHP etc from source RPMs with increased FD_SETSIZE value. Please follow through the steps below.
Make sure that the system allows to open enough files:
# /sbin/sysctl fs.file-max
fs.file-max = 131072
If fs.file-max is quite small (several thousands or so), it should be changed by adding the following lines to /etc/sysctl.conf:
fs.file-max = 131072
and running the shell command:
# /sbin/sysctl -w fs.file-max=131072
Note, if you are running Virtuozzo you have to adjust fs.file-max on the hardware node and it will be applied to all VEs.
Edit __FD_SETSIZE value in typesizes.h and posix_types.h files that can be found with:
# find /usr/include/ -name typesizes.h
# find /usr/include/ -name posix_types.h
(Note, glibc-kernheaders and glibc-headers package has to have been installed before).
and set it like:
#define __FD_SETSIZE 65536
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 is 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, 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
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, for example:
# rpmbuild –rebuild php-4.3.10-2.4.src.rpm
# rpm -Uvh –force /usr/src/redhat/RPMS/i386/php-*
Add `ulimit -n 65536` 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