Installing PHP on Ubuntu
Installation

Install PHP on Ubuntu

Sagar Sharma
Sagar Sharma

Table of Contents

PHP is one of the most popular server-side programming languages. From WordPress to Drupal, PHP runs underneath most of the frameworks.

Whether you are deploying a LAMP server or doing standalone PHP programming, if you need to install PHP on Ubuntu, this tutorial will help you.

In this guide, I will walk you through the following:

  • Installing PHP
  • Installing PHP modules

So let's start with the installation process.

How to install PHP on Ubuntu

PHP is available in the default repository of Ubuntu which means it can be installed using a single command:

sudo apt update && sudo apt install php

The reason why I added sudo apt update is to update the repository index to get you the most recent package.

Once you are done with the installation, you can check the installed version of PHP:

php -v
check installed version of php

And as you can see, it gave me PHP version 8.1.2.

Now, let's have a look at how you can install PHP modules.

How to install PHP modules in Ubuntu

You can think of PHP modules as extensions that are used to extend the functionality of PHP.

PHP modules can easily be installed using the following command syntax:

sudo apt install php[version]-[package_name]

For example, if I want to install MySQL extension, I will be using the following:

sudo apt install php8.1-mysql

Similarly, if you want to install multiple extensions at once, you can refer to the following command syntax:

sudo apt install php[version]-{module1,module2,module3}

So let's say I want to install 3 modules: zip, bcmath, and posix so I will be using the following:

sudo apt install php8.1-{zip,bcmath,posix}

To list installed PHP plugins, all you have to do is append the -m flag to the php command:

php -m
list installed PHP modules in ubuntu

Usually, people install PHP as part of a server stack like LAMP, LEMP or LOMP. In case your aim is to get a LAMP server, this guide will be of help to you.

Installing LAMP Server on Localhost on Ubuntu
Learn all about installing the popular LAMP tech stack on an Ubuntu server in your localhost in this step-by-step beginner’s tutorial.


Sagar Sharma

Sagar Sharma

A software engineer who loves to tinker with hardware till it gets crashed. While reviving my crashed system, you can find me reading literature, manga, or watering my plants.