For some reason, i have to install PHP 7.4 and PHP 8.0 in the same ubuntu server. By default when i install php 7.4, it shows it is the default version when use the command php -v
.
But i want to run composer using PHP 8.0 now to install one of my application in the server. Server cant find any php version now, so i cant install my application using composer.
How did i install PHP 8.0
I have used sudo add-apt-repository ppa:ondrej/php
this repository to install latest version of 8.0 in the server, I can make it work with caddy server and even site is running fine in my testing environment. https://caddyt.tamilchatz.com
<< you can check out this URL to make sure my 8.0 is running fine in server.
Anyway i have removed PHP 7.4 from server to make sure does it help me to set 8.0 as default one, but no i can’t get it to work.
php --version
Help me out to set PHP 8.0 as default version in server now. Thanks.
2
Answers
Try this:
To update CLI version:
sudo update-alternatives --config php
should work for all ubuntu versions after 16.04 (18.04 and 20.04)
This is what you should see as a response:
There are 4 choices for the alternative php (providing /usr/bin/php).
Press to keep the current choice[*], or type selection number and press enter to change version:
To Update version in server/browser output (you can use for all version just change version number as per requirement):
DOWNGRADE PHP 8.0 to PHP 7.4
UPGRADE PHP 7.4 to PHP 8.0