How to Install PHP on Ubuntu 22.04

Install PHP on Ubuntu 22.04

In this article, we will have explained the necessary steps to install PHP on Ubuntu 22.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

PHP an acronym for Hypertext Preprocessor is an open-source general scripting language preferred for web development. The most fascinating feature about PHP is its simple code, which newcomers get along with really fast. It is also powerful, flexible, and platform-independent among many other professional programming features.

Prerequisite:

  • Operating System with Ubuntu 22.04
  • Server IPv4 Address with Superuser Privileges (Root Access)
  • Gnome Terminal for Linux Desktop
  • PuTTy SSH client for Windows or macOS
  • Powershell for Windows 10/11
  • Familiar with APT Commands

Install PHP on Ubuntu 22.04 LTS

Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.

sudo apt update
sudo apt upgrade
sudo apt install software-properties-common dirmngr apt-transport-https gnupg

Step 2. Install PHP on Ubuntu Linux.

Installing the PHP on your Ubuntu 22.04 Jammy Jellyfish system is straightforward, Now add enable the PHP repository:

sudo add-apt-repository ppa:ondrej/php

Now install PHP 8.1 on Ubuntu with the below following command:

sudo apt install php8.1

Check your PHP version information with the following command:

php -v

Output:

PHP 8.1.3 (cli) (built: Jun  8 2022 19:46:26) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.2, Copyright (c), by Zend Technologies

Step 3. Install PHP 8 Extensions.

Besides PHP itself, you will likely want to install some additional PHP modules. You can use this command to install additional modules:

sudo apt install php8.1-<extension>

For instance, we will use the given syntax for installing some PHP 8.1 extensions as follows:

sudo apt install php8.1-cli php8.1-common php8.1-imap php8.1-mysql php8.1-xml php8.0-zip php8.1-mbstring php8.1-fpm

To check the loaded modules of PHP 8, utilize the following command:

php -m

That’s all you need to do to install PHP on Ubuntu 22.04 LTS Jammy Jellyfish. I hope you find this quick tip helpful. For further reading on the installation of the PHP Programming Language, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.