How to Install PHP on Ubuntu 20.04/18.04/16.04

Install PHP on Ubuntu 20.04/18.04/16.04

Intro:

PHP is a server-side scripting language and it is used as a web programming language. PHP should be installed on a webserver to run and execute PHP code. PHP is free, as well as open-source.

Stage 1: PHP Repository to be Enable:

First, we need to update our system then execute software-properties-common and ppa: ondrej/php commands.

~# sudo apt-get update

~# sudo apt-get update

~# sudo apt -y install software-properties-common

~# sudo add-apt-repositaryppa:ondrej/php

Stage 2: Install PHP 7.4 on an ubuntu machine:

~# sudo apt-get install php7.4

Verify the php version, by using below command shown below:

~# php -v

image

If you want to install more packages at a time, use the below command

install php extention

You can see your list of php modules

~# php -m

Stage 3: Execute PHP Sample file on Ubuntu:

We need to create a PHP file in the location of /var/www/html/directory.

~# sudo vi /var/www/html/sample.php

Under sample.php use the below code to test it.

<?php

phpinfo();

?>

Save and close it.

Now, open the browser and go tohttp://IP_address:sample.php

php info