skip to Main Content

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

enter image description here

Help me out to set PHP 8.0 as default version in server now. Thanks.

2

Answers


  1. Try this:

    sudo update-alternatives --set php /usr/bin/php7.4
    
    Login or Signup to reply.
  2. 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).

      Selection    Path             Priority   Status
    ------------------------------------------------------------
    * 0            /usr/bin/php7.2   72        auto mode
      1            /usr/bin/php5.6   56        manual mode
      2            /usr/bin/php7.0   70        manual mode
      3            /usr/bin/php7.1   71        manual mode
      4            /usr/bin/php7.2   72        manual mode
    

    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

    sudo a2dismod php8.0
    sudo a2enmod php7.4
    sudo service apache2 restart
    sudo update-alternatives --config php
    sudo update-alternatives --config phar
    sudo update-alternatives --config phar.phar
    sudo service apache2 restart
    

    UPGRADE PHP 7.4 to PHP 8.0

    sudo a2dismod php7.4
    sudo a2enmod php8.0
    sudo service apache2 restart
    sudo update-alternatives --config php
    sudo update-alternatives --config phar
    sudo update-alternatives --config phar.phar
    sudo service apache2 restart
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search