How to Install PHP in Ubuntu 22.04

PHP is known as an efficient programming language that is used to develop web-based applications and dynamic websites. It is used for major websites development and maintenance like WordPress etc. It helps in creating the blogs, websites and commercial applications etc.

PHP introduced new features to its users like return type, enums etc. So, it is supported by several platforms. The Ubuntu system also includes the PHP packages to install the PHP on Ubuntu for several purposes.

This writing illustrates how to install the latest version of PHP on Ubuntu 22.04 with the following expected results:

  • Install PHP from Ubuntu’s official repository
  • Install PHP from PPA repository

How to install PHP on Ubuntu 22.04

PHP is an excellent programming language that is utilized for developing the web-based applications. Ubuntu 22.04 provides multiple ways to install PHP on Ubuntu 22.04. This section enlists the best possible methods to get PHP on Ubuntu 22.04.

Method 1: Install PHP from Ubuntu’s official repository

The Ubuntu’s official repository includes the latest version of PHP. The following steps will lead you to get PHP on Ubuntu 22.04.

Step 1: Update system’s packages

A user should update the core repository of Ubuntu system to get the updated packages. Run the following command in terminal to update system packages.

$ sudo apt update

The installed packages have been updated.

Step 2: Install PHP

When the system packages are updated, you can install the PHP. For this purpose, use the following command:

$ sudo apt install php

Hit the ‘’Y’ key to continue the installation. The output showed that PHP is installed successfully.

Step 3: Check version

To verify the successful installation of PHP on Ubuntu 22.04, a user can check the version of PHP using the following command:

$ php --version

It is verified that the installed version of PHP is 8.1.2

How to remove PHP from Ubuntu 22.04

If you have installed the PHP on Ubuntu 22.04, you can also remove it by using the below-mentioned command in terminal:

$ sudo apt purge php

Hit the ‘’Y’ key to continue the uninstallation process. The PHP is removed successfully from Ubuntu 22.04

Method 2: Install PHP from PPA repository

The PPA (Personal Package Archives) repository provides the utility to install the latest version of PHP on Ubuntu 22.04. Follow the steps to get PHP on Ubuntu 22.04 via PPA repository.

Step 1: Add PPA repository

To add the Ondrej PPA repository for PHP, use the following command in the terminal:

$ sudo add-apt-repository ppa:ondrej/php

The PPA repository is added successfully.

Step 2: Update system’s packages

After adding the PPA repository, you must update the core libraries of the system to opt for the latest packages. To update system repository, run the following command:

$ sudo apt update

The installed packages have been updated.

Step 3: Install PHP

Now, to install the PHP on Ubuntu 22.04, execute the following command:

$ sudo apt install php

PHP is installed successfully.

Step 4: Check Version

To verify the successful installation of PHP on Ubuntu 22.04, a user can check the version of PHP using the following command:

$ php -version

It is verified that the installed version of PHP is 8.1.7

How to remove PHP from Ubuntu 22.04

You can remove all the dependencies and configuration files of PHP from Ubuntu 22.04. For this action, type and execute the following command in the terminal:

$ sudo apt autoremove php

The output shows that PHP is removed successfully.

Congratulations! You have learned the installation methods of PHP on Ubuntu 22.04 release.

Conclusion

The PHP can be installed on Ubuntu 22.04 from Ubuntu’s official repository or by importing the PPA repository. PHP is an excellent programming language that develops web-based applications. To get the stable version of PHP, install it from Ubuntu’s official repository. However, you can get the latest version by adding the PPA repository of PHP on Ubuntu 22.04.