I kept seeing a notice on WordPress Site Health about PHP needing an update. On Ubuntu, it was showing 7.4 as the PHP version but not in WordPress. I’m writing this post to show the steps I took and it will be a resource I can find quickly in the future.
At root, check for updates to Ubuntu and all repositories. Choose Y when asked.
$ sudo apt-get update && apt-get upgrade
At root, check for installed program updates and it will automatically install those that need updates. Choose Y when asked.
$ sudo apt-get dist-upgrade
At root, clean up any packages not being used. Choose Y when asked.
$ sudo apt-get autoremove
At root, save a list of the currently installed PHP settings to a text file that you can look at later with
cat packages-first.txt – you will need it later to know which extensions to install for PHP 7.4.
$ sudo dpkg -l | grep php | tee packages-first.txt
Now go into your Digital Ocean account, turn off the Droplet you are going to update PHP on, create a snapshot, then turn the droplet back on.
At root, add repository for latest PHP version.
$ sudo add-apt-repository ppa:ondrej/php # Press enter when prompted. $ sudo apt-get update
At root, install the basic configuration of PHP 7.4.
$ sudo apt install php7.4 php7.4-common php7.4-cli
At root, install the extensions you need. Here are few from the article and you will need to install the extension you have in PHP 7.3 for 7.4 that you can find in packages-first.txt that you made above.
$ sudo apt install php7.4-bcmath php7.4-bz2 php7.4-curl php7.4-intl php7.4-mbstring php7.4-mysql php7.4-readline php7.4-xml php7.4-zip
At root, create a second file to see the currently installed extensions so you can compare it with the first file. You can find both of these in the root of your Droplet if you use SFTP access. Install PHP 7.4 extensions that you need.
$ sudo dpkg -l | grep php | tee packages-second.txt
At root, for web server integration with Apache.
$ sudo apt install php7.4-fpm $ sudo a2enconf php7.4-fpm # For Apache only
At root, remove all versions of PHP except for the most recent version 7.3. I kept it while going through these steps as a safety blanket until I was sure that I had installed PHP 7.4 extensions of all the PHP 7.3 extensions found in packages-first.txt. I removed 7.0, 7.1, and 7.2. Add the names of the extensions for each older PHP version that are still installed to purge them too, found in packages-second.txt. You don’t want to purge the file names without a number as those are part of the server.
$ sudo apt purge php7.0 php7.0-common # Change 7.0 with all versions you want to purge.
At root, to disable PHP 7.3 and enable PHP 7.4 so that WordPress will see the correct version. Even if
php -v at root would show the latest version, WordPress would not. The bottom answer from this website helped me here.
$ sudo a2dismod php7.3 $ sudo a2enmod php7.4 $ sudo systemctl restart apache2
I used these articles as reference: