Table of Contents
Upgrading PHP on my GCP VM was a pretty frustrating ordeal, so it’s probably a good idea to note some of the resources I used.
Updating PHP #
There are several steps to updating PHP. First, make sure the system is updated:
sudo apt update sudo apt upgrade -y && sudo reboot
Next, make sure the SURY PHP PPA repository is added:
sudo apt -y install lsb-release apt-transport-https ca-certificates sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
Finally, install PHP.
sudo apt update
sudo apt -y install php7.4
# Install any additional packages
sudo apt-get install php7.4-{bcmath,bz2,intl,gd,mbstring,mysql,zip}
Setting PHP Version for Apache #
To get Apache to load the correct version of PHP, you’ll need to enable its module and disable any previous. In general, that works like this:
# Disable modules sudo a2dismod php5.6 php7.1 php7.0 # Enable module sudo a2enmod php7.2 # Restart Apache sudo service apache2 restart