Trending News


How To Install PHP 8 on Ubuntu 18.04 / 20.04 [ Easy Guide ]

How To Install PHP 8 on Ubuntu 18.04 / 20.04 [ Easy Guide ] 

Php 8 on ubuntu

One of the most popular server-side programming languages is PHP. This guide will show you how to install PHP 8.0 on Ubuntu 18.04 / 20.04. When creating dynamic and responsive websites, it is the language of choice.

PHP empowers many major CMS Platforms like WordPress, Drupal, and Magento. Released on November 26, 2020. Php 8.0 is the latest edition at the time we wrote this guide.

It boasts of several following features and optimizations:
  • JIT Compiler
  • Union Types
  • Named Arguments
  • Null Safe Operator
  • Match Expression
  • Improvements in error handling and consistency

Ubuntu 20.04 repositories are the default version of PHP 7.4 at the time of writing. From the Ondrej/PHP repository, we will install PHP.

Make sure that your apps support it before upgrading to or installing PHP 8. So, let us get started with the guide on installing and using PHP 8.0 on the Ubuntu 18.04 / 20.04 LTS Focal system.


Enable PHP Repository

PHP 7.4 was the default PHP version in Ubuntu 20.04 repositories at the time of writing. We will use the Ondrej PPA repository to install the latest release of PHP. Many PHP versions and PHP extensions are available in this repository.

But first, update your Ubuntu system packages and install certain prerequisites.

After that, add the Ondrej PPA.
To proceed with adding the repository, hit ENTER when prompted.

Install PHP 8.0 on Ubuntu with Apache

If you use Apache as your web server, you can install PHP as an Apache module or PHP-FPM.

Install PHP as an Apache Module

Install Php as an Apache module with the following commands:

Restart Apache after installing the packages to allow the PHP module to load:

Set up Apache using PHP-FPM

PHP’s Php-FPM is a FastCGI process manager. To install the required packages, use the following command:

PHP-FPM is disabled by default in Apache. Run the following command to enable it:
Restart Apache to apply the changes:

Install PHP 8.0 on Ubuntu with Nginx

For the Nginx server, there is no official PHP module. In that case, we will deploy PHP applications via Nginx web servers using PHP-FPM.

As a result, you must first install PHP fpm on your system.
Enable and start the service after the installation is complete.
Then, with the following code, update the Nginx server block configuration.

The above code tells Nginx to use PHP-fpm to handle all files with the “.php” extension.

To apply the changes, restart the Nginx web server.

Install PHP 8 Extensions

PHP extensions are libraries that extend PHP’s functionality. These extensions are available as packages and installed in the following way:

Examples include the SNMP, Memcached, and MySQL extensions installed in the following example.


Verify Php 8 Installation

Run the following command to verify the version of PHP you have installed:
You can also make a sample PHP file in /var/www/HTML like shown:
Save the file after pasting the lines mentioned below:
Finally, open your browser and type in the IP address of the server as shown:
You should see the following webpage.
Php 8 on ubuntu Yehiweb

Switch from Default Php Version

You can switch between installed PHP versions on your system quickly. Run the following terminal command:

PHP 8.0 and PHP 7.4 are installed on this system. Select your preferred PHP version.


We hope you can now install PHP 8.0 and easily integrate it with either the Apache or Nginx web servers. Your feedback is much appreciated.

Related posts

Leave a Reply

Required fields are marked *