Hello Developers, In this post i will guide you how to install PHP on Ubuntu 22.04, Here we will install latest php8.1.
I will also guide you how to install other older php on Ubuntu 22.04.
Get Ready:
Login to Terminal with Root user access.
$ sudo apt update && sudo apt upgrade
When ever prompted for your permission press Y and hit enter.
Install PHP on Ubuntu 22.04
Step 1. Install some dependency which are required for Installation.
$ sudo apt install software-properties-common ca-certificates lsb-release apt-transport-https
Step 2. Adding the Ondrej PPA to our system, which have all versions of PHP.
$ LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
Step 3. Again Update PHP package manager.
$ sudo apt update
Step 4. Install PHP 8.1
$ sudo apt install php8.1
Note: If you want to install another Version of PHP just change the version number on above command like below
$ sudo apt install php7.4
Step 5. Install PHP package which are required by PHP.
$ sudo apt install php8.1-mysql php8.1-mbstring php8.1-xml php8.1-curl
Step 6. Check installed or Not?
$ php -v
This will give you output like below message
PHP 8.1.5 (cli) (built: Apr 21 2022 10:32:13) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.5, Copyright (c) Zend Technologies with Zend OPcache v8.1.5, Copyright (c), by Zend Technologies
Suppose you have old php Version then how to uninstall that, Check below command for uninstall Process.
$ sudo apt remove php7.4
and its module uninstallation
$ sudo apt remove php7.4-*
Thanks and Happy Coding.