So you are recently greeted with the following nice warning message in the WordPress console saying PHP 7.2 is being deprecated and you should upgrade to the more recent version of 7.3 or preferably PHP 7.4?
Here's how you can do it in under a minute:
1. Install PHP7.4 and the extensions needed
2. Switch to PHP7.4 in apache2
3. Restart the apache2 service
Step 1 - Install PHP 7.4 and extensions
First open a shell to your web server. You'll need superuser access, so either access to the root account or your account needs to be added to the sudo group or in the /etc/sudoers file separately.
Run the following:
# Add the repos containing the newer php packages sudo apt install software-properties-common sudo add-apt-repository ppa:ondrej/php sudo apt -y update # Install PHP 7.4 and extensions sudo apt -y install php7.4 php7.4-{mysql,mbstring,bcmath,bz2,curl,imagick,dom,zip} libapache2-mod-security2 wget
Step 2/3 - Switch to PHP 7.4
Now we need to let the apache service know that we want to use php7.4 instead of the existing version. Assuming that we currently use php7.2 the following commands will do the job. If you use a different version, substitute that number accordingly in the a2dismod line.
sudo a2dismod php7.2 sudo a2enmod php7.4 # Restart the apache 2 service to activate the new configuration sudo systemctl restart apache2
Should you have any comments please share down below.
Carlos says
Obrigado, me ajudou muito!!!
Jim says
I really appreciate the information, its something Ive been looking for, but adding the -y flag can be a little dangerou at times especially if you get a warning you are not expecting, I think you should let people know what the -y flag is for (it basically says ‘Yes; to everything so you dont have to type yes in when asked) and why you should or should not use it
Boris says
Hey there,
after i switch
sudo a2dismod php7.2
sudo a2enmod php7.4
my website will only download a file but wont open the real website. I startet the Browser in Private Mode to avoid caching but it wont help.
Thx
Boris
Boris says
If i switch back to Version 7.2 it will work again
Zsolt Agoston says
Hi Boris, what is the name of the file which is downloading when using php7.4?
Ghifari says
Yes, me too. If I follow some tutorial for upgrading PHP7.4, Alwasy failed and if I open my website address, like a download file but not upen my website. Please help me
Zsolt Agoston says
Hi Ghifari, I understand and I’ll try to figure out what is the culprit in both of your cases. May I ask you too: what is the name of the file that is downloaded?
Make sure your server is up to date. Run these commands on your server:
apt update
apt upgrade
If it doesn’t work, try the following:
apt update
apt install libapache2-mod-php