By jplafata
Hi all,
I host 2 WordPress sites using Apache(httpd) on my droplet and am getting the nagging message to upgrade my version of PHP. I’ve found some tutorials and article on installing PHP, but nothing regarding upgrading from one version of PHP to another, and nothing particularly for CentOS 8. Can anyone give me some pointers or offer any advice on how to safely upgrade from PHP 7.2 to 7.4?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Accepted Answer
Hi @jplafata,
In order to upgrade from one PHP version to another just need to install it. There is no actual upgrade process like upgrading from Ubuntu 16 to 18. You just install your new PHP version and make that the default one.
Anyway, let’s see how to install PHP 7.4
To get started, you need to add EPEL & Remi repository from where you will be able to install PHP 7.4 on CentOS 8 Linux.
dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
Next once you have the EPEL repository, run:
dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
Upon successful addition of EPEL and Remi repositories, execute the command below to get a list of available PHP module streams.
dnf module list php
You should see an output of PHP version. The one we care about is remi-7.4, the latest PHP stream, To enable the module stream run the following :
dnf module enable php:remi-7.4
Once the PHP remi-7.4 module has been enabled, you can then proceed and install PHP
dnf install php php-cli php-common
Regards, KFSys
This was super helpful to upgrade a CENTOS 8 machine from PHP 7.2 to 7.4. I turned it into a quick script to automate it and to make sure you install all of the PHP 7.2 modules you had previously.
Enjoy
#!/usr/bin/bash
#This script upgrades CENTOS 8 from PHP 7.2 to 7.4
#-----------------------------------------
if [ `whoami` != "root" ];
then
echo "Sorry, gotta be root!"
exit 0
fi
echo "This script will upgrade PHP 7.2 to 7.4 on Centos 8"
echo ""
echo "Press CTRL-C to stop, or any key to continue"
read ans
if [[ `cat /etc/centos-release | grep 'CentOS Linux release 8.'` ]];
then
echo "You are on Centos 8, proceeding."
else
echo "Not on Centos 8. Sorry, exiting."
exit 1
fi
echo "These are your current PHP modules installed. Saving to /tmp/php-7.2.modules.txt"
echo ""
rpm -qa | grep php | tee -a /tmp/php-7.2.modules.txt
echo ""
pkgs=`rpm -qa --queryformat "[%{NAME}\n]" | grep php | sort`
dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
dnf module list php
dnf module reset php
dnf module enable php:remi-7.4
dnf install $pkgs
echo "Upgrade complete."
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.