How to change PHP handler from Server Backend
PHP handler means the way apache software on the server serves PHP scripts. On cPanel/WHM Servers there are four PHP handlers : SuPHP, DSO, CGI, FastCGI. suPHP is the default handler on cPanel/WHM Servers. You might be familiar with switching the PHP handler from Web Host Manager(WHM) but most of us are not sure how to do the same from server backend. This article will enlighten how to switch PHP handler on a cPanel/WHM Server.
Command to check the current PHP handler on the server
Command :
/usr/local/cpanel/bin/rebuild_phpconf --current
The below command will show the current PHP handler on your cPanel server.
Available handlers: suphp dso fcgi cgi none
DEFAULT PHP: 5
PHP4 SAPI: none
PHP5 SAPI: suphp
SUEXEC: enabled
RUID2: not installed
Command to list all available PHP handlers on the server
Command :
/usr/local/cpanel/bin/rebuild_phpconf --available
Run the above command on the server and it will list all available PHP handlers on the server. An Example is given below :
PHP4 SAPI: not installed
PHP5 SAPI: cgi-fcgi
SUEXEC: available
RUID2: not available
Command to change the current handler to CGI
Advantages and drawback of CGI (mod_cgi) :
- CGI (Common Gateway Interface), also known as mod_cgi
- It is highly configurable
- It is neither fast nor secure
- It does not support apache directives
On cPanel/production servers this handler is not recommended. This handler is used only when DSO and suPHP is not available.
Command:
/usr/local/cpanel/bin/rebuild_phpconf 5 none cgi 1
Command to change the current handler to DSO
Advantages and drawback of DSO (mod_php):
- DSO (Dynamic Shared Object), also known as mod_php.
- Main advantage is speed. It consumes less memory and CPU.
- Opcode cache like eAccelerator, APC is compatible with this handler.
- PHP users will run as Apache user ‘nobody’ so it is not secure.
- In DSO + ModRuid2 setup the PHP script will not run with nobody ownership so it is secure.
- It support Apache directives
Log into server via SSH as root and run the below command to change the handler to DSO
DSO (Dynamic Shared Object) is used for speed
Command to switch to DSO :
/usr/local/cpanel/bin/rebuild_phpconf 4 dso none 1
Command to change the current handler to suPHP
Advantages and drawback of suPHP (mod_suphp) :
- suPHP + suEXEC is secure because it will show the user who owns the PHP script so it is secure compared to other handlers.
- It is not compatible with opcode cache like EAccelerator, XCache. Installing opcode cache will not have any effect.
- It is the default handler on cPanel servers
- suPHP consumes high CPU
- It is slower than DSO and FastCGI
- Do not support Apache directives
Command to switch to suPHP :
/usr/local/cpanel/bin/rebuild_phpconf 5 none suphp 1
Command to change the current PHP handler to FCGI
Advantages and drawback of FCGI (mod_fcgi):
- It is faster compared to suPHP
- FCGI with SuExec enabled is a secure setup.
- This handler consumes more memory but less CPU
- It support opcode caching
Command to switch to FastCGI :
/usr/local/cpanel/bin/rebuild_phpconf 5 none fcgi 1
Command usage :
Usage: /usr/local/cpanel/bin/rebuild_phpconf [--dryrun] [--no-restart] [--no-htaccess] [--current|--available] [--errors] <Default PHP> <PHP4 Handler> <PHP5 Handler> <Suexec> --dryrun : Only display the changes that would be made --no-restart : Don't restart Apache after updating the php.conf link --no-htaccess : Don't update user configurable PHP mime mapping. --current : Show current settings --available : Show available handlers and PHP SAPIs --errors : Print additional errors on stderr instead of only writing to log <Default PHP> : Version of PHP to set as default handler for .php files <PHP# Handler> : Type of Apache module to use in serving PHP requests <Suexec> : enabled, disabled, 1 or 0
EasyApache4 Commands
Command to switch to DSO Handler:
--default means default PHP version ea-php56 = This is for PHP5.6, change the PHP version accordingly. Command : /usr/local/cpanel/bin/rebuild_phpconf --default=ea-php56 --ea-php56=dso
DEFAULT PHP: ea-php56
ea-php55 SAPI: cgi
ea-php56 SAPI: dso
ea-php70 SAPI: cgi
Command to switch to suPHP Handlder
Command :
/usr/local/cpanel/bin/rebuild_phpconf --default=ea-php56 --ea-php56=suphp
DEFAULT PHP: ea-php56
ea-php55 SAPI: cgi
ea-php56 SAPI: suphp
Command to switch to CGI Handler
Command :
/usr/local/cpanel/bin/rebuild_phpconf --default=ea-php56 --ea-php56=cgi
ea-php55 SAPI: cgi
ea-php56 SAPI: cgi
ea-php70 SAPI: cgi
Command to switch to FCGI Handler :
FCGI is not a supported PHP handler in WHM version 58 EasyApache4. It is however supposed to be available in the upcoming WHM version 60 release.