How to install Multiple PHP version in Linux and switch between them?
There can be 2 scenarios here.
1) You are installing it for the very first time.
2) You already had PHP installed and want to install more.
Whatever the scenario just follow the steps below:-
Step 1)
Open your Terminal.
Step 2)
sudo apt-get install software-properties-common -y
Step 3)
sudo add-apt-repository ppa:ondrej/php
Step 4)
sudo apt-get update -y
Step 5)
sudo apt-get install php7.2 php7.2-fpm php7.2-mysql libapache2-mod-php7.2 -y
Step 6)
sudo apt-get install php7.4 php7.4-fpm php7.4-mysql libapache2-mod-php7.4 -y
Step 7)
sudo apt-get install php8.2 php8.2-fpm php8.2-mysql libapache2-mod-php8.2 -y
Step 8)
update-alternatives --config php
With this command, you would be able to change PHP version. If this doesn't work then goto step 9.
Step 9)
sudo a2dismod php7.4
sudo a2enmod php8.2
sudo service apache2 restart
This will switch the PHP version from 7.4 to 8.2
No comments