How To Install PHP 7 On Ubuntu (Debian, Mint)?

PHP is a popular programming language that is generally used to do develop web applications. Even it can run on different platforms like Windows, MacOS, Unix, etc. the most popular platform and operating system family for PHP is Linux. PHP can be installed on Linux distributions like Ubuntu, Debian, Mint in different ways. Command-line apt and apt-get package manager can be used to install PHP 7 in these Linux distributions. In this tutorial, we will learn how to install PHP 7 in Ubuntu (20.04, 19.10, 19.04, 18.04, …, ) Debian and Mint.

Install PHP7 with apt or apt-get Command Line Package Manager

apt and apt-get commands are used to manage packages in deb based distributions like Ubuntu, Debian, Mint, etc. First, we will list information about the PHP7 package before installation. We will use the apt show or apt-get show command and provide the package name which is php.

$ apt show php
$ apt-get show php
Install PHP7 with apt or apt-get Command Line Package Manager

Now we have information about the PHP package like the version is PHP 7.4. We will install the PHP package with the apt install or apt-get install command but the package installation requires root privileges which is provided with the sudo command like below.

$ sudo apt install php
$ sudo apt-get install php

After the installation is complete we can test the PHP installation by entering the PHP interactive shell where we can type PHP scripts.

$ php -a

php> $name = "wisetut";
php> echo $name;
php> echo $name.".com";
PHP Command Line Interactive Shell

Leave a Comment