Secure, Fast and Experimental
       PHP Handling
         PBWEB.CO.UK
         @PHILL_BROWN
What is a PHP Handler?
<?php            Interprets       Hello
echo ‘Hello’;       code
DSO (mod_php)
• Makes PHP part of Apache

• Oldest and most common

• Runs in the same process as Apache -
  low CPU and memory usage

• PHP-created files owned by apache user
CGI
• Run as a program outside of your server

• Reads php.ini configuration at runtime

• Loads PHP on every request - requires
  more CPU time and processes
suPHP
• Apache runs as the user that owns the
  requested PHP script

• Doesn’t support PHP accelerators eg APC

• High CPU usage
FastCGI
• Apache runs as the user that owns the
  requested PHP script

• Keeps a persistent session in the
  background

• Lower CPU but high memory usage
Summary
                              DSO     CGI   suPHP   FastCGI
CPU usage

Memory usage

Run as file owner

Supports PHP Accelerators
The Ultimate Handler Setup
  CPU usage

  Memory usage

  Run as file owner

  Supports PHP Accelerators
Enter mod_ruid2
What is mod_ruid2?
mod_ruid2                        Apache                        /webroot




         Tells Apache to run                 Loads a wrapper
       /webroot files as User1            program that executes
             and Group1                   your scripts using the
                                          configured credentials
Where did mod_ruid2 come from?
 mod_suid2   Faster    mod_ruid2



                      Makes use of the
                      Linux kernel to
                      reduce processes
How do we use mod_ruid2 to achieve
    The Ultimate Handler Setup?
DSO + mod_ruid2
DSO
• Low CPU usage
                            mod_ruid2
                            • Process
                              ownership control
• Low memory usage

• PHP accelerator support
Apache server




                    User2
Site1 files       Site2 files   Site3 files
owned by          owned by      owned by
  User1             User2         User3
Apache is imprisoned in each website
It gets better..
Site 1

includes
misc
modules
            Apache can write
               to any file
profiles
scripts
sites
themes
index.php
...
Site 1

includes
misc
                        But we can
modules
profiles
scripts               lockdown Apache
sites/default/files
themes
index.php
...
                         even further
Create a separate user for Apache
Group




User           ApacheUser
This is
     The Ultimate Handler Setup
‐rw‐r‐‐‐‐‐ User Group index.php


drwxrwx‐‐‐ User Group sites/default/files
Thank you for listening!
  Handling questions..
     PBWEB.CO.UK
      @PHILL_BROWN

PHP Handlers

  • 1.
    Secure, Fast andExperimental PHP Handling PBWEB.CO.UK @PHILL_BROWN
  • 2.
    What is aPHP Handler? <?php Interprets Hello echo ‘Hello’; code
  • 3.
    DSO (mod_php) • MakesPHP part of Apache • Oldest and most common • Runs in the same process as Apache - low CPU and memory usage • PHP-created files owned by apache user
  • 4.
    CGI • Run asa program outside of your server • Reads php.ini configuration at runtime • Loads PHP on every request - requires more CPU time and processes
  • 5.
    suPHP • Apache runsas the user that owns the requested PHP script • Doesn’t support PHP accelerators eg APC • High CPU usage
  • 6.
    FastCGI • Apache runsas the user that owns the requested PHP script • Keeps a persistent session in the background • Lower CPU but high memory usage
  • 7.
    Summary DSO CGI suPHP FastCGI CPU usage Memory usage Run as file owner Supports PHP Accelerators
  • 8.
    The Ultimate HandlerSetup CPU usage Memory usage Run as file owner Supports PHP Accelerators
  • 9.
  • 10.
    What is mod_ruid2? mod_ruid2 Apache /webroot Tells Apache to run Loads a wrapper /webroot files as User1 program that executes and Group1 your scripts using the configured credentials
  • 11.
    Where did mod_ruid2come from? mod_suid2 Faster mod_ruid2 Makes use of the Linux kernel to reduce processes
  • 12.
    How do weuse mod_ruid2 to achieve The Ultimate Handler Setup?
  • 13.
  • 14.
    DSO • Low CPUusage mod_ruid2 • Process ownership control • Low memory usage • PHP accelerator support
  • 15.
    Apache server User2 Site1 files Site2 files Site3 files owned by owned by owned by User1 User2 User3
  • 16.
    Apache is imprisonedin each website
  • 17.
  • 18.
    Site 1 includes misc modules Apache can write to any file profiles scripts sites themes index.php ...
  • 19.
    Site 1 includes misc But we can modules profiles scripts lockdown Apache sites/default/files themes index.php ... even further
  • 20.
    Create a separateuser for Apache
  • 21.
    Group User ApacheUser
  • 22.
    This is The Ultimate Handler Setup ‐rw‐r‐‐‐‐‐ User Group index.php drwxrwx‐‐‐ User Group sites/default/files
  • 23.
    Thank you forlistening! Handling questions.. PBWEB.CO.UK @PHILL_BROWN