Introduction to PHP


Last modified: March 25, 2024

Overview

Websites frequently use the PHP scripting language for applications and content. EasyApache allows you to easily install and modify PHP for your server.

When you install cPanel & WHM, the installation process automatically installs PHP with some common PHP options.

For more information about PHP, read the PHP website.

How Apache handles PHP

By default, cPanel & WHM configures your Apache web server to use the CGI PHP handler to handle requests that it receives for PHP content.

Note:
The PHP handler that you select affects the speed and security of your web server. For more information about PHP handlers, read our PHP Handlers documentation.

PHP versions

The cPanel default profile includes PHP versions 8.1 and 8.2. You can install additional PHP versions with WHM’s EasyApache 4 interface (WHM » Home » Software » EasyApache 4).

EasyApache 4 supports PHP versions 5.4 through 5.6, PHP versions 7.0 through 7.4, and PHP 8.0 through 8.3.

Note:

EasyApache 4 adheres to the php.net supported versions timeline. The profiles that we supply in WHM’s EasyApache 4 interface (WHM » Home » Software » EasyApache 4) only provide PHP versions that php.net currently supports.

Packages for unsupported versions of PHP will remain on the cPanel L.L.C. mirrors and servers, but we will not provide any further updates.

When the PHP development team makes a new version of PHP available, we test and then make the new version available in EasyApache.

Minor version number changes do not impact functionality, but major updates may require changes to your configuration. In many cases, the EasyApache software will make the necessary adjustments automatically. Custom configurations may require further manual adjustments.

For more information on PHP versions and extensions available in EasyApache 4, read our PHP Options documentation.

MultiPHP

EasyApache 4 supports multiple versions of PHP.

To change your server’s default version of PHP or a virtual host’s version of PHP, use WHM’s MultiPHP Manager interface (WHM » Home » Software » MultiPHP Manager).

If the version of PHP that you wish to use does not exist on your server, you can install it in WHM’s EasyApache 4 interface (WHM » Home » Software » EasyApache 4). To install your PHP version with a package manager, read our How to Locate and Install a PHP Version or Extension documentation.

Each version of PHP that you install will use a separate php.ini file. To update these php.ini files, you must use the MultiPHP Editor for cPanel interface (cPanel » Home » Software » MultiPHP INI Editor for cPanel) or make changes separately to each file. Each file exists in the /opt/cpanel/ea-php##/root/etc/php.ini path, where ## is the PHP version number.

Warning:

We strongly recommend that you only edit your server’s EasyApache 4 php.ini files with cPanel’s MultiPHP INI Editor interface (cPanel » Home » Software » MultiPHP INI Editor).

Vendor-provided PHP versions

EasyApache 4 allows you to use PHP versions that WebPros International, LLC does not provide. These PHP versions must be a Software Collection Library (SCL) package and cannot start with the ea- prefix that EasyApache 4 uses.

  • You cannot use the EasyApache 4 interface (WHM » Home » Software » EasyApache 4) to install vendor-provided versions of PHP. You must use a package manager to install these packages on your system. For more information, read our Package Manager Basics documentation.
  • After you install the packages, you can use WHM’s MultiPHP Manager interface (WHM » Home » Software » MultiPHP Manager) and WHM’s MultiPHP INI Editor interface (WHM » Home » Software » MultiPHP INI Editor) to make changes.
Important:
  • The DSO PHP handler is not available with rh- and alt- PHP packages.
  • cPanel & WHM does not support DSO on PHP 8.0 and higher.
  • SCL PHP packages require a vendor prefix in order to install in EasyApache 4. For example, you cannot use RHEL PHP versions 5.4 or 5.5 because these packages do not begin with a vendor prefix.
  • Not all vendor-provided PHP packages will contain all of the files that EasyApache 4’s MultiPHP system requires. You may experience additional limitations.

Potential issues

Some potential issues exist in vendor-provided versions of PHP.

Vendor-provided php.ini does not exist

In some cases, a vendor-provided PHP version’s php.ini file will not exist in the directory that cPanel & WHM requires. For example, RHEL’s PHP 5.6 .ini file exists in the /opt/rh/rh-php56/register.content/etc/opt/rh/rh-php56 directory, but cPanel & WHM expects it in the /opt/rh/rh-php56/root/etc directory. You must create a symlink in order for the MultiPHP system to read the php.ini file.

To create the symlink, use the following command, where php56 represents the PHP version that you wish to use:

ln -s /opt/rh/rh-php56/register.content/etc/opt/rh/rh-php56 /opt/rh/rh-php56/root/etc

If you installed the PHP version before you created the symlink, you must reinstall the PHP version with the following command, where php56 represents the PHP version that you wish to use:

yum reinstall rh-php56*
PHP CLI and PHP CGI binaries in different locations

Some PHP versions include the PHP CLI and PHP CLI binaries in different locations than cPanel & WHM’s implementation. In these cases, the PHP installation reverses the location of these binaries. If your PHP version does this, then the following issues may occur:

  • The php-cgi binary path will not exist.
  • The php-cli binary path will be incorrect.

To fix this issue, use the following commands, where prefix represents the vendor prefix and package represents the package name:

1
2
mv /opt/prefix/package/root/usr/bin/php /opt/prefix/package/root/usr/bin/php-cgi
mv /opt/prefix/package/root/usr/bin/php-cli /opt/prefix/package/root/usr/bin/php

Modify PHP

You can use several methods to modify your PHP configuration. For more information, read the following documentation:

  • PHP Options — A list of the available options in EasyApache that directly modify PHP.
  • PHP Handlers — The PHP handler that you select determines how Apache handles requests for PHP content.

To more easily allow you to call the PHP binaries directly, we provide the following symlinks for each version of PHP installed on your system:

  • PHP CLI — /usr/local/bin/ea-php##, where ## represents the two-digit PHP version.
  • PHP CGI — /usr/bin/ea-php## command, where ## represents the two-digit PHP version.

To more easily allow you to install PECL and PEAR extensions, we provide the following symlinks:

  • PECL — /usr/bin/ea-php##-pecl, where ## represents the two-digit PHP version.
  • PEAR — /usr/bin/ea-php##-pear, where ## represents the two-digit PHP version.

Adjust configuration files

To further customize your PHP configuration, you can edit your .ini files. We strongly recommend that you only edit your configuration files with cPanel’s MultiPHP INI Editor interface (cPanel » Home » Software » MultiPHP INI Editor). To edit your files manually, adjust the following Apache handler files in your document root:

PHP Security

To ensure that your PHP version stays up to date, use one of the following options:

  • Set the Operating System Package Updates section of WHM’s Update Preferences interface (WHM » Home » Server Configuration » Update Preferences) to Automatic.
  • As a user with root-level privileges, run yum update on the command line.
  • Install the CentOS-provided yum-cron package with the following command: yum install yum-cron.

For more information about PHP security, read our PHP Security Concepts documentation.

Additional Documentation