Categories
Knowledge Base Server Administration

How to Update PHP Version in a LAMP Stack

This article covers:

  1. Update PHP in a Lamp Stack
  2. Switch PHP version

Audiences of this article:

  • Server Admin

Install The Latest PHP (7.4 in this case)

sudo apt-get install software-properties-common 
sudo add-apt-repository ppa:ondrej/php 
sudo apt-get update 
sudo apt-get install -y php7.4
sudo apt install php7.4-common php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-curl php7.4-gd php7.4-imagick php7.4-cli php7.4-dev php7.4-imap php7.4-mbstring php7.4-opcache php7.4-soap php7.4-zip php7.4-intl -y

Disable old PHP version 7.1 and Enable New version 7.4, then restart Apache and check PHP version

sudo a2dismod php7.0 
sudo a2enmod php7.4
sudo service apache2 restart
php -v

If your PHP version does NOT change, it’s likely you have switched PHP version earlier, you’ll need to switch PHP version manually like so:

sudo update-alternatives --set php /usr/bin/php7.4

By Ethan

To many, a business is a lifetime commitment. It's easy to start one yet difficult to make it successful. Attitude, skills, experiences and dedication help hone the craft along the way, but it's often the great vision and resilience to remain focused wins the game. Read more about me here