How to change PHP version on shared servers

ByJUJU-dev

How to change PHP version on shared servers

Changing PHP version on a shared server can be a bit tricky, but it’s doable. Here’s a step-by-step guide to help you through the process:

Before you begin:

  1. Check if you have access: Make sure you have the necessary permissions and access to modify the server configuration.
  2. Check the hosting provider’s documentation: Familiarize yourself with your hosting provider’s documentation on how to change PHP versions.

Method 1: Using cPanel (if available)

  1. Log in to your cPanel account.
  2. Click on the “Software” section and select “MultiPHP Manager”.
  3. Click on the “Select PHP Version” dropdown menu and choose the desired PHP version from the list.
  4. Click “Update” to apply the changes.
  5. Restart your website or reload the page to ensure the changes take effect.

Method 2: Using .htaccess file (if cPanel is not available)

  1. Log in to your file manager (e.g., FileZilla) and navigate to your website’s root directory.
  2. Open the .htaccess file and add the following lines at the end:
<IfModule mod_php7.c>
    PHPIniDir /path/to/php.ini
</IfModule>

<IfModule mod_php8.c>
    PHPIniDir /path/to/php8.ini
</IfModule>

Replace /path/to/php.ini and /path/to/php8.ini with the actual paths to your PHP configuration files.

Method 3: Using SSH (if you have SSH access)

  1. Connect to your server using SSH.
  2. Navigate to your website’s root directory using the command cd /path/to/website.
  3. Create a new file called php.conf with the following contents:
<?php
php_flag[display_errors] = On
php_value[error_reporting] = E_ALL
?>

This sets PHP’s error reporting level to E_ALL and displays errors. 4. Save the file and then update the Apache configuration by running:

sudo /usr/local/apache/bin/apachectl restart

This restarts Apache and applies the changes.

Verify PHP version

To verify that you have successfully changed the PHP version, you can use one of the following methods:

  1. Check your website’s phpinfo() function: Create a new file with a .php extension (e.g., info.php) and add the following code:
<?php phpinfo(); ?>

Open this file in a web browser to see the PHP information, including the version. 2. Check your hosting provider’s control panel: If you’re using a control panel like cPanel, you can check the PHP version from there.

Remember to always test your website after changing PHP versions to ensure everything is working as expected.

Keep in mind that changing PHP versions can affect your website’s functionality, so be cautious when making these changes, especially if you’re not familiar with PHP or have a complex setup.

About the author

JUJU-dev administrator

Leave a Reply

five × 4 =