How To Install PHP 8 on Ubuntu 20.04 LTS

Install PHP 8 on Ubuntu 20.04

In this tutorial, we will show you how to install PHP 8 on Ubuntu 20.04 LTS. For those of you who didn’t know, PHP (recursive acronym for PHP: Hypertext Preprocessor) is a popular server scripting language known for creating dynamic and interactive Web pages. PHP is a widely-used programming language on the Web.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you through the step by step installation of PHP 8 on Ubuntu 20.04 (Focal Fossa). You can follow the same instructions for Ubuntu 18.04, 16.04, and any other Debian based distribution like Linux Mint.

Install PHP 8 on Ubuntu 20.04 LTS Focal Fossa

Step 1. First, make sure that all your system packages are up-to-date by running the following apt commands in the terminal.

sudo apt update
sudo apt upgrade
sudo apt install software-properties-common

Step 2. Installing PHP 8 on Ubuntu 20.04.

Now we add a third-party PPA to Ubuntu:

sudo add-apt-repository ppa:ondrej/php

Then, you can update the packages cache in the system and install PHP packages:

sudo apt update
sudo apt install php8.0 libapache2-mod-php8.0

After installing, you can restart Apache using the following commands:

sudo systemctl restart apache2

Once successfully installed, you can confirm the using the following command:

$ php -v
HP 8.0.0RC3 (cli) (built: Nov 26 2020 19:06:36) ( NTS )
Copyright (c) The PHP Group
   Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
   with Zend OPcache v8.0.0RC3, Copyright (c), by Zend Technologies

Step 3. Installing PHP 8 Extensions.

To install PHP 8 extensions on Ubuntu 20.04 using the command syntax:

sudo apt install php8.0-[extension]

Some available extensions are as shown below:

$ sudo apt install php8.0-

php8.0-amqp       php8.0-common     php8.0-gd         php8.0-ldap       php8.0-odbc       php8.0-readline   php8.0-sqlite3    php8.0-xsl
php8.0-apcu       php8.0-curl       php8.0-gmp        php8.0-mailparse  php8.0-opcache    php8.0-redis      php8.0-sybase     php8.0-yac
php8.0-ast        php8.0-dba        php8.0-igbinary   php8.0-mbstring   php8.0-pgsql      php8.0-rrd        php8.0-tidy       php8.0-yaml
php8.0-bcmath     php8.0-dev        php8.0-imagick    php8.0-memcached  php8.0-phpdbg     php8.0-smbclient  php8.0-uuid       php8.0-zip
php8.0-bz2        php8.0-ds         php8.0-imap       php8.0-msgpack    php8.0-pspell     php8.0-snmp       php8.0-xdebug     php8.0-zmq
php8.0-cgi        php8.0-enchant    php8.0-interbase  php8.0-mysql      php8.0-psr        php8.0-soap       php8.0-xhprof
php8.0-cli        php8.0-fpm        php8.0-intl       php8.0-oauth      php8.0-raphf      php8.0-solr       php8.0-xml

An example to install a few more useful extensions:

sudo apt install php8.0-cli php8.0-common php8.0-fpm php8.0-redis php8.0-snmp php8.0-xml

Step 4. Test PHP.

To test PHP, create a text file named info.php with the content below. Save the file, then browse to it to see if PHP is working:

nano /var/www/html/info.php

In this file, paste the following code:

<?php
phpinfo();
?>

Try to access it at http://ip-address/info.php. If the PHP info page is rendered in your browser then everything looks good and you are ready to proceed further.

Congratulations! You have successfully installed PHP. Thanks for using this tutorial for installing the latest version of PHP (Hypertext Preprocessor) 8 on Ubuntu 20.04 LTS (Focal Fossa) system. For additional help or useful information, we recommend you to check the official PHP website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!