Install PHP on Ubuntu Linux

Overview

In this tutorial, we’ll be going through the steps to install PHP on Ubuntu Linux machine.

Environment: Ubuntu Linux Server LTS.

Install PHP

Log in with a user having sudo privileges.

Open Terminal window.

Issue the following command

$ sudo apt install php

 

PHP Install on Linux

Install PHP extensions

PHP extensions are available as packages and can extend the functionality of PHP instance.
To install a new PHP extension, we can run the command in the terminal window as shown.

$ sudo apt install <php extension name>

For example, if we want to install MySql extension we can run the following command

$ sudo apt install php-mysql

 

mysql php extension linux

Verification

Open a terminal window and type the following command.

$ php -version

 

Test PHP on Apache Server