Open In App

How to Install PHP on Ubuntu?

Last Updated : 15 Apr, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Installing PHP in Ubuntu is a very simple and efficient process estimate we already know, PHP is responsible for the development of various web applications it is considered one of the most popular languages for web development, in this article we will learn and understand how we can install the PHP in the ubuntu.

What is PHP?

PHP is a server-side programming language that is free and open-source for users and also can be used to make various types of apps, websites, CRMs, and many more. It is a general-purpose language that is often used and may be integrated into Hypertext Markup Language (HTML). Basically in the system, Eight primitive data types that PHP offers are further divided into three internal categories: Script Types (pre-established), Types of Compounds (user-defined), and Unique Types.

Prerequisites

  1. Linux system that runs Ubuntu.
  2. Access to an Ubuntu user account that also has sudo privileges/rights.
  3. Full Access to the terminal window (Ctrl+Alt+T)

How to Install PHP in Ubuntu?

Ubuntu is known as one of the most used open-source operating systems which is responsible for the overall development of any web interface for an application that we want to develop, we will install PHP in Ubuntu and understand how easy it is to install the PHP in ubuntu.

There are two methods through which we can install PHP in Ubuntu, let’s understand each:

Method 1: Install PHP Using Apt/Terminal

This is the simplest method, we use apt package manager to install the PHP into the Ubuntu system, The following are the steps involved:

Step 1: Open Terminal with Sudo Rights

The first step is to open the Ubuntu terminal and apply sudo rights, To open the terminal (Ctrl+Alt+T) type the following command, then enter the system’s user password:

sudo -i

This will give us the following output:

sudo-command

sudo -i

Step 2: Update Repository

Now run the following commands to update the index and repository for the latest repositories using the following command:

sudo apt update

This will give us the following output:

sudo-apt-update

sudo apt update.

Step 3: Install PHP Package

Now you have to run the following apt command and it will automatically install the PHP in the Ubuntu system:

sudo apt install php

This will give us the following output:

sudo-apt-install-php

sudo apt install PHP.

Step 4: Check if PHP is Installed or Not

This is the final step where we will now check if PHP is installed or not, for this, you will simply have to run the following command:

php -v

This will give the following output:

php--v

php -v

Note: If the PHP version is different then there is no issue, PHP is successfully installed in your system.

Method 2: Install PHP Using Apache on Ubuntu

Now we will install the PHP using Apache in Ubuntu, for follow the step-by-step process mentioned below:

Step 1: Install software-properties-common

This helps us in the management of the software and its resources so first we will have to install this package, for this run the following command:

sudo apt install software-properties-common

This will give the following output:

software-properties-common

sudo apt install software-properties-common,

Step 2: add ondrej/php PPA

Now we will have to add ondrej/php PPA which is used to provide different versions of PHP to Ubuntu, for entering the following command:

sudo add-apt-repository ppa:ondrej/php

Again, this will give the following output:

sudo-add-apt-repository-ppa-ondrej_php

sudo add-apt-repository ppa:ondrej/php.

Step 3: Install the PHP version

Now you can install any version of the PHP that you want, make sure that you verify that the version does exist and that there are no typos, for example, here I have installed:

php-74

Install the PHP version.

Also Read

Conclusion

In conclusion, we learned two different methods to install PHP which is very common and popularly used in web development for complex websites, we learned how to install PHP on any Ubuntu system very easily and efficiently, read this article to install PHP in your Ubuntu system.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads