A PHP handler is an Apache module that interprets and runs PHP code. There are a handful of handlers to choose from, and each has its advantages and disadvantages. What’s more, using the most suitable handler for you website can have a huge impact on the performance of your websites.
What handler to use depends on many variables. This makes PHP handlers a complicated topic. We are of course more than happy to work with you to make sure that your server’s configuration is optimal for your particular workload – it’s what managed hosting is all about.
cPanel servers support multiple PHP versions, and different virtual hosts can use different PHP versions. For instance, you might have the website example.com running PHP 7.3 and a dev.example.com subdomain that uses PHP 7.4. On top of that different PHP versions can use different handlers.
The WHM interface for PHP handlers depends on the cPanel version you are using. For versions up to 86 you can view what handlers are used via Software » MultiPHP Manager. The PHP Handlers tab lists the PHP versions and their handler. More recent cPanel versions show the same information under Software » MultiPHP Manager (new). This interface has two tabs:
If you prefer the command line, you can get information about PHP versions and handlers by looking at /etc/apache2/conf.d/php.conf.
You can change the PHP handler for a PHP version by selecting a handler from the drop-down list. The one exception is PHP-FPM, which strictly speaking isn’t a handler. To use PHP-FPM you first needs to be enable it and then apply it to one or more domains via the User Domain Settings tab.
cPanel servers offer six different PHP handlers out of the box.
CGI (mod_cgi) is rarely used, as it’s slow and relatively insecure. There are better variations on the handler. Before we get to them, it’s still useful to understand how CGI works.
You can think of CGI as a technology that let’s a web server talk to external applications. It lets Apache interact with server-side scripting languages such as PHP and Perl. Historically, such scripts were often installed in the cgi-bin directory. When a script in the directory was accessed the server ran the script and the output was sent to the user’s browser. The cgi-bin directory isn’t required to process server-side code – servers are usually configured to treat any PHP script as a CGI script.
CGI has the following characteristics:
DSO (mod_php) is not enabled by default on cPanel servers. It can be installed via EasyApache (search for “dso” under PHP Extensions). Note that you need to use the Prefork MPM with DSO.
As with CGI, you are unlikely to use the handler but it’s useful to understand its basics.
suPHP (mod_suphp) works much like CGI but is more secure as PHP scripts are always executed with the permissions of their owner. This is particularly important on servers that have multiple user accounts. However, suPHP is no longer maintained and largely replaced by PHP-FPM.
FastCGI (mod_fcgid) is a much improved version of CGI. One of the main reasons why it performs very well is that it keeps PHP script in memory. This means it doesn’t have to start a new PHP process every time a PHP script is executed.
FPM isn’t really a handler. Instead, it’s a daemon that takes FastCGI to the next level. It more efficiently manages processes (by using pools) and has advanced features, including a “slow log”. It’s also relatively light on memory.
The main downside of PHP-FPM is that its configuration is more complicated and that it works slightly differently. For instance, on cPanel servers error logs for users are stored in the ~/logs directory and the global error log is /opt/cpanel/ea-php??/root/usr/var/log/php-fpm/error.log (where ?? is the PHP version). Similarly, if you need to restart PHP-FPM then you need to do so either via WHM » Restart Services » PHP-FPM service for Apache or using the command /scripts/restartsrv_apache_php_fpm
.
In short, PHP-FPM is an advanced and feature-rich tool. In particular high-traffic website can benefit from using PHP-FPM, but it may need some tweaking. We can of course work with you to get the most out of PHP-FPM.
LiteSpeed is a drop-in replacement for the Apache web server. LiteSpeed is included by default on cPanel servers that run CloudLinux and has its own control panel (Plugins » LiteSpeed Web Server). For RHEL, Centos and Amazon Linux servers you can use cPanel’s own “light” LSAPI version. The latter option is unlikely to perform better than PHP-FPM.
One of the main selling points of LSAPI is that it “just works”. It usually doesn’t involve tweaking and fine-tuning, and for end users it works as expected. For instance, you can add PHP directives in .htaccess files.
If you are switching from PHP-FPM to LiteSpeed then you need to first disable PHP-FPM for individual domain before selecting the lsapi handler.