How to Install PHP on Ubuntu 20.04 Machine

how to install php on ubuntu 20.04

PHP is a common purpose scripting language which is mainly used for developing websites and web applications. PHP was created by Rasmus Lerdof in the year 1994. Php is a free and open source platform. It runs on any Web server like Apache and nginx.

In this tutorial we are going to learn how to install PHP on Ubuntu 20.0 machine. It covers PHP 7.0, 7.1, 7.2, 7.3, 7.4 installations.

Add PPA:

To add the Ondrej PPA for PHP on Ubuntu 20.04 machine, run the following commands below:

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php

Install PHP on ubuntu:

You can choose a specific version to install PHP on Ubuntu. At the time of writing this article PHP 7.4 is the latest version, for this tutorial I have installed PHP 7.4 on my Ubuntu 20.0 machine.

sudo apt-get update

Following PHP installation commands will automatically install Apache on your Ubuntu 20.04 machine.

To install PHP 7.0

To install the PHP 7.0 on your Ubuntu 20.04 machine, run the commands below:

sudo apt install -y php7.0

To install PHP 7.1

To install the PHP 7.1 on your Ubuntu 20.04 machine, run the commands below:

sudo apt install -y php7.1

To install PHP 7.2

To install the PHP 7.2 on your Ubuntu 20.04 machine, run the commands below:

sudo apt install -y php7.2

To install PHP 7.3

To install the PHP 7.3 on your Ubuntu 20.04 machine, run the commands below:

sudo apt install -y php7.3

To install PHP 7.4

To install the PHP 7.4 on your Ubuntu 20.04 machine, run the commands below:

sudo apt install -y php7.4

To check the PHP version:

To check the installed PHP version on your Ubuntu 20.0 machine, run the command below:

php -v
Output

PHP 7.4.6 (cli) (built: May 14 2020 10:03:35) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.6, Copyright (c), by Zend Technologies

Install PHP modules:

After installing PHP 7.4 on Ubuntu 20.04 machine, install the required PHP 7.4 modules.
To search the PHP 7.4 modules, run the command below:

sudo apt-cache search php7.4

After that install, the required PHP 7.4 modules you want, to installing different versions just change the PHP version then install the PHP modules. To install PHP 7.4 modules run the command below:

sudo apt install php7.4-mysql php7.4-curl php7.4-json php7.4-cgi php7.4-xsl

Test if PHP is working on your Ubuntu 20.04:

Create the info.php file in your root directory then copy and paste the code below to test PHP is working or not.

<?php
phpinfo();
?>

After that access your IP address http://ip_address/info.php or domain name http://domain_name/info.php on your browser.

PHP Ubuntu 20.04

Conclusion:

Congratulations! We have successfully installed PHP 7.4 on Ubuntu 20.04 machine. Now we learned how to install PHP 7.0, 7.1, 7.2, 7.3, 7.4 on Ubuntu. Let’s start your PHP development now.

Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like