Knowledgebase

How To Add Handlers To Change PHP Version - PHP Version Setup Print

  • 0

Overview

This article will explain 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.



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 webserver. The web server follows any instructions contained within the file. There are many ways to access this file. For the purposes of this article, we will explain accessing it through the File Manager on the cPanel of your hosting account.

Account Manager

  1. Log in to your account.
  2. Click the Hosting tab from the side navigation.
    am-hosting-tab
  3. In the Quick Links section, click on File Manager.
    am-file-manager-v2
  4. Search for the Settings button in your screen's upper right corner.
    cpanel-settings
  5. The Preferences window will appear on your screen. Switch on the radio button for Show Hidden Files (dotfiles). Once you're done, click Save.
    cpanel-show-hidden-folders
  6. Find the .htaccess file in the list of files, right-click on it, and choose the Edit option.
    cpanel-show-hidden-folders
  7. At the top of the file, add the PHP handler corresponding to the version you desire to use. If there's an existing handler in the file, remove it or substitute it with your preferred handler.
Below are the available PHP handlers:
  • 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
    
  1. Click Save.

PHP Standard PHP (Default)

All accounts use Standard PHP by default. You can install the default php.ini file to your public_html folder using the PHP Config option inside your cPanel. You can make any changes or modifications to that file and take a guide over the master file. The Standard PHP on the cPanel will need to copy the modified php.ini file into all subdirectories, including PHP files, to use the custom PHP settings.

# Use PHP(8.1|8.2|8.3) as default 
AddHandler application/x-httpd-php(74|80|81|82) .php 

PHP Single php.ini

The Single php.ini will help you avoid copying the same php.ini file to each directory containing php files. This option changes the PHP handler defined in ~/public_html/.htaccess to indicate that all subfolders use the same php.ini found in public_html/.

# Use PHP(8.1|8.2|8.3) Single php.ini as default 
AddHandler application/x-httpd-php (81|82|83)s .php 

Important Note: The .htaccess PHP handler is looping through all subdirectories unless a subdirectory has a .htaccess file and defines a PHP handler.

PHP FastCGI

The FastCGI for PHP makes all your PHP applications tenacious and uses only one php.ini file in the public_html directory. Also, there is no per-request startup and initialization indirect cost. 
This PHP makes possible the development of applications that would otherwise be ineffective within the CGI paradigm (e.g., a huge PHP script or an application that requires a connection to one or more databases). Using the PHP FastCGI option makes all your PHP applications run through mod_fcgid instead of mod_suphp.

# Use PHP(81|82|83)CGI as default 
AddHandler fcgid(81|82|83)-script .php 

If you need further assistance, feel free to contact us via Chat or Phone:

  • Chat Support - While on our website, you should see a CHAT bubble in the bottom right-hand corner of the page. Click anywhere on the bubble to begin a chat session.
  • Phone Support -
    • US: 210-488-5907
    • International: 210-488-5907

You may also refer to our Knowledge Base articles to help answer common questions and guide you through various setup, configuration, and troubleshooting steps.


Was this answer helpful?
Back

Powered by WHMCompleteSolution