How To Add Handlers To Change PHP Version in cPanel – Setup PHP Version
Learn how to add a PHP handler to your .htaccess files. This is useful if you want to customize the version of PHP that runs your PHP files by directly editing your .htaccess file. As explained in PHP Config, if you do not wish to edit the .htaccess file, you can use the cPanel to change your PHP version. (This may be necessary on servers that doesn’t not have multi PHP manager option)
Adding the Handler to the .htaccess File
The PHP handler is written into the .htaccess file. The .htaccess file is a hidden file that is read by the web server. The web server follows any instructions contained within the file. There are many ways to access this file. For this article, we will explain accessing it through the File Manager option on the cPanel of your hosting account.
- Login to cPanel.
- Under the File section, click the File Manager icon.
- Look for the Settings button located towards the upper right corner of your screen.
- Click the Preferences, then toggle the radio button for “Show Hidden Files (dotfiles).”
- Click the Save button when finished.
- Locate the .htaccess file, right-click on it, and select edit.
- At the top of the file, insert the PHP handler for the version you would like to use. If there is a handler in the file already, it should be removed or replaced with your new handler.
For EasyApache EA Handler Configuration
PHP 5.4
#php – BEGIN cPanel-generated handler, do not edit #Set the “ea-php54” package as the default “PHP” programming language. <IfModule mime_module> AddHandler application/x-httpd-ea-php54___lsphp .php .php5 .phtml </IfModule> #php – END cPanel-generated handler, do not edit
PHP 5.5
#php – BEGIN cPanel-generated handler, do not edit #Set the “ea-php55” package as the default “PHP” programming language. <IfModule mime_module> AddHandler application/x-httpd-ea-php55___lsphp .php .php5 .phtml </IfModule> #php – END cPanel-generated handler, do not edit
PHP 5.6
#php – BEGIN cPanel-generated handler, do not edit #Set the “ea-php56” package as the default “PHP” programming language. <IfModule mime_module> AddHandler application/x-httpd-ea-php56___lsphp .php .php5 .phtml </IfModule> #php – END cPanel-generated handler, do not edit
PHP 7.0
#php – BEGIN cPanel-generated handler, do not edit #Set the “ea-php70” package as the default “PHP” programming language. <IfModule mime_module> AddHandler application/x-httpd-ea-php70___lsphp .php .php7 .phtml </IfModule> #php – END cPanel-generated handler, do not edit
PHP 7.1
#php – BEGIN cPanel-generated handler, do not edit #Set the “ea-php71” package as the default “PHP” programming language. <IfModule mime_module> AddHandler application/x-httpd-ea-php71___lsphp .php .php7 .phtml </IfModule> #php – END cPanel-generated handler, do not edit
PHP 7.2
#php – BEGIN cPanel-generated handler, do not edit #Set the “ea-php72” package as the default “PHP” programming language. <IfModule mime_module> AddHandler application/x-httpd-ea-php72___lsphp .php .php7 .phtml </IfModule> #php – END cPanel-generated handler, do not edit
PHP 7.3
#php – BEGIN cPanel-generated handler, do not edit #Set the “ea-php73” package as the default “PHP” programming language. <IfModule mime_module> AddHandler application/x-httpd-ea-php73___lsphp .php .php7 .phtml </IfModule> #php – END cPanel-generated handler, do not edit
PHP 7.4
#php – BEGIN cPanel-generated handler, do not edit #Set the “ea-php74” package as the default “PHP” programming language. <IfModule mime_module> AddHandler application/x-httpd-ea-php74___lsphp .php .php7 .phtml </IfModule> #php – END cPanel-generated handler, do not edit
PHP 8.0
#php – BEGIN cPanel-generated handler, do not edit #Set the “ea-php80” package as the default “PHP” programming language. <IfModule mime_module> AddHandler application/x-httpd-ea-php80___lsphp .php .php8 .phtml </IfModule> #php – END cPanel-generated handler, do not edit
PHP 8.1
php – BEGIN cPanel-generated handler, do not edit Set the “ea-php81” package as the default “PHP” programming language. <IfModule mime_module> AddHandler application/x-httpd-ea-php81___lsphp .php .php8 .phtml </IfModule> php – END cPanel-generated handler, do not edit
- PHP 8.2
php – BEGIN cPanel-generated handler, do not edit Set the “ea-php82” package as the default “PHP” programming language. <IfModule mime_module> AddHandler application/x-httpd-ea-php82___lsphp .php .php8 .phtml </IfModule> php – END cPanel-generated handler, do not edit
PHP 8.3
php – BEGIN cPanel-generated handler, do not edit Set the “ea-php83” package as the default “PHP” programming language. <IfModule mime_module> AddHandler application/x-httpd-ea-php83___lsphp .php .php8 .phtml </IfModule> php – END cPanel-generated handler, do not edit
Click Save.
For Cloudlinux ALT-PHP Handler Configuration
PHP 5.4
# BEGIN CloudLinux ALT-PHP handler, do not edit # Set the “alt-php54” package as the default “PHP” programming language. <IfModule mime_module> AddHandler application/x-httpd-alt-php54 .php .php5 .phtml </IfModule> # END CloudLinux ALT-PHP handler, do not edit
PHP 5.5
# BEGIN CloudLinux ALT-PHP handler, do not edit # Set the “alt-php55” package as the default “PHP” programming language. <IfModule mime_module> AddHandler application/x-httpd-alt-php55 .php .php5 .phtml </IfModule> # END CloudLinux ALT-PHP handler, do not edit
PHP 5.6
# BEGIN CloudLinux ALT-PHP handler, do not edit # Set the “alt-php56” package as the default “PHP” programming language. <IfModule mime_module> AddHandler application/x-httpd-alt-php56 .php .php5 .phtml </IfModule> # END CloudLinux ALT-PHP handler, do not edit
PHP 7.0
# BEGIN CloudLinux ALT-PHP handler, do not edit # Set the “alt-php70” package as the default “PHP” programming language. <IfModule mime_module> AddHandler application/x-httpd-alt-php70 .php .php7 .phtml </IfModule> # END CloudLinux ALT-PHP handler, do not edit
PHP 7.1
# BEGIN CloudLinux ALT-PHP handler, do not edit # Set the “alt-php71” package as the default “PHP” programming language. <IfModule mime_module> AddHandler application/x-httpd-alt-php71 .php .php7 .phtml </IfModule> # END CloudLinux ALT-PHP handler, do not edit
PHP 7.2
# BEGIN CloudLinux ALT-PHP handler, do not edit # Set the “alt-php72” package as the default “PHP” programming language. <IfModule mime_module> AddHandler application/x-httpd-alt-php72 .php .php7 .phtml </IfModule> # END CloudLinux ALT-PHP handler, do not edit
PHP 7.3
# BEGIN CloudLinux ALT-PHP handler, do not edit # Set the “alt-php73” package as the default “PHP” programming language. <IfModule mime_module> AddHandler application/x-httpd-alt-php73 .php .php7 .phtml </IfModule> # END CloudLinux ALT-PHP handler, do not edit
PHP 7.4
# BEGIN CloudLinux ALT-PHP handler, do not edit # Set the “alt-php74” package as the default “PHP” programming language. <IfModule mime_module> AddHandler application/x-httpd-alt-php74 .php .php7 .phtml </IfModule> # END CloudLinux ALT-PHP handler, do not edit
PHP 8.0
# BEGIN CloudLinux ALT-PHP handler, do not edit # Set the “alt-php80” package as the default “PHP” programming language. <IfModule mime_module> AddHandler application/x-httpd-alt-php80 .php .php8 .phtml </IfModule> # END CloudLinux ALT-PHP handler, do not edit
PHP 8.1
# BEGIN CloudLinux ALT-PHP handler, do not edit # Set the “alt-php81” package as the default “PHP” programming language. <IfModule mime_module> AddHandler application/x-httpd-alt-php81 .php .php8 .phtml </IfModule> # END CloudLinux ALT-PHP handler, do not edit
- PHP 8.2
# BEGIN CloudLinux ALT-PHP handler, do not edit # Set the “alt-php82” package as the default “PHP” programming language. <IfModule mime_module> AddHandler application/x-httpd-alt-php82 .php .php8 .phtml </IfModule> # END CloudLinux ALT-PHP handler, do not edit
PHP 8.3
# BEGIN CloudLinux ALT-PHP handler, do not edit # Set the “alt-php83” package as the default “PHP” programming language. <IfModule mime_module> AddHandler application/x-httpd-alt-php83 .php .php8 .phtml </IfModule> # END CloudLinux ALT-PHP handler, do not edit
Click Save.