How to Install PHP on Ubuntu 20.04

How to Install PHP on Ubuntu 20.04

PHP stands for Hypertext Preprocessor, free and open source, server-side scripting language that can also integrate into HTML. PHP language is suitable for dynamic and interactive web development. This is the most common and widely used web programming language in the world. PHP is an interpreted language so, you don’t require a compiler to run the PHP program. PHP processing acts as a bridge between the PHP interpreter and the webserver.

We will go through the PHP installation on Ubuntu 20.04 system in this article.


You need sudo privileges to run the administrative commands.

PHP installation steps on Ubuntu 20.04

The installation of PHP completed into the following steps:

Step 1: Install PHP modules

Update the apt packages of your system and then type the following command on the terminal to install PHP components:

$ sudo apt install php libapache2-mod-php php-mysql

Enter the administrative password and in a while, a prompt interrupt the installation. Press ‘y’ and then hit the ‘Enter’ key to continue this process.

After that, all PHP modules to be installed on your system. You can also install the required PHP extension depending on the project requirements.

Step 2: Check installed PHP version

Verify the installation of PHP by running the following command:

$ php --version

The installed PHP version should display on the terminal.

Step 3: Install required PHP extensions

To search for the relevant PHP extension type the following command on the terminal:

$ sudo apt-cache search php | grep php-

The all PHP extensions list displays on the terminal. You can find the relevant PHP extension and install it on your system by using the following syntax:

$ sudo apt install php-[extension-name]

Step 4: Configure PHP

To configure the PHP for your web applications, you need to change certain values in the php.ini configuration file. Type the following command to open the ‘php.ini’ configuration file:

$ sudo nano /etc/php/7.4/apache2/php.ini

Now, find and change the following values in the configuration file:

# Upload max write = 32 M

# After max size = 48 M

# Speicher limit = 256 M

# Max perform time = 600

# Input vars = 3000

# Input time max = 1000

Once you have changed the PHP configuration settings. Now, restart the service of the apache server by typing the following command:

$ sudo systemctl restart apache2

Step 5: Test the PHP installation

Now, create a new PHP file in the web directory. Here, we have created a new file with the name ‘info.php’ by using the following command:

$ sudo nano /var/www/html/info.php

Paste the following PHP code in the above file:

<? php

echo “Welcome to PHP installation Tutorial!”;


Save this file and open the following URL in your browser:


For example,

The following output should display on the terminal after running the above code:


We have explained all details in this article that are necessary for the PHP installation on Ubuntu 20.04 system. By using the above installation steps, you can easily install the PHP components and extensions on your Ubuntu system.


Similar Posts