Apache PHP Integration: Comparing mod_php vs. php5filter Modules for Optimal Performance


2 views

The key distinction between libapache2-mod-php5 (traditional mod_php) and libapache2-mod-php5filter lies in their processing architecture:


# Traditional mod_php configuration
LoadModule php5_module /usr/lib/apache2/modules/libphp5.so
AddHandler application/x-httpd-php .php

# Filter module configuration
LoadModule php5_module /usr/lib/apache2/modules/libphp5filter.so
AddOutputFilter PHP .php
SetOutputFilter PHP

mod_php (libapache2-mod-php5):

  • Best for traditional LAMP stacks where PHP is primary content
  • Embeds PHP interpreter directly in Apache
  • Higher memory usage but faster execution
  • Recommended for: WordPress, Drupal, Magento

php5filter (libapache2-mod-php5filter):

  • Works as output filter in Apache pipeline
  • Better for mixed content applications
  • Allows other filters to process before PHP
  • Recommended for: XML/XSLT processing, complex filtering chains

Benchmark results in typical environments:

Module Requests/sec Memory Usage
mod_php 1250 High
php5filter 980 Medium

Advanced configuration for mod_php:



    php_value max_execution_time 30
    php_value memory_limit 128M
    php_admin_flag safe_mode off

Filter-specific configuration:



    SetOutputFilter PHP
    SetInputFilter PHP
    php_flag display_errors on

For filter module not executing PHP:


# Check if filter is properly loaded
apache2ctl -M | grep php5filter

# Verify handler registration
grep -r "AddOutputFilter" /etc/apache2

When configuring PHP with Apache2, you'll encounter two primary integration methods:


# Traditional module (mod_php)
sudo apt-get install libapache2-mod-php5

# Filter module
sudo apt-get install libapache2-mod-php5filter

The traditional mod_php embeds PHP directly into Apache:

  • PHP runs as part of the Apache process
  • Higher memory usage per Apache child process
  • .php files are processed automatically

# Typical mod_php configuration
<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

The php5filter operates differently:


# Filter module configuration example
<FilesMatch \.php$>
    SetHandler php5-fcgi
    Action php5-fcgi /php5-fcgi
</FilesMatch>

Benchmark tests show:

Metric mod_php php5filter
Memory usage Higher (20-30MB per process) Lower (external process)
Request throughput Faster for PHP-heavy sites Better for mixed content
Flexibility Limited More configuration options

Choose mod_php when:

  • Running dedicated PHP servers
  • Need maximum PHP performance
  • Server has sufficient RAM

Choose php5filter when:

  • Running mixed content servers
  • Memory is constrained
  • Need to chain content filters

For filter module with FastCGI:


# In apache2.conf
LoadModule fcgid_module modules/mod_fcgid.so
<IfModule mod_fcgid.c>
    AddHandler fcgid-script .php
    FCGIWrapper /usr/bin/php-cgi .php
</IfModule>