• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
OpenTechTips

OpenTechTips

Comprehensive IT Guides for Pros and Enthusiasts

MENUMENU
  • HOME
  • ALL TOPICS
    • Exchange
    • InfoSec
    • Linux
    • Networking
    • Scripting
      • PowerShell
    • SSL
    • Tools
    • Virtualization
    • Web
    • Windows
  • ABOUT
  • SUBSCRIBE
Home » Upgrade PHP 7.2 to PHP 7.4 on Ubuntu

Upgrade PHP 7.2 to PHP 7.4 on Ubuntu

August 4, 2021 - by Zsolt Agoston - last edited on November 15, 2021

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?

Upgrade PHP 7.2 to PHP 7.4 on Ubuntu

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
Upgrade PHP 7.2 to PHP 7.4 on Ubuntu

Should you have any comments please share down below.

Reader Interactions

Comments

  1. Carlos says

    January 5, 2022 at 01:43

    Obrigado, me ajudou muito!!!

    Reply
  2. Jim says

    January 24, 2022 at 15:49

    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

    Reply
  3. Boris says

    March 10, 2022 at 12:29

    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

    Reply
    • Boris says

      March 10, 2022 at 12:29

      If i switch back to Version 7.2 it will work again

      Reply
      • Zsolt Agoston says

        March 10, 2022 at 13:24

        Hi Boris, what is the name of the file which is downloading when using php7.4?

        Reply
    • Ghifari says

      March 15, 2022 at 03:46

      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

      Reply
      • Zsolt Agoston says

        March 15, 2022 at 15:58

        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

        Reply

Comments Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Tools

Secondary Sidebar

CONTENTS

  • Step 1 – Install PHP 7.4 and extensions
  • Step 2/3 – Switch to PHP 7.4

  • Terms of Use
  • Disclaimer
  • Privacy Policy
Manage your privacy

To provide the best experiences, we and our partners use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us and our partners to process personal data such as browsing behavior or unique IDs on this site and show (non-) personalized ads. Not consenting or withdrawing consent, may adversely affect certain features and functions.

Click below to consent to the above or make granular choices. Your choices will be applied to this site only. You can change your settings at any time, including withdrawing your consent, by using the toggles on the Cookie Policy, or by clicking on the manage consent button at the bottom of the screen.

Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Statistics

Marketing

Features
Always active

Always active
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
Manage options
{title} {title} {title}
Manage your privacy
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Statistics

Marketing

Features
Always active

Always active
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
Manage options
{title} {title} {title}