To install different PHP versions in Ubuntu, you can use the ondrej/php PPA (Personal Package Archive), which provides the latest PHP versions for Ubuntu. Here are the steps:
- Add the ondrej/php PPA to your system:
bash
sudo add-apt-repository ppa:ondrej/php
- Update the package lists:
sql
sudo apt-get update
- Install the PHP version you need, e.g. PHP 7.4:
arduino
sudo apt-get install php7.4
- Check if the installation was successful by running the following command:
php -v
This should output the version of PHP you just installed.
- To switch between PHP versions, you can use the update-alternatives command. For example, to switch to PHP 7.4, run:
bash
sudo update-alternatives --set php /usr/bin/php7.4
And to switch back to the default PHP version, run:
sql
sudo update-alternatives --auto php
That’s it! You now have multiple PHP versions installed on your Ubuntu system.