How To Install Multiple PHP Versions On Ubuntu

Managing multiple PHP versions on Ubuntu is essential for developers working with different applications requiring specific PHP versions. By setting up multiple PHP versions, you can easily switch between them without conflicts. This guide will show you How To Install Multiple PHP Versions On Ubuntu.

Steps To Install Multiple PHP Versions On Ubuntu

Step 1: Add the Required Repository

Ubuntu does not provide multiple PHP versions by default. You need to add the Ondřej Surý PPA, which maintains up-to-date PHP packages:

sudo add-apt-repository ppa:ondrej/php
sudo apt update

Step 2: Install Multiple PHP Versions

To install specific PHP versions, use the following commands:

sudo apt install php<--php-version-->

Replace the versions with the ones you need.

For example:

sudo apt install php8.1 php8.3

Configure PHP Version Switching

To switch between installed PHP versions, use the update-alternatives command:

sudo update-alternatives --set php /usr/bin/php8.3

Alternatively, use:

sudo update-alternatives --config php

This command will prompt you to select the desired PHP version.

If using Apache, enable the required PHP module:

sudo a2dismod php8.1
sudo a2enmod php8.3
sudo systemctl restart apache2

For Nginx, update your server block to point to the correct PHP version.

Check your default PHP versions with command:

php -v

If you don’t want to waste time setting default PHP Version, you can use the form below to run the command:

php<--php-version--> <--your-command-->

For example:

php8.3 -v
Run Multiple PHP Versions On Ubuntu

Conclusion

Installing and managing multiple PHP versions on Ubuntu allows greater flexibility in development environments. By following these steps, you can seamlessly switch between different PHP versions and ensure compatibility with various applications.

This is the end of the How To Install Multiple PHP Versions On Ubuntu.

Follow us for the more helpful posts!

We hope this is a useful post for you.

You can read more useful posts like How To Set Automatic Backup In Magento 2.

Thank you for reading!

 

4.8 5 votes
Article Rating

Aaron LX

Aaron is a passionate writer, crazy about shopping, eCommerce and trends. Besides his outstanding research skills and a positive mind, Aaron eagerly shares his experience with the readers.

Leave a Reply or put your Question here

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x