How to install PHP 7.4 on Ubuntu 22.04 LTS Jammy Linux

By default system repository Php 8.1 is available to install on Jammy JellyFish, hence in this tutorial, we learn the commands to install PHP 7.4 on Ubuntu 22.04 LTS server or desktop using the terminal. 

PHP is a scripting language, so it is translated line by line into machine commands by an interpreter. On the Internet, PHP is behind over 80% of all websites on whose web servers it runs and thus controls the behavior of the website.  It has been used by many web servers such as Apache to power thousands of websites and web platforms.  Also, PHP makes it easy for programmers to develop and control a website functioning because PHP has numerous function libraries and connections to Internet protocols and databases.

Further, PHP can be used to process user input. If, for example, you want to include a contact form on your website, the entries must be further processed. Only with HTML, this is not possible. With PHP, for example, you can check whether all fields have been filled in and, if successful, send an e-mail. Also, when it comes to retrieving content from a database, it makes sense to use PHP. For example, if you want to program a news website, you can save your texts in a database and then output them with PHP at the desired places in your HTML code. You do not have to create a single HTML file for each article and can implement changes much faster. That’s why PHP has been used for creating Dynamic websites.

Steps to install PHP 7.2 on Ubuntu 22.04 LTS server or desktop

The steps given here can also be used for other Linux distros based on Ubuntu 22.04 LTS such as POP OS Linux, Linux Mint, Elementary OS, and more…

1. Run system update

Our system must be in its latest state to avoid any package conflict. Hence, before going further, let’s first run the system update command to ensure all the available security updates are on our Ubuntu.

sudo apt update && sudo apt upgrade

 

2. Add Ondrej PPA Repository on Ubuntu 22.04

We cannot install the PHP7.4 packages using the default system repository of Ubuntu 22.04 because the default version of PHP present to install in this Ubuntu version is PHP 8.1. Hence, to get the older version, add the PPA repository called Ondrej.

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php -y

Add Ondrej PPA Repository on Ubuntu 22.04

 

3. Install PHP 7.4 on Ubuntu 22.04

Now, we can install PHP7.4 on our Ubuntu 22.04 Linux, however, we need to mention the version number with the command otherwise the system will install the php8.1 on our system. Here are the commands to follow:

sudo apt install php7.4

For Common Extensions you can use:

sudo apt install php7.4-{cli,common,curl,zip,gd,mysql,xml,mbstring,json,intl}

install PHP 7.4 on Ubuntu 22.04 1

 

4. Set PHP7.4 as the default version

Note: This step is only needed by those who are using two versions of PHP. For example, on Ubuntu 22.04 you are using PHP 7.4 and PHP 8.1 both. Hence, to make one of them as system’s default version we can use the update-alternatives command:

sudo update-alternatives --config php

Enter one of the “Selection” numbers of the listed PHP version that you want to make the system’s default one. For example, here 7.4 is at 1 number, hence we have typed the same followed by pressing of the “Enter” key.

Set PHP 7.4 as default version on Ubuntu

 

5. Uninstall PHP and remove Ondrej PPA

If you don’t require the PHP7.4 and Ondrej PPA anymore on your Ubuntu 22.04 then we can remove them as well. Here are the commands to follow:

sudo apt autoremove --purge php7.4

To remove PPA:

sudo add-apt-repository --remove ppa:ondrej/php -y

 

Other Articles:

How to install PHP 8 on Ubuntu 20.04 LTS Server
Steps to install PHP 8 on Debian Server 10 | 9
Install LAMP on Rocky Linux 8 Server
How to install Apache, MySQL, and PHP on AlmaLinux 8
How to install PrestaShop on Ubuntu 22.04 Server

 

 

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.