Apache MPM ITK RPM for CentOS 5

Building and using Apache MPM ITK for improved security in shared hosting environments

๐Ÿ”ง

What is Apache MPM ITK?

Apache2-mpm-itk provides a modified httpd daemon that allows each web site (vhost) in a shared hosting environment to run under a separate user account.

Why is this important?

โš ๏ธSecurity Concerns

By default, without a solution like mpm-itk, all web sites run under the "apache" user account. If all web sites are managed by the same entity, this is not necessarily a big issue. However, if the content of these sites is managed by more than one entity, or if one of those sites is hacked, there are serious security implications.

๐Ÿ”“File Access Issues

In order for the apache daemon (httpd) to be able to serve-up content and execute PHP for all of the web sites it hosts, all files must be readable by the "apache" user. This includes:

  • โ€ข .htpasswd files
  • โ€ข PHP configuration files
  • โ€ข Database login credentials
  • โ€ข Other sensitive configuration data

๐ŸšซPHP Safe Mode Limitations

Features within PHP designed to mitigate these problems, such as Safe Mode, are next to useless and can provide a false sense of security. These features are trivial to bypass. Consequently, Safe Mode itself has been removed from PHP 5.4 and above.

How does mpm-itk work?

๐Ÿ”„

Process Switching

Anyone familiar with how a traditional Unix SMTP MTA delivers mail to local users will be familiar with the basic mechanics of mpm-itk. Instead of running as the "apache" user, httpd runs as root, but with limited privileges.

Process Flow:
1. httpd retains root's ability to "su" to any other user account
2. After determining which web site the request is for
3. httpd then su's to either a designated user account for that site
4. Or failing that, to the regular apache user

The Spec File

Download and Patches

The spec file can be downloaded from the original source. For those more security conscious, this is a patch against the current (2.2.3-65) httpd.spec, complete with explanation:

# ITK Patches added to spec file:
+# ITK
+Patch402: http://mpm-itk.sesse.net/apache2.2-mpm-itk-2.2.17-01/02-rename-prefork-to-itk.patch
+Patch403: http://mpm-itk.sesse.net/apache2.2-mpm-itk-2.2.17-01/03-add-mpm-to-build-system.patch
+Patch404: http://mpm-itk.sesse.net/apache2.2-mpm-itk-2.2.17-01/04-correct-output-makefile-location.patch
+Patch405: http://mpm-itk.sesse.net/apache2.2-mpm-itk-2.2.17-01/05-add-copyright.patch
# ... additional patches ...

Package Description

%package -n httpd-itk
Group: System Environment/Daemons
Summary: MPM Itk for Apache HTTP Server
URL: http://mpm-itk.sesse.net/
License: ASL 2.0
Requires: httpd = %{version}-%{release}

Building Process

Directory Setup

mkdir server/mpm/experimental/itk/
cp server/mpm/prefork/* server/mpm/experimental/itk/
mv server/mpm/experimental/itk/prefork.c server/mpm/experimental/itk/itk.c

Build Commands

# Install source RPM
rpm -ivh httpd-2.2.3-65.el5.centos.3.src.rpm
# Build the package
rpmbuild -bb /usr/src/redhat/SPECS/httpd.spec
# Navigate to built RPMs
cd /usr/src/redhat/RPMS/`uname -i`/
# Install ITK package
rpm -ivh httpd-itk-2.2.3-65.el5.centos.3.`uname -i`.rpm

Using MPM ITK

Configuration

To use the ITK MPM, you'll need to modify your Apache startup configuration:

HTTPD=/usr/sbin/httpd.itk

PHP Considerations

When using worker MPM with PHP, special considerations apply:

<IfModule !worker.c>
LoadModule php5_module modules/libphp5.so
</IfModule>
<IfModule worker.c>
# Use of the "ZTS" build with worker is experimental
LoadModule php5_module modules/libphp5-zts.so
</IfModule>

โš ๏ธ Important Notes:

  • โ€ข This tutorial is specific to CentOS 5
  • โ€ข Always test in a development environment first
  • โ€ข Backup your current Apache configuration
  • โ€ข Consider performance implications for high-traffic sites

MPM ITK Benefits

๐Ÿ”’

Enhanced Security

Each virtual host runs under its own user account, preventing cross-site access to sensitive files and configurations.

โšก

Better Performance

Faster than CGI solutions like suexec while maintaining security isolation between different hosted sites.

๐Ÿ”ง

PHP Compatible

Safely use non-thread-aware code and PHP extensions that wouldn't work properly in threaded environments.

Need Help with Apache Configuration?

Our technical team has extensive experience with Apache MPM configurations and can help you implement secure hosting solutions.