Installing PHP is an essential part of any web development pipeline. Without a server-side scripting language, you cannot implement logic in your pages.

In this article, we will see how to install PHP in Ubuntu 20.04 and 18.04 LTS versions. The process itself is quite simple and almost identical for both versions.

We’re going to look at two methods of installing PHP on your Ubuntu machine, one with Apache and one with Nginx.

Installing PHP with Apache

If you are using Apache as your primary web server, use the following command to install PHP with the Apache PHP module.

On Ubuntu 20.04 the following command installs PHP 7.4, and on Ubuntu 18.04 it installs PHP 7.2.

sudo apt update
sudo apt install php libapache2-mod-php

Restart Apache after installing the packages to load the PHP module.

sudo systemctl restart apache2

Also read : Mint vs. Ubuntu: Comparison of Linux distributions

Installing PHP with Nginx

Nginx does not have built-in support for processing PHP files, which means that PHP-FPM, also known as fastCGI Process Manager, must be used to process PHP files.

sudo apt update
sudo apt install php-fpm

Once the installation is complete, the FPM service is automatically started. To check the status of the service, use this command.

php7.4-fpm system status

Once you are sure the service is installed and running, make the following addition to your Nginx server block so it can process the PHP files.

Server {

# … another code

location ~ .php$ {
allows snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;

Then restart the Nginx service for the changes to take effect.

sudo systemctl restart nginx

Also read : How to install themes in Ubuntu?

How do I install PHP on Ubuntu 18.04 LTS?

If you are using Ubuntu 18.04, the commands to install PHP via Apache or Nginx remain the same. However, note that both commands install PHP 7.2, as this is the default version of PHP in the repository.

To verify that the FPM service works on Ubuntu 18.04 LTS, you need to modify the above command to make sure you are getting the correct version of PHP.

php7.2-fpm system status

The basic functionality of PHP can let you down. There are many PHP extensions/libraries you can use to speed up your work.

To install it, use the apt command with the following syntax.

sudo apt install php-packagename

For example, MySQL and GD, some of the most widely used PHP extensions, can be installed this way.

sudo apt install php-mysql php-gd

Depending on the server you are using, you may need to restart Apache or the PHP FPM service after the installation is complete.

Read also: 25 basic commands for the Linux terminal

Testing your installation is fairly simple. Create a new info.php file in the /var/www/html directory and insert the following code.

One of the Debian developers, Ondrej Suroj, manages the PHP version repository. Here’s how to activate the deposit.

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

You can now install almost any version of PHP using the apt command.

sudo apt install php(version)

A z. B. To install PHP 7.2, the command should look like this

sudo apt install php7.2

The same applies to the installation of packages.

Also read : How do I install PHP manually on Windows?

The one who writes/cuts/films/owns all the technology, and when he’s not around, switches to virtual machine races. You can contact Yadullah at [email protected], or follow him on Instagram or Twitter.

frequently asked questions

How do I download PHP on Ubuntu?


How do I run PHP on Ubuntu?

Questions about how to start…

How do I install the latest version of PHP on Ubuntu?


unable to locate package php,install php 7.4 ubuntu,uninstall php 8 ubuntu,instalar php ubuntu,install php 7.3 ubuntu,libapache2-mod-php,install php lubuntu,php 7.2 zip extension ubuntu,install php 8 ubuntu,uninstall php ubuntu,uninstall php in ubuntu,install php 7.2 ubuntu 18.04 digitalocean,configure php with apache linux,php on linux,error: module php does not exist!,apache enable php 7,start php server ubuntu command line,ubuntu php package,how to run php script ubuntu,ubuntu php nginx,ubuntu server database,how to run php file in ubuntu using xampp,Feedback,upgrade php 7.0 to 7.3 ubuntu,upgrading php in linux,install php7 mysql,ubuntu apache php7,e: unable to locate package php,php7 apache,how to install php 7.4 in ubuntu,how to install php in kali linux,how to run php in apache in ubuntu,what is php on linux,i require php but its not installed termux,how to install php 8 on windows 10,upgrade to php 8 ubuntu,install php 8 debian,install php 8 centos 7,install php 8 mac,install php 7.4 debian,uninstall php 7.4 ubuntu,install php 7.4 windows 10,digitalocean upgrade php,apt-cache search php7 not found,Privacy settings,How Search works,install php ubuntu 20,install composer ubuntu,install mysql ubuntu,ubuntu install apache php

You May Also Like

Download ShowBox Alternatives on iPhone/iPad and Android

Here are the best known Showbox alternatives for iOS 11+/10+/+8+7+ on iPhone,…

9 common types of Malware explained

Today, we are exposed to thousands of software products every day and…

The Importance of Storyboarding Your PowerPoint Presentation

For most of us, the word storyboard conjures up images of movie…

The Complete Guide To Improving A Website

There are nearly two billion websites on the Internet. With so many…