Posted By Shahid Malla

How to Change Default PHP Version on Ubuntu - Shahid Malla - WHMCS Expert Freelancer

On Ubuntu, you can have multiple versions of PHP installed, and you can switch between them as needed. Here are the general steps to change the default PHP version:

  1. List Installed PHP Versions:
    You can use the following command to see the installed PHP versions:
   sudo update-alternatives --config php

This command will display a list of installed PHP versions along with a selection prompt.

  1. Select the Desired PHP Version:
    From the list of installed PHP versions, choose the number corresponding to the version you want to set as the default. Enter the number and press Enter.
  2. Verify the Change:
    After selecting the PHP version, you can verify the change by running:
   php -v

This will display the currently active PHP version.

  1. Update Apache or Nginx Configuration (if applicable):
    If you are using Apache or Nginx as your web server, you may need to update their configurations to use the newly selected PHP version. Restart the web server after making changes. For Apache, you can use:
   sudo service apache2 restart

For Nginx:

   sudo service nginx restart

That’s it! You have successfully changed the default PHP version on your Ubuntu system. Keep in mind that the specific commands and steps may vary slightly depending on your Ubuntu version and the way PHP was installed on your system. If you installed PHP using a package manager like apt, the above steps should work. If you used a different method, adjust the steps accordingly.

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x