How To Install PHP In Ubuntu, Debian, Mint?

PHP is popular programming and scripting language which is created 30 years ago it gained popularity with the web and mainly used to create web applications. Even the PHP provides support for different platforms and libraries the main usage is creating web applications. Linux and especially Ubuntu is popular distributions for web servers. PHP applications deployed into Ubuntu regularly and in order to run these PHP applications, the webserver software like Apache or Nginx and the PHP should be installed. In this tutorial, we will learn how to install the PHP latest version into the apt or apt-get based distributions like Ubuntu, Debian, Mint, etc.

Search PHP Packages

Even this is not mandotory you may take a look how to find PHP and related packages with the apt or apt-get command. By the way both the apt and apt-get will work in similar way. The “apt search” command can be used to search PHP package.

$ apt search php
Search PHP Packages

The PHP package is named as php and has the following information.

php/groovy,groovy 2:7.4+76 all
server-side, HTML-embedded scripting language (default)
  • php is the package name.
  • groovy is the Ubuntu release name.
  • 7.4 is the PHP version number.
  • server-side, HTML-embedded scripting language” is a short description about the php package.

Show PHP Package Information

As an Ubuntu, Debian, or Mint package PHP package will have some information like below. This php package information can be displayed with the “apt show” command like below.

$ apt show php

The package information output will be like below.

Package: php
Version: 2:7.4+76
Priority: optional
Section: php
Source: php-defaults (76)
Origin: Ubuntu
Maintainer: Ubuntu Developers
Original-Maintainer: Debian PHP Maintainers
Installed-Size: 13,3 kB
Depends: php7.4
Download-Size: 2.772 B
APT-Manual-Installed: yes
APT-Sources: groovy/main amd64 Packages
Description: server-side, HTML-embedded scripting language (default)
PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used
open source general-purpose scripting language that is especially suited
for web development and can be embedded into HTML.
This package is a dependency package, which depends on latest stable
PHP version (currently 7.4).

Install PHP

We can install the PHP package with the “apt install” command providing the php as the package name. Installing packages in Linux requires the root privileges which can be provided with the sudo command like below.

$ sudo apt install php

But if you are not in the sudoers group and can not use the sudo command you can log in as root and use “apt install” like below without sudo command.

$ apt install php

Remove PHP

If you do not need any more the PHP package you can remove it easily with the “apt remove” command. Like the install the removal also requires the root privileges which can be provided with the “sudo” command.

$ sudo apt remove php

If you are already logged as the root user and do not have the sudoers right use the following command from the root user bash shell.

$ apt remove php

The “apt remove” will only remove the package files like binaries, libraries or executables. But if you also need to remove the PHP configuration files you should purge PHP like below.

$ sudo apt purge php

Leave a Comment