In this guide, we will learn how to use the terminal to install PHP 7.4 on an Ubuntu 22.04 LTS server or desktop since PHP 8.1 is already available to install by default in the system repository on Jammy JellyFish.
In this guide, we will learn how to use the terminal to install PHP 7.4 on an Ubuntu 22.04 LTS server or desktop since PHP 8.1 is already available to install by default in the system repository on Jammy JellyFish.
Since PHP is a scripting language, an interpreter converts each line of the language into a set of machine commands. Over 80% of websites on the Internet run on web servers that are powered by PHP, which in turn governs how those websites behave. Thousands of websites and web platforms have been powered by it thanks to the deployment of numerous web servers like Apache. Additionally, PHP’s extensive function libraries, interfaces to Internet protocols, and support for databases make it simple for programmers to create and maintain websites.
PHP can also be used to handle user input. The entries need to be further processed, for instance, if you wish to include a contact form on your website. This is just not feasible with HTML. PHP, for instance, allows you to verify that all fields have been completed and, if so, send an email. Additionally, using PHP when requesting items from a database makes logical. If you’re programming a news website, for instance, you can save your texts in a database and then output them using PHP where you want them in your HTML code. Changes may be made considerably faster and there is no need to produce a separate HTML file for every article. Therefore, PHP has been utilised to build dynamic websites.
On the Page
Steps to install PHP 7.2 on Ubuntu 22.04 LTS server or desktop
1. Run system update
2. Add Ondrej PPA Repository on Ubuntu 22.04
3. Install PHP 7.4 on Ubuntu 22.04
4. Set PHP7.4 as the default version
5. Uninstall PHP and remove Ondrej PPA
Other Linux distributions based on Ubuntu 22.04 LTS, such as POP OS Linux, Linux Mint, Elementary OS, and others, can also use the instructions provided here.
To prevent any package conflicts, we must use the most recent version of our system. So let’s first run the system update command to make sure Ubuntu has all the latest security updates before moving on.
sudo apt update && sudo apt upgrade
Because PHP 8.1 is the default PHP version to install in this version of Ubuntu, we are unable to install PHP7.4 packages using the default system repository of Ubuntu 22.04. So, add the Ondrej PPA repository to receive the earlier version.
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php -y
We may now install PHP7.4 on our Ubuntu 22.04 Linux system, but we must specify the version number with the command in order to avoid having PHP8.1 installed on our system. The instructions are as follows:
sudo apt install php7.4
You can use: for Common Extensions.
sudo apt install php7.4-{cli,common,curl,zip,gd,mysql,xml,mbstring,json,intl}
Only individuals who are utilising two versions of PHP are required to complete this step. For instance, you use both PHP 7.4 and PHP 8.1 on Ubuntu 22.04. Therefore, we can use the update-alternatives command to set one of them as the system’s default version:
sudo update-alternatives –config php
If you want to choose a specific PHP version as the system’s default, enter one of its “Selection” numbers. For instance, 7.4 is the first number here, so we typed it and then pressed the “Enter” key.
We can also remove the PHP7.4 and Ondrej PPAs from your Ubuntu 22.04 if you no longer need them. The instructions are as follows:
sudo apt autoremove –purge php7.4
To remove PPA:
sudo add-apt-repository –remove ppa:ondrej/php -y