WebHost Manager can be used to set the PHP version that is used by default. While default PHP version set in WHM applies server-wide, please note that, as mentioned by cPanelTristan, it is possible to override the server-wide default by configuring a customized Apache .htaccess file, which may be placed within the document root (e.g., public_html) directory or any sub-directory therein. If affecting the default PHP version for an entire cPanel account is not desired, but rather needed only for a specific script (that has its own sub-directory), please keep in mind that more fine-grained control is possible by selectively placing the custom .htaccess file in only the specific directory where your PHP script is installed; this may be useful to avoid having a legacy PHP version affect the entire account and or to allow more time for migrating from or upgrading and modernizing out-of-date PHP scripts.
For reference, here is the cPanel menu path where an end-user in can set a custom preference for which PHP version is used in their account (that will override the server-wide default): cPanel: Main >> Software/Services >> PHP Configuration
Similarly, here is where the server-wide default can be set via WebHost Manager: WHM: Main >> Service Configuration >> Apache Configuration >> PHP and SuExec Configuration
The server-wide default can be configured via command-line SSH access using the following utility:
Related Documentation: Configuring PHP and suEXEC from the Command Line
Code:
# /usr/local/cpanel/bin/rebuild_phpconf --help
Usage: /usr/local/cpanel/bin/rebuild_phpconf [--dryrun] [--no-restart] [--no-htaccess] [--current|--available] <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
<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
Command-line (CLI) Examples (of setting the server-wide default PHP version via root SSH access):- Set PHP 5 as the default, using suPHP as the request handlers for both PHP 5 and 4, with suEXEC enabled
Code:
# /usr/local/cpanel/bin/rebuild_phpconf 5 suphp suphp 1
- Set PHP 4 as the default, using suPHP as the request handlers for both PHP 5 and 4, with suEXEC enabled
Code:
# /usr/local/cpanel/bin/rebuild_phpconf 4 suphp suphp 1
When an end-user overrides the PHP version using cPanel, an Apache .htaccess file will be created in the user's home directory. The contents of this .htaccess file, as setup by cPanel, may resemble one of the following examples and will be located at a path like /home/username/.htaccess, where "username" represents the cPanel account username:
Code:
# Use PHP4 as default
AddHandler application/x-httpd-php4 .php
Code:
# Use PHP5 as default
AddHandler application/x-httpd-php5 .php
The aforementioned Apache .htaccess file will exist if the preference was customized via cPanel, and can be viewed using a number of methods, including via the cPanel File Manager, cPanel Web Disk (WebDAV), FTP, SFTP, and SSH access. The following commands may be used via command-line (SSH) access, while ensuring to replace "username" with the actual cPanel account username:
Code:
# cat -en ~username/.htaccess
# grep -Hn '' ~username/.htaccess