15%

Save 15% on All Hosting Services

Test your skills and get Discount on any hosting plan

Use code:

Skills
Get Started
01.11.2024
1 +1

How to Change the PHP Version on Your Hosting Environment (Complete Guide)

Managing your PHP version is one of the most critical administrative tasks for any website owner or developer. Whether you're upgrading to leverage the latest performance improvements, downgrading for legacy application compatibility, or patching security vulnerabilities, knowing exactly how to switch PHP versions across different hosting environments is an essential skill. This comprehensive guide walks you through every method available β€” from cPanel's graphical interface to command-line tools on VPS Hosting and dedicated servers.

Table of Contents

  1. Why PHP Version Management Matters
  2. Understanding PHP Versions and Compatibility
  3. Method 1: Changing PHP Version via cPanel (MultiPHP Manager)
  4. Method 2: Changing PHP Version via .htaccess (Apache)
  5. Method 3: Changing PHP Version via Command Line (VPS/Dedicated Servers)
  6. Method 4: Changing PHP Version via php.ini
  7. How to Verify Your Active PHP Version
  8. Common Errors After Switching PHP Versions
  9. Best Practices for PHP Version Management
  10. Conclusion

1. Why PHP Version Management Matters {#why-it-matters}

PHP powers over 77% of all websites with a known server-side language, including major platforms like WordPress, Joomla, Drupal, and Magento. Each major PHP release introduces significant changes:

  • Performance gains: PHP 8.x is dramatically faster than PHP 5.x or 7.x, thanks to the JIT (Just-In-Time) compiler.
  • Security patches: Older PHP versions eventually reach End of Life (EOL) and no longer receive security updates, leaving your site exposed.
  • Application compatibility: Some older plugins, themes, or custom applications were written for specific PHP versions and may break on newer releases.
  • Hosting compliance: Many hosting providers enforce minimum PHP version requirements to maintain server security standards.

Failing to manage your PHP version proactively can result in broken functionality, security breaches, or outright website downtime. Understanding how to control this setting β€” regardless of your hosting type β€” is non-negotiable for any serious web administrator.

2. Understanding PHP Versions and Compatibility {#understanding-versions}

Before making any changes, it's important to understand the PHP release lifecycle and how versions are structured.

PHP Version Numbering

PHP follows a MAJOR.MINOR.PATCH versioning scheme:

ComponentExampleMeaning
Major8Significant architectural changes, possible breaking changes
Minor8.2New features, backward-compatible improvements
Patch8.2.10Bug fixes and security patches only

PHP Support Lifecycle

Each PHP minor version receives:

  • Active support for approximately 2 years (bug fixes + security patches)
  • Security-only support for an additional 1 year
  • End of Life (EOL) after which no patches are released

Currently Supported PHP Versions (as of 2024–2025)

PHP VersionStatusNotes
PHP 8.3Active SupportLatest stable release
PHP 8.2Active SupportRecommended for most applications
PHP 8.1Security OnlyStill widely used
PHP 8.0EOLAvoid β€” no security patches
PHP 7.4EOLLegacy support only
PHP 7.3 and belowEOLStrongly discouraged

> Rule of thumb: Always run the highest PHP version your application officially supports. If your CMS or framework supports PHP 8.2, there is no reason to run PHP 7.4.

3. Method 1: Changing PHP Version via cPanel (MultiPHP Manager) {#cpanel-method}

cPanel is the most widely used hosting control panel, and it provides two built-in tools for PHP version management: MultiPHP Manager (server-wide or per-domain) and MultiPHP INI Editor (for fine-tuning PHP settings). If you're using a VPS with cPanel, both tools are available to you.

Step 1: Log Into cPanel

  1. Open your browser and navigate to your cPanel login URL:
    https://yourdomain.com:2083 (secure, recommended)
    https://yourdomain.com/cpanel
  • Or the direct IP: https://your-server-ip:2083
    1. Enter your cPanel username and password.
    2. Click Log In.

    Step 2: Open MultiPHP Manager

    1. In the cPanel dashboard, scroll to the Software section.
    2. Click on MultiPHP Manager.

    > Alternative: Some cPanel setups label this as Select PHP Version, PHP Config, or PHP Selector (the latter is common with CloudLinux-based shared hosting). The interface may differ slightly, but the process is the same.

    Step 3: Select Your Domain and PHP Version

    In the MultiPHP Manager interface:

    1. You will see a list of all domains and subdomains hosted on your account.
    2. Check the checkbox next to the domain you want to modify.
    3. From the PHP Version dropdown at the top of the page, select your desired PHP version (e.g., PHP 8.2).
    4. Click Apply.

    > Important: If you're on a shared hosting account, the available PHP versions are determined by your hosting provider. If you need a version that isn't listed, contact your host's support team or consider upgrading to a VPS Hosting plan where you have full control over installed PHP versions.

    Step 4: (Optional) Customize PHP Settings via MultiPHP INI Editor

    After switching versions, you may need to adjust PHP configuration values:

    1. Return to the Software section in cPanel.
    2. Click MultiPHP INI Editor.
    3. Select your domain from the dropdown.
    4. Modify values such as:
      memory_limit (e.g., 256M)
      upload_max_filesize (e.g., 64M)
      max_execution_time (e.g., 300)
      post_max_size (e.g., 64M)
      
      
      Click Apply to save changes.
      
      Step 5: Verify the Change
      Create a test file to confirm the active PHP version (see Section 7 for full instructions).
      4. Method 2: Changing PHP Version via .htaccess (Apache) {#htaccess-method}
      If your hosting environment runs Apache but doesn't provide a graphical PHP selector, you can control the PHP version directly through your .htaccess file. This method is particularly useful on Shared Web Hosting plans where server-level access is restricted.
      How It Works
      Apache uses handlers to determine how .php files are processed. By specifying a custom handler in .htaccess, you instruct Apache to use a specific PHP version for your site.
      Step 1: Access Your .htaccess File
      You can edit .htaccess via:
      
      cPanel File Manager: Navigate to public_html, find .htaccess, right-click, and select Edit.
      FTP/SFTP client: Connect to your server and navigate to your web root (usually public_html or www).
      SSH command line: nano /home/username/public_html/.htaccess

      > Note: .htaccess is a hidden file. In your FTP client, enable "Show Hidden Files." In cPanel File Manager, check "Show Hidden Files (dotfiles)" in the top-right settings.

      Step 2: Add the PHP Handler Directive

      Add one of the following lines to your .htaccess file, depending on your server's PHP handler naming convention:

      For PHP 8.2:

      AddHandler application/x-httpd-php82 .php

      For PHP 8.1:

      AddHandler application/x-httpd-php81 .php

      For PHP 7.4 (legacy):

      AddHandler application/x-httpd-php74 .php

      Alternative syntax (used on some hosts):

      # Using suPHP or FastCGI
      Action php-cgi /cgi-bin/php82
      AddHandler php-cgi .php

      > Important: The exact handler name (x-httpd-php82, x-httpd-php81, etc.) depends on how your hosting provider has configured PHP on their servers. If the above doesn't work, check your host's documentation or contact support for the correct handler names.

      Step 3: Save and Test

      Save the .htaccess file and test your site. If you see a 500 Internal Server Error, the handler name is likely incorrect β€” remove the line and try an alternative syntax.

      5. Method 3: Changing PHP Version via Command Line (VPS/Dedicated Servers) {#cli-method}

      If you manage your own Dedicated Servers or a VPS with root access, you have complete control over PHP installation and version switching. This is the most powerful and flexible method.

      Prerequisites

      • Root or sudo access to your server
      • SSH client (Terminal on macOS/Linux, PuTTY or Windows Terminal on Windows)
      • Basic familiarity with Linux command-line operations

      Ubuntu / Debian β€” Using update-alternatives

      Ubuntu and Debian-based systems use the update-alternatives system to manage multiple PHP versions simultaneously.

      #### Step 1: Add the OndΕ™ej SurΓ½ PHP Repository

      This PPA provides multiple PHP versions for Ubuntu/Debian:

      sudo apt update
      sudo apt install -y software-properties-common
      sudo add-apt-repository ppa:ondrej/php
      sudo apt update

      #### Step 2: Install the Desired PHP Version

      # Install PHP 8.2 and common extensions
      sudo apt install -y php8.2 php8.2-cli php8.2-fpm php8.2-mysql php8.2-curl 
          php8.2-gd php8.2-mbstring php8.2-xml php8.2-zip php8.2-bcmath
      
      # Install PHP 8.1 if needed
      sudo apt install -y php8.1 php8.1-cli php8.1-fpm php8.1-mysql

      #### Step 3: Switch the Default PHP Version (CLI)

      # View all registered PHP alternatives
      sudo update-alternatives --list php
      
      # Switch to PHP 8.2
      sudo update-alternatives --set php /usr/bin/php8.2
      
      # Or use the interactive selector
      sudo update-alternatives --config php

      The interactive selector will display something like:

      There are 3 choices for the alternative php (providing /usr/bin/php).
      
        Selection    Path             Priority   Status
      ------------------------------------------------------------
      * 0            /usr/bin/php8.2   82        auto mode
        1            /usr/bin/php7.4   74        manual mode
        2            /usr/bin/php8.1   81        manual mode
        3            /usr/bin/php8.2   82        manual mode
      
      Press <enter> to keep the current choice[*], or type selection number:

      Enter the number corresponding to your desired version and press Enter.

      #### Step 4: Switch PHP Version for Apache (mod_php)

      # Disable current PHP module (e.g., PHP 8.1)
      sudo a2dismod php8.1
      
      # Enable new PHP module (e.g., PHP 8.2)
      sudo a2enmod php8.2
      
      # Restart Apache
      sudo systemctl restart apache2

      #### Step 5: Switch PHP Version for Nginx (PHP-FPM)

      For Nginx, PHP is handled via PHP-FPM. Update your Nginx server block to point to the correct FPM socket:

      # In your Nginx server block configuration
      location ~ .php$ {
          fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
          fastcgi_index index.php;
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      }

      Then restart both PHP-FPM and Nginx:

      sudo systemctl restart php8.2-fpm
      sudo systemctl restart nginx

      CentOS / RHEL / AlmaLinux / Rocky Linux β€” Using SCL or Remi Repository

      #### Option A: Using Software Collections (SCL) β€” CentOS 7

      # Install the SCL repository
      sudo yum install -y centos-release-scl
      
      # Install PHP 7.4 via SCL
      sudo yum install -y rh-php74 rh-php74-php-fpm rh-php74-php-mysqlnd
      
      # Enable PHP 7.4 for the current session
      sudo scl enable rh-php74 bash
      
      # Verify
      php --version

      > Note: SCL changes are session-specific. To make them permanent for a user, add source /opt/rh/rh-php74/enable to ~/.bashrc.

      #### Option B: Using Remi Repository β€” CentOS 7/8, AlmaLinux, Rocky Linux

      # Install EPEL and Remi repositories
      sudo dnf install -y epel-release
      sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm  # For RHEL 8/AlmaLinux 8
      
      # List available PHP streams
      sudo dnf module list php
      
      # Reset current PHP module
      sudo dnf module reset php
      
      # Enable PHP 8.2 stream
      sudo dnf module enable php:remi-8.2
      
      # Install PHP 8.2
      sudo dnf install -y php php-cli php-fpm php-mysqlnd php-gd php-mbstring php-xml php-zip
      
      # Verify
      php --version

      Switching PHP for Individual Sites (Per-Site PHP Version)

      On servers running multiple websites, you often need different PHP versions per site. The cleanest approach is to run multiple PHP-FPM pools:

      # Start PHP-FPM for multiple versions
      sudo systemctl start php7.4-fpm
      sudo systemctl start php8.1-fpm
      sudo systemctl start php8.2-fpm

      Then configure each Nginx virtual host to use a different FPM socket:

      # Site A β€” PHP 8.2
      server {
          server_name site-a.com;
          root /var/www/site-a;
          location ~ .php$ {
              fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
          }
      }
      
      # Site B β€” PHP 7.4 (legacy application)
      server {
          server_name site-b.com;
          root /var/www/site-b;
          location ~ .php$ {
              fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
          }
      }

      6. Method 4: Changing PHP Version via php.ini {#phpini-method}

      In some hosting environments, particularly those using CGI or FastCGI PHP handlers, you can influence PHP behavior β€” and sometimes even the version β€” through a custom php.ini file placed in your website's root directory.

      Creating a Custom php.ini

      1. Create a file named php.ini in your website's root directory (public_html).
      2. Add your configuration directives:
      ; Custom PHP configuration
      memory_limit = 256M
      upload_max_filesize = 64M
      post_max_size = 64M
      max_execution_time = 300
      max_input_vars = 3000
      date.timezone = "UTC"

      > Note: This method controls PHP *settings*, not necessarily the PHP *version* itself. Version selection via php.ini is only possible on specific hosting setups. For full version control, use cPanel, .htaccess, or command-line methods described above.

      7. How to Verify Your Active PHP Version {#verify}

      After making any changes, always verify that the correct PHP version is active. There are several ways to do this:

      Method A: Create a phpinfo() Test Page

      1. Create a new file named phpinfo.php in your web root directory (public_html).
      2. Add the following content:
      <?php
      phpinfo();
      ?>
      1. Navigate to https://yourdomain.com/phpinfo.php in your browser.
      2. The page will display comprehensive PHP configuration information. The PHP Version is shown at the very top.

      > Security Warning: Delete this file immediately after testing. The phpinfo() output reveals sensitive server configuration details that could aid attackers.

      Method B: Check via Command Line (SSH)

      php --version
      # or
      php -v

      Expected output:

      PHP 8.2.10 (cli) (built: Sep  5 2023 08:12:49) (NTS)
      Copyright (c) The PHP Group
      Zend Engine v4.2.10, Copyright (c) Zend Technologies
          with Zend OPcache v8.2.10, Copyright (c), by Zend Technologies

      Method C: Check via a Simple PHP Script

      For a less verbose check, use this minimal script instead of the full phpinfo():

      <?php
      echo 'PHP Version: ' . PHP_VERSION;
      echo '<br>PHP Major Version: ' . PHP_MAJOR_VERSION;
      echo '<br>PHP Minor Version: ' . PHP_MINOR_VERSION;
      ?>

      Method D: Check via WordPress Admin (for WordPress Sites)

      In your WordPress dashboard:

      1. Go to Tools β†’ Site Health.
      2. Click the Info tab.
      3. Expand the Server section.
      4. Look for PHP version.

      8. Common Errors After Switching PHP Versions {#common-errors}

      Switching PHP versions can sometimes cause issues. Here are the most common problems and how to resolve them:

      Error 1: White Screen of Death (WSOD) or Blank Page

      Cause: A plugin, theme, or custom code uses syntax or functions that are incompatible with the new PHP version.

      Solution:

      • Enable WordPress debug mode by adding to wp-config.php:
        define('WP_DEBUG', true);
        define('WP_DEBUG_LOG', true);
        define('WP_DEBUG_DISPLAY', false);
      • Check /wp-content/debug.log for specific error messages.
      • Deactivate all plugins and switch to a default theme to isolate the issue.

      Error 2: 500 Internal Server Error

      Cause: Often caused by an incorrect PHP handler in .htaccess, or a PHP extension that isn't installed for the new version.

      Solution:

      • Remove or correct the AddHandler directive in .htaccess.
      • Check your server's error log: tail -f /var/log/apache2/error.log or tail -f /var/log/nginx/error.log.
      • Ensure required PHP extensions are installed for the new version.

      Error 3: "Call to undefined function" or "Class not found"

      Cause: A PHP extension required by your application (e.g., php-gd, php-mbstring, php-xml) is not installed for the new PHP version.

      Solution:

      # Ubuntu/Debian β€” install missing extensions for PHP 8.2
      sudo apt install php8.2-gd php8.2-mbstring php8.2-xml php8.2-curl php8.2-zip
      
      # Restart web server
      sudo systemctl restart apache2  # or nginx

      Error 4: Deprecated Function Warnings

      Cause: Your code uses functions that were deprecated in older PHP versions and removed in newer ones (e.g., mysql_* functions removed in PHP 7.0).

      Solution:

      • Update your code or plugins to use modern equivalents (e.g., mysqli_* or PDO).
      • If immediate code changes aren't possible, consider staying on a compatible PHP version temporarily while you plan the upgrade.

      Error 5: PHP Version Not Changing Despite Following Steps

      Cause: Multiple PHP configurations may be in effect (e.g., CLI vs. web server), or caching is serving old responses.

      Solution:

      • Clear your browser cache and any server-side caches (OPcache, Redis, Varnish).
      • Restart your web server: sudo systemctl restart apache2 or sudo systemctl restart nginx.
      • Confirm you're editing the correct .htaccess or configuration file for the right domain.

      9. Best Practices for PHP Version Management {#best-practices}

      Follow these guidelines to maintain a healthy, secure, and performant PHP environment:

      1. Always Test in a Staging Environment First

      Never switch PHP versions directly on a live production site. Set up a staging environment β€” either a subdomain or a separate server β€” and test your application thoroughly before applying changes to production.

      2. Keep PHP Updated

      Subscribe to PHP's official security announcements and plan upgrades before your current version reaches End of Life. Running EOL PHP versions is one of the most common causes of website compromises.

      3. Audit Your Plugins and Dependencies Before Upgrading

      Before upgrading PHP, check the compatibility of:

      • All installed CMS plugins and themes
      • Composer dependencies (composer.json)
      • Custom application code

      Use tools like PHPCompatibility (a PHP_CodeSniffer ruleset) to scan your codebase for compatibility issues.

      4. Keep PHP Extensions in Sync

      When switching PHP versions, always reinstall all required extensions for the new version. A missing extension is the most common cause of post-upgrade errors.

      5. Use Version Control for Configuration Files

      Store your .htaccess, php.ini, and server configuration files in a Git repository. This makes it easy to roll back changes if something goes wrong.

      6. Monitor After Switching

      After changing PHP versions, monitor:

      • Application error logs
      • Server error logs (/var/log/apache2/error.log, /var/log/nginx/error.log)
      • Application performance metrics
      • Uptime monitoring alerts

      7. Choose the Right Hosting for PHP Flexibility

      If you find yourself constantly constrained by your hosting environment's PHP options, it may be time to upgrade. Shared Web Hosting plans offer a curated set of PHP versions managed by the provider, while VPS Hosting gives you complete freedom to install, configure, and switch any PHP version at any time. For enterprise-grade control and performance, Dedicated Servers provide the ultimate flexibility.

      10. Conclusion {#conclusion}

      Changing your PHP version is a fundamental hosting management task that directly impacts your website's security, performance, and compatibility. Whether you're using cPanel's MultiPHP Manager, editing .htaccess directives, or managing PHP installations via the command line on a VPS or dedicated server, the key principles remain the same: test before you deploy, verify after you change, and always keep your PHP version within the actively supported lifecycle.

      Here's a quick summary of the methods covered:

      MethodBest ForAccess Required
      cPanel MultiPHP ManagerShared hosting, cPanel VPScPanel login
      .htaccess directiveApache-based shared hostingFile Manager / FTP
      update-alternatives (Ubuntu/Debian)VPS, dedicated serversSSH root/sudo
      SCL / Remi repository (CentOS/RHEL)VPS, dedicated serversSSH root/sudo
      Custom php.iniCGI/FastCGI environmentsFile Manager / FTP

      If you're looking for a hosting environment that makes PHP version management straightforward and gives you the control you need, explore AlexHost's VPS Hosting plans β€” featuring full root access, multiple Linux distributions, and the flexibility to run any PHP version your applications require. You can also explore our range of VPS Control Panels to find the management interface that best suits your workflow.

      Stay proactive with your PHP updates, and your websites will remain fast, secure, and compatible for years to come.

      15%

      Save 15% on All Hosting Services

      Test your skills and get Discount on any hosting plan

      Use code:

      Skills
      Get Started