PHP Handlers

From wiki.mikejung.biz
Jump to: navigation, search

LiquidWeb API Banner.jpg

cPanel PHP Handlers Overview

A PHP handler is an Apache module which allows Apache to read and execute PHP code. cPanel currently has 4 main PHP handlers which can be added / removed via EasyApache. Each PHP handler has it's own pros and cons. DSO is relatively fast, however PHP will run as "nobody" which may not be ideal on a server that is hosting many websites and has multiple cPanel users. SuPHP is more secure than DSO because it allows PHP to run as the cPanel user, so you can execute multiple PHP scripts at once all running as their specific user.

FCGI is similar to SuPHP, but it's significantly faster (3x to 5x). FCGI also runs PHP as the cPanel user, but unlike SuPHP you can configure FCGI to keep processes alive for long periods of time, and to cache PHP code via OPcache, this means that PHP code only has to be compiled once, any time the code needs to run again it can execute significantly faster, this means a faster website and less CPU utilization.

  • DSO -- cPanel installs this handler by default, however DSO is not selected as the default handler. This means that you can quickly switch between DSO and SuPHP without having to run Easy Apache.
  • SuPHP -- cPanel installs and enables this handler by default. SuPHP is secure and compatible with lots of stuff, however it's pretty slow and can be memory intensive.
  • FCGI -- Not installed or enabled by default. Can enable FCGI by running EasyApache and selecting "mod_fastcgi". UserDir does not work with FCGI and PHP applications must support the FastCGI protocol.
  • CGI -- Old and not fast

How to select cPanel PHP Handler

WHM

To modify the default PHP handler in WHM you can simply type in "php" on the left search bar in WHM. Under "Service Configuration" there is a sub option called "Configure PHP and suEXEC" click on that link and you should see a page that looks like this:

WHM how to change php handler fcgi.png

To change the PHP handler from FCGI to SuPHP you need to click on the dropdown box to the right of "PHP 5 Handler" select SuPHP and click on the blue bottom called "Save New Configuration".

CLI

You can run the command below to view available handlers for PHP, as well as the current PHP handler.

/usr/local/cpanel/bin/rebuild_phpconf --current

If you run Easy Apache and select all the handlers, the output of the command above should display something like this:

Available handlers: suphp fcgi cgi none
DEFAULT PHP: 5
PHP4 SAPI: none
PHP5 SAPI: suphp
SUEXEC: enabled
RUID2: not installed

To change the handler from SuPHP to FCGI, you would run this command

/usr/local/cpanel/bin/rebuild_phpconf 5 none fcgi 1

The first option "5" is the default version of PHP to use. The second option "none" is what handler to use for PHP 4. PHP 4 is old, slow and not secure so I don't even want a handler for it, or allow anyone to use PHP 4. The third option is "fcgi" which is the handler to use for PHP 5. Finally, the last option "1" is to enable SuExec, if you don't want to enable suexec then you would use a "0" instead of a "1".

Once you run that command, you should be able to check --current and see that FCGI handler is now in use.

Available handlers: suphp fcgi cgi none
DEFAULT PHP: 5
PHP4 SAPI: none
PHP5 SAPI: fcgi
SUEXEC: enabled
RUID2: not installed

PHP Handler Performance Comparisons and Benchmarks