HostGator Web Hosting Help

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

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. If you do not wish to edit the .htaccess file you can use the cPanel to change your php version as explained in PHP Config.



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 the purposes of this article, we will explain accessing it through the File Manager on the cPanel of your hosting account.

Rock

  1. Log in to your HostGator.sg  account.
  2. Click the Advanced tab from the side navigation menu to the left.
  3. Under the File section, click the File Manager icon.
  4. Look for the Settings button located towards the upper right corner of your screen.
  5. Click the Preferences, then toggle the radio button for "Show Hidden Files (dotfiles)."
  6. Click the Save button when finished.
  7. Locate the .htaccess file, right-click on it, and select edit.
  8. 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.
  9. Click Save.

Legacy

  1. Open the File Manager located on the cPanel.
  2. Choose Web Root, select Show Hidden Files, and click the submit button on the directory selection popup.
  3. In the table of files, you should see a file named .htaccess, right-click on it and select the code edit.
  4. You may get a popup asking about encoding. If so, click the edit button.
  5. 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.

    Note: See the Available PHP Handlers section for handlers on each PHP version available. You can copy and paste these directly into the file.

  6. Click Save.

Once you have saved the file, you can close it. Your account will then use the PHP version you selected.

Available PHP Handlers

Please note: We will be updating to PHP version 8.0 in batches beginning in 2022. Keep an eye out for communications on when your account will be updated and what changes, if any, you will need to make. For more information on updating content for PHP compatibility, read our guide on What to do if your Site Does not Work with Newer Versions of PHP. To learn more about what is changing with PHP 8.0, please see PHP.net's release notes.

The following handlers can be copied and pasted directly into your .htaccess file:

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(7.3|7.4|8.0|8.1) as default
            AddHandler application/x-httpd-php(73|74|80|81) .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(7.3|7.4|8.0|8.1) Single php.ini as default
            AddHandler application/x-httpd-php(73|74|80|74)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(73|74|80|81)CGI as default
            AddHandler fcgid(73|74|80|81)-script .php


Was this resource helpful?

Did this resolve your issue?


Please add any other comments or suggestions about this content:





Recommended Help Content

What are Apache Handlers? How do I setup customized Apache Handlers?
Knowledgebase Article 177,373 views tags: apache handler handlers

How to change your PHP version in your hosting account
Knowledgebase Article 836,842 views tags: config php selection version

There are many ways that you can transfer files and folder to and from your hosting account. We highly recommend using an FTP (File Transfer Protocol) program to quickly upload and download files. We
Getting Started Article 280,289 views tags: file files filezilla manager setup

Related Help Content

The redirection of www.yourdomain.com/default.html or index.html to http://www.yourdomain.com/index.php?act=whatever redirects it to http://www.yourdomain.com/index.php%3fact=whatever In other words,
Knowledgebase Article 972,673 views tags: htaccess messing mod php redirect redirects rewrite variable variables

How do I change the PHP environment for my site with php.ini?
Knowledgebase Article 751,587 views tags: configuration ini php server

500 Internal Server Error when installing via the MOJO Marketplace installer.
Knowledgebase Article 236,471 views tags: cpanel errors htaccess panel php script simpel

Executing php code within a HTML document
Knowledgebase Article 210,748 views tags: addhandler addtype handler mime parse php sethandler

Explains how to edit the .htaccess
Knowledgebase Article 312,978 views tags: htaccess

How to customize your html or php error pages.
Knowledgebase Article 143,273 views tags: errors php

Many popular website platforms use PHP for rendering their content. It’s common for these sites to have automatic update tools to ensure that they work with the latest version of PHP, however sometimes a theme or plugin for these services may prevent them from updating or may not work with a newer
Knowledgebase Article 108,178 views tags: deprecation discontinue end php upgrade

This article will explain how to change or reset the password for a MySQL user.
Knowledgebase Article 112,803 views tags: change mysql password reset user