xxxxxxxxxx
There are two methods to switch php versions on the command line ubuntu.
Run each command one by one and input the number of the php version you want to change.
**Method 1**
sudo update-alternatives --config php
sudo update-alternatives --config phar
sudo update-alternatives --config phar.phar
sudo service apache2 restart
**Method 2**
If you want to change PHP 5.6 to 7.4 just run the below codes.
sudo a2dismod php5.6
sudo a2enmod php7.4
sudo service apache2 restart
If you want to change from PHP 7.4 to 5.6 run the below codes.
sudo a2dismod php7.4
sudo a2enmod php5.6
sudo service apache2 restart
For more information follow this link https://slaford.com/laravel/how-to-switch-php-versions-on-command-line-ubuntu/
xxxxxxxxxx
Interactive switching mode
sudo update-alternatives --config php
sudo update-alternatives --config phar
sudo update-alternatives --config phar.phar
Manual Switching
From PHP 5.6 => PHP 7.1
Default PHP 5.6 is set on your system and you need to switch to PHP 7.1.
Apache:
$ sudo a2dismod php5.6
$ sudo a2enmod php7.1
$ sudo service apache2 restart
Command Line:
$ sudo update-alternatives --set php /usr/bin/php7.1
$ sudo update-alternatives --set phar /usr/bin/phar7.1
$ sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.1
From PHP 7.1 => PHP 5.6
Default PHP 7.1 is set on your system and you need to switch to PHP 5.6.
Apache:
$ sudo a2dismod php7.1
$ sudo a2enmod php5.6
$ sudo service apache2 restart
Command Line:
$ sudo update-alternatives --set php /usr/bin/php5.6
xxxxxxxxxx
sudo update-alternatives --config php
sudo update-alternatives --config phar
sudo update-alternatives --config phar.phar
xxxxxxxxxx
sudo update-alternatives --set php /usr/bin/php7.2
sudo update-alternatives --set phar /usr/bin/phar7.2
sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.2
sudo update-alternatives --set phpize /usr/bin/phpize7.2
sudo update-alternatives --set php-config /usr/bin/php-config7.2
xxxxxxxxxx
# 1. Create file .bash_profile in the root
# 2. Paste the followinng line to it:
# Plesk
export PATH=/opt/alt/php83/usr/bin:$PATH
# Direct Admin
export PATH=/usr/local/php83/bin:$PATH
# 3. Run the following command to update the file
. ~/.bash_profile
xxxxxxxxxx
sudo apt-add-repository ppa:ondrej/php
sudo apt update
//then
sudo apt install -y php8.0 php8.0-cli php8.0-common
xxxxxxxxxx
vim ~/.bashrc
alias phpchange=change_php
change_php(){
CURRENT_PHP_VERSION=$(php -v | head -n 1 | cut -d " " -f 2 | cut -f1-2 -d"." 2>/dev/null)
echo "Current PHP Version is ".$CURRENT_PHP_VERSION;
sudo a2dismod php$CURRENT_PHP_VERSION;
sudo a2enmod php$1;
sudo update-alternatives --set php /usr/bin/php$1
sudo service apache2 restart
}
and then run phpchange 7.0 // to switch to 7
make sure you need to have that version installed
xxxxxxxxxx
PHP UPGRADE (7.2 TO 8.2)
sudo add-apt-repository ppa:ondrej/php && sudo apt update
//or sudo apt-add-repository ppa:ondrej-ubuntu-php && sudo apt update
sudo apt update
sudo apt install php8.2 php8.2-cli php8.2-common php8.2-curl php8.2-gd php8.2-intl php8.2-mbstring php8.2-mysql php8.2-opcache php8.2-readline php8.2-xml php8.2-zip
a2dismod php7.2 #Disable php7.2
a2enmod php8.2 #Enable php8.2
sudo service apache2 restart
sudo update-alternatives --config php #switch php terminal
sudo service apache2 restart