Site Overlay

How to Install PHP 7.4 on Ubuntu 20.04 and the New Features?

Throughout this article, we’ll see step by step how to install PHP 7.4 which is the latest minor version before PHP 8 major release expected by the end of this year. We’ll also see the new features added in PHP 7.4.

When PHP 7.4 Was Released?

PHP 7.4 was released on November 2020

What are the New Features of PHP 7.4?

PHP 7.4 brought many new features to the most popular server-side language such as:

  • Support for Arrow functions: this new feature allows PHP developers to write clean and shorter code and make the syntax more concise,
  • Support for Typed properties: Thanks to this new feature, you will be able to use nullable types, int, float, array, string, object, iterable, self, bool, and parent,
  • Preloading: This feature will help to increase the PHP 7.4 performance. Preloading refers to the process of loading files, frameworks, and libraries in OPcache,
  • Weak References: The WeakReference class allows web developers to have a reference to an object that does not prevent its destruction,
  • Coalescing assign operator: This new operator will make your code shorter and easy to read, for example, you can use it instead of a ternary operator together with isset(). It allows you to return the first operand if it exists and is not NULL. Otherwise, it returns the second operand,
  • A spread operator in array expression: This new feature will allow developers to use spread operators in arrays instead of array_merge, etc.

These new features will increase the performance of your PHP apps and reduce memory usage. Developers will be able to avoid many limitations of PHP, produce cleaner and shorter code, and create web solutions faster.

Next, let’s see how to install this new version of PHP in our Ubuntu 20.04 machine.

How to Install PHP 7.4 on Ubuntu 20.04?

Let’s now learn about the steps that you need to follow to install PHP 7,4 in your Ubuntu 20.04 machine.

Ubuntu 20.04 ships with the latest PHP 7.4 version so you can install it from the official packages without adding a PPA.

Open a new terminal and run the following command to display the available PHP 7.4 packages:

apt-cache pkgnames | grep php7.4

Now you can install PHP 7.4 from the Ubuntu package repository using the following command:

sudo apt-get install php7.4 -y
    sudo apt-get install php7.4-{bcmath,bz2,intl,gd,mbstring,mysql,zip} -y

Wait for the operation to finish then run the following command to ensure that PHP 7,4 is successfully installed on your machine:

php -v

You should get a similar output:

That’s it! We have briefly seen the new features introduced in PHP 7.4 which is the latest minor version before the release of the major PHP 8 version. We have also seen how to install PHP 7.4 in our Ubuntu 20.04 machine which ships with the official packages of this new version without the need to use a third-party PPA.

Leave a Reply

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