How to install PHP 7.4 on Ubuntu 22.04?

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Ubuntu 22.04 includes by default PHP 8.1 which is one of the most recent versions of this language. And if I want PHP 7.4 in Ubuntu 22.04, how do I do it? Well, this post is to help you with that.

PHP 7.4 and PHP 8.1

Although it is normal that we have well-supported versions of a program, it is true that there are certain applications or configurations that make this impossible.

In the case of PHP, there are applications such as Owncloud that do not yet support PHP 8, so we wait until support is complete? Or we install a lower version? This will be determined by circumstances.

In any case, both versions are stable, mature and have a strong user base. Let’s get started.

Install PHP 7.4 on Ubuntu 22.04

As we know, PHP 7.4 is not in the official Ubuntu 22.04 repositories, so we have to resort to another PPA for it.

In this post, we assume that you have not installed PHP, if so, uninstall it from the system

sudo apt remove php*

Then, update the whole system

sudo apt update
sudo apt upgrade

Thereafter, install some important packages to fulfill the post.

sudo apt install software-properties-common apt-transport-https

The next step is to add the ondrej PPA repository

sudo add-apt-repository ppa:ondrej/php

Refresh APT to load the new repository:

sudo apt update

And now you can install PHP 7.4

sudo apt install php7.4

You are done.

Test PHP 7.4 with Apache on Ubuntu 22.04

Now, to demonstrate the correct operation of PHP, I will install the Apache web server and some modules.

sudo apt install apache2 php7.4 php7.4 php7.4-common libapache2-mod-php7.4 php7.4-cli
Install PHP 7.4 on Ubuntu 22.04
Install PHP 7.4 on Ubuntu 22.04

Now, create a new PHP file in the Apache root directory. This to access it.

sudo nano /var/www/html/test.php

And add the following:

<?php
phpinfo();
?>

Save the changes and close the editor.

For all this to work, remember that ports 80 and 443 must be open.

sudo ufw allow 80
sudo ufw allow 443

Then, open a web browser and access http://your-server/test.php and you will see the page working.

PHP 7.4 on Ubuntu 22.04
PHP working!

So, enjoy it.

Conclusion

In this post, you learned how to install PHP 7.4 on a recent system. Although occasionally, it is not necessary, it can help to improve compatibility with certain applications.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Angelo
Angelo
I am Angelo. A systems engineer passionate about Linux and all open-source software. Although here I'm just another member of the family.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook