know-how.dev

How to change PHP version in Ubuntu

3 years ago 763

For example, you want to change PHP version from 7.4 to 8.0, steps will be:

  1. Update defaults for CLI:
sudo update-alternatives --set php /usr/bin/php8.0
sudo update-alternatives --set phar /usr/bin/phar8.0
sudo update-alternatives --set phar.phar /usr/bin/phar.phar8.0
sudo update-alternatives --set phpize /usr/bin/phpize8.0
sudo update-alternatives --set php-config /usr/bin/php-config8.0
  1. If you use Apache:
sudo a2dismod php7.4
sudo a2enmod php8.0
sudo service apache2 restart
  1. If you use Nginx:
location ~ \.php$ {
    fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
    ...
}