Install PHP 8 on Ubuntu 20.04 or 18.04 - Step by Step Process ?







A powerful scripting language for web development, we can execute PHP on a Linux, Windows, macOS, and Unix system with PHP runtime installed.

PHP is one of the most widely used server-side programming languages. Many popular CMS and frameworks such as WordPress, Magento, and Laravel are written in PHP.

The latest version to this day of PHP is PHP 8.0 and was released on November 26, 2020.

In it you can find many new features. PHP 8.0 is a major update to the PHP language that contains new features and optimizations. 

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related PHP queries.

In this context, we shall look into how to install PHP 8.0 on the Ubuntu Linux system.


How to install PHP 8 on Ubuntu 20.04/Ubuntu 18.04 ?

To perform this installation procedure, follow the steps given below.


1. System Update

First and foremost, we need to update all system packages to the latest. For that, we run the commands below:

$ sudo apt update
$ sudo apt -y upgrade

Also perform a reboot after an upgrade:

$ sudo systemctl reboot


2. Add Ondrej Sury PPA repository

The latest PHP packages are available in the Ondrej Sury PPA repository. We run the commands below to add this repository to the Ubuntu system:

$ sudo apt update
$ sudo apt install lsb-release ca-certificates apt-transport-https software-properties-common -y
$ sudo add-apt-repository ppa:ondrej/php

Then hit the enter key when it prompts us to add the repository.

Here, from the update output, we can see the repositories added:


Get:5 http://ppa.launchpad.net/ondrej/php/ubuntu focal InRelease [23.9 kB]
Get:10 http://ppa.launchpad.net/ondrej/php/ubuntu focal/main amd64 Packages [74.8 kB]
Get:11 http://ppa.launchpad.net/ondrej/php/ubuntu focal/main i386 Packages [20.2 kB]
Get:12 http://ppa.launchpad.net/ondrej/php/ubuntu focal/main Translation-en [28.2 kB]
Fetched 147 kB in 1s (158 kB/s)
Reading package lists… Done


3. Install PHP 8 on Ubuntu 20.04|18.04

Here, we update the APT index just to ensure it is ready for package installation:

$ sudo apt update

Then we install PHP 8.0 on Ubuntu 20.04|18.04 Linux machine:

$ sudo apt install php8.0

Eventually, hit the 'y' key to start the installation.

Then we confirm the default PHP version on the server:

$ php -v
PHP 8.0.0RC3 (cli) (built: Oct 31 2020 17:06:41) ( 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


4. Install PHP 8 Extensions on Ubuntu 20.04|18.04

To install PHP 8 extensions on Ubuntu 20.04|18.04, we use the command syntax:

$ sudo apt install php8.0-<extension>

For example,

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

We can use the same format to install other extensions.


How to resolve Common error encountered while installing PHP 8 on Ubuntu Linux System ?

In addition, an error we may come across is:

Error: Unable to locate package

This error occurs when we try to install a dependency.

In such a case, we have to install the most recent version of the required dependency from Debian packages.


[Failed to finish PHP installation on Ubuntu? We'd be of assistance. ]


Conclusion

This article covers steps to install PHP 8 on Ubuntu. PHP is arguably one of the most widely used server-side programming languages. It's the language of choice when developing dynamic and responsive websites. Basically, popular CM platforms such as WordPress, Drupal, and Magento are based on PHP.


To Install PHP as Apache Module

Run the commands:

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

Once the packages are installed, restart Apache for the PHP module to get loaded:

$ sudo systemctl restart apache2


To Configure Apache with PHP-FPM

Php-FPM is a FastCGI process manager for PHP. 

1. Run the following command to install the necessary packages:

$ sudo apt update
$ sudo apt install php8.0-fpm libapache2-mod-fcgid

2. By default PHP-FPM is not enabled in Apache. 

To enable it, run:

$ sudo a2enmod proxy_fcgi setenvif
$ sudo a2enconf php8.0-fpm

3. To activate the changes, restart Apache:

$ systemctl restart apache2 


To install PHP 8.0 with Nginx

Nginx doesn't have built-in support for processing PHP files. We'll use PHP-FPM ("fastCGI process manager") to handle the PHP files.

Run the following commands to install PHP and PHP FPM packages:

$ sudo apt update
$ sudo apt install php8.0-fpm

Once the installation is completed, the FPM service will start automatically. 

To check the status of the service, run

$ systemctl status php8.0-fpm

Do not forget to restart the Nginx service so that the new configuration takes effect:

$ sudo systemctl restart nginx

For Linux Tutorials

We create Linux HowTos and Tutorials for Sys Admins. Visit us on LinuxAPT.com

Also for Tech related tips, Visit forum.outsourcepath.com or General Technical tips on www.outsourcepath.com



Related Posts






Focus on your business, not your servers.

Click Here to Learn More






Recent Post