DEV Community


Posted on • Originally published at

Install PHP 7.4 on Ubuntu

What's new?

There are countless articles about the changes php7.4 brings. Feel free to get an overview here.


Regardless of whether you want to upgrade or install, let's first adhere to the general recommendation you will find anywhere. Namely, make sure we are up to date: sudo apt-get update.

Then, we want to add Ondrej Sury's repository:

sudo apt -y install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
Enter fullscreen mode Exit fullscreen mode

Now we are ready to install php 7.4.

sudo apt -y install php7.4
Enter fullscreen mode Exit fullscreen mode

You might want to test the success with php -v, which will give you an output about the version.


I don't know which extensions you might need, but the format is very intuitive and with the example of mbstring looks like this:

sudo apt-get install php7.4-mbstring
Enter fullscreen mode Exit fullscreen mode

Tip: you can install multiple extensions with the following format:

sudo apt-get install -y php7.4-{mbstring,mysql}
Enter fullscreen mode Exit fullscreen mode

NOTE: We are happy with the shipped Apache here, but be sure to install php7.4-fpm if you are aiming for NGINX after stopping apache sudo systemctl disable --now apache2

Old installations

In the case of former installations, you will want to purge the old version of php (assuming php 7.3):

sudo apt purge php7.3 libapache2-mod-php7.3

Top comments (1)

devugur profile image
Ugur CELIK • Edited

For install all important php 7.4 extensions

apt install php7.4-common php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-curl php7.4-gd php7.4-imagick php7.4-cli php7.4-dev php7.4-imap php7.4-mbstring php7.4-opcache php7.4-soap php7.4-zip php7.4-intl -y
Enter fullscreen mode Exit fullscreen mode