📒 

Changing the PHP version on your hosting environment can be necessary for various reasons, such as compatibility with certain applications, performance improvements, or security updates. This article will guide you through the process of changing the PHP version on popular hosting platforms, including cPanel and other common methods.

1. Understanding PHP Versions

PHP is regularly updated, and each version comes with new features, improvements, and security patches. However, some applications may not be compatible with newer PHP versions, making it essential to manage and switch between versions as needed.

2. Changing PHP Version via cPanel

If your hosting provider uses cPanel, follow these steps:

Step 1: Log into cPanel

  1. Open your web browser and navigate to your cPanel login URL (usually http://yourdomain.com/cpanel).
  2. Enter your username and password to log in.

Step 2: Locate the PHP Selector

  1. In the cPanel dashboard, look for the Software section.
  2. Click on Select PHP Version (or it may be labeled as PHP Config or MultiPHP Manager).

Step 3: Select the Desired PHP Version

  1. You will see a dropdown menu listing the available PHP versions.
  2. Select the desired PHP version from the dropdown menu.

Step 4: Set as Current Version

  1. After selecting the version, click on the Set as current button or equivalent to apply the changes.
  2. You may also have the option to customize PHP settings (extensions, limits, etc.) for the selected version.

Step 5: Verify the Changes

To verify that the PHP version has changed, you can create a simple PHP info file:

  1. Create a file named phpinfo.php in your web root directory with the following content:
<?php phpinfo(); ?>
  1. Navigate to http://yourdomain.com/phpinfo.php in your browser to check the current PHP version.

3. Changing PHP Version Without cPanel

If your hosting does not provide cPanel, you can change the PHP version using alternative methods:

Method 1: Using .htaccess

If your server uses Apache, you can specify the PHP version in your .htaccess file:

  1. Open or create the .htaccess file in the root directory of your website.
  2. Add the following line, replacing 7.4 with your desired PHP version:
AddHandler application/x-httpd-php74 .php

Method 2: Using the Command Line (For VPS/Dedicated Servers)

If you have access to the command line on your VPS or dedicated server, you can change the PHP version using the following commands, depending on your server’s configuration:

  1. For Ubuntu:
    sudo update-alternatives –set php /usr/bin/php7.4
  2. For CentOS: Use the Software Collections (SCL) to switch PHP versions:
    sudo scl enable php74 bash

4. Conclusion

Changing the PHP version on your hosting environment is an essential task that can help maintain compatibility, improve performance, and enhance security. By following the steps outlined in this article, you can easily manage your PHP version in cPanel or through alternative methods. Regularly review your PHP version and update your applications to ensure optimal performance and security.