Best way to switch php version in ubuntu

Created at 17-Oct-2024 , By samar

In this post, we’ll look at how to solve the "Best way to switch php version in ubuntu" programming puzzle.

There are many ways to switch the php versions in ubuntu. But i am going to share the best way to switch from one php version to another php version in ubuntu system.

1. First open the new terminal on your ubuntu system.

2. Paste below command in your ubuntu terminal to see all the available php versions and to switch php version from one to another.

sudo update-alternatives --config php

Now You may be asked for password. You have to enter the password to see the list of all php versions and you can also pass the selection number infront of the php version to switch for specific php version you want to use.

You can also hit the enter button to select the current php version in case if you don't want to switch to another version.

This is how you can switch one php version to another php version in ubuntu system.

Now you can run php -v command in your ubuntu terminal to check the current php version.

  • Switch php version form php8.1 to php8.2

    First, disable the currently enabled PHP version Apache module. Lets i am working on php8.1 and now i want to switch to php8.2 so first we have to disable the php8.1 version and enable the php8.2 and restart the apache2 server.

    To switch from one version to another php version you have to install the Apache modules for PHP 8.1 and PHP 8.2 using sudo apt install libapache2-mod-php8.1 libapache2-mod-php8.2 command. This command installs the Apache modules for PHP 8.1 and PHP 8.2, which allow Apache to interpret PHP code using the respective PHP versions.

    Disable php8.1 first

    sudo a2dismod php8.1
    

    Enable php8.2

    sudo a2enmod php8.2
    

    Restart apache2 server

    sudo systemctl restart apache2
    

Back to code snippet queries related cmd

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.