Install PHP 8 on linux, ubunti, mint, debian, etc.

Installing PHP 8+ on Ubuntu 20.04


PHP 8 is the latest stable release of PHP. Thank comrade Ondřej Surý for maintaining a PPA repository with all popular versions of PHP on launchpad.

If you want to install a specific version of PHP, this article will help you in this difficult task. In this article you will learn how to install PHP 8.0, PHP 7.4, 7.3, 7.2, 7.1 and PHP 7.0 on Ubuntu 20.04, 18.04 and 16.04 LTS using PPA.

Installing PHP

# Installing a missing package
sudo apt-get install software-properties-common
# Adding a repository to the system
sudo add-apt-repository ppa:ondrej/php
# Updating the list of packages
sudo apt-get update
# Installing РНР8.0
sudo apt-get install -y php8.0

# or РНР7.4
sudo apt-get install -y php7.4
# or РНР7.3
sudo apt-get install -y php7.3
# or РНР7.2
sudo apt-get install -y php7.2
# or РНР7.1
sudo apt-get install -y php7.1
# or РНР7.0
sudo apt-get install -y php7.0

Checking the PHP version

Run the following command to check the installed version of PHP:

php -v
PHP 7.4.5 (cli) (built: Apr 28 2020 14:49:23) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.5, Copyright (c), by Zend Technologies

Installing PHP Modules

You may also need to install certain modules, depending on the requirements of the application you are developing. Use the command below to find available PHP 7 modules in the package repository:

# for php8* version
sudo apt-cache search php8*

# for php7* version
sudo apt-cache search php7*

We get roughly the following:

php-all-dev - package depending on all supported PHP development packages
php7.0 - server-side, HTML-embedded scripting language (metapackage)
php7.0-cgi - server-side, HTML-embedded scripting language (CGI binary)
php7.0-cli - command-line interpreter for the PHP scripting language
php7.0-common - documentation, examples and common module for PHP
php7.0-curl - CURL module for PHP
php7.0-dev - Files for PHP7.0 module development
php7.0-gd - GD module for PHP
php7.0-gmp - GMP module for PHP
php7.1-xml - DOM, SimpleXML, WDDX, XML, and XSL module for PHP
php7.1-xmlrpc - XMLRPC-EPI module for PHP
php7.1-zip - Zip module for PHP
php7.1-opcache - Zend OpCache module for PHP
php7.1 - server-side, HTML-embedded scripting language (metapackage)
php7.1-xsl - XSL module for PHP (dummy)
php7.2-bcmath - Bcmath module for PHP
php7.2-bz2 - bzip2 module for PHP
php7.2-cgi - server-side, HTML-embedded scripting language (CGI binary)
php7.2-cli - command-line interpreter for the PHP scripting language
php7.2-common - documentation, examples and common module for PHP
php7.2-curl - CURL module for PHP
php7.2-dba - DBA module for PHP

From the output of the command above, copy the names of the modules needed for our version of PHP and put them into the system.

sudo apt-get install php7.2-mysql php7.2-curl php7.2-json php7.2-cgi php7.2-xsl
If you do not specify the exact version of the module in the name, the latest build of the package from the repository will be installed.
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like