Run and Install PHP 8 on Ubuntu 20.04 – Your Guide 

Run and Install PHP 8 on Ubuntu 20.04 - Your Guide 

Installing PHP 8 on Ubuntu 20.04 is a precise and crucial process, particularly for those seeking to leverage the latest advancements and features offered by this widely used scripting language. With its enhanced performance, improved syntax, and expanded functionality, PHP 8 brings forth numerous benefits that can significantly enhance web development projects. In this blog post, we will guide you through the comprehensive process of how to install PHP 8 on Ubuntu 20.04 system.


To embark on this endeavour, it is essential to ensure that you have access to a terminal window or SSH connection through which you can execute commands. Additionally, it is recommended to have administrative privileges, as certain steps may require administrative access.

What is PHP?

What is PHP?

PHP (Hypertext Preprocessor) is a widely-used server-side scripting language designed for web development. It is primarily used to create dynamic web pages or web applications. It can embed HTML code, interact with databases, manipulate files, handle form data, and perform various server-side tasks. PHP code is executed on the web server and the resulting output is sent to the client’s browser.


One of the main strengths of PHP is its wide integration with web servers, such as Apache and Nginx, and its ability to work with different databases like MySQL, PostgreSQL, and Oracle. It also has an extensive range of built-in functions and a large community that provides numerous libraries, frameworks, and resources to enhance PHP development.


PHP code is typically embedded directly into HTML files, denoted by opening and closing PHP tags: `<?php … ?>`. Additionally, PHP files have a `.php` extension. PHP is known for its simplicity, flexibility, and ease of learning, making it a popular choice among beginners and experienced developers alike.


When was PHP Version 8.0 Released? 

The latest and highly anticipated release of PHP, version 8, occurred on November 26, 2020. This significant milestone in the evolution of PHP brought forth a multitude of new features and enhancements, elevating the language to new heights of performance, stability, and modernity.


PHP 8 introduced a groundbreaking Just-In-Time (JIT) compiler, bringing about substantial performance boosts for numerous web applications. This compiler optimizes the execution of code during runtime, resulting in significant reductions in response times and improvements in overall efficiency.


The timely release of PHP 8 represents a testament to the continued dedication of the PHP community towards enhancing the language’s performance and functionality. By embracing the latest version, developers can leverage its modern features to build exceptional web applications that cater to the ever-evolving demands of today’s digital landscape.

Minimum System Requirements to Install PHP 8 on Ubuntu 20.04

The minimum system requirements for installing PHP 8 on Ubuntu 20.04 are as follows:

  • Operating System: Ubuntu 20.04 LTS (or equivalent Ubuntu-based distribution)
  • Processor: 1 GHz processor or faster
  • Memory: At least 2 GB RAM
  • Disk Space: 50 MB of free disk space for PHP installation
  • Additional Packages: Some additional packages may be required, such as build-essential, libxml2, and libxml2-dev.


It is worth noting that these are the minimum requirements, and the actual system requirements may vary depending on your specific use case and the size of the PHP projects you plan to work on.


How to Install PHP 8 on Ubuntu 20.04?

How to Install PHP 8 on Ubuntu 20.04?

Before commencing the installation, it is prudent to update your system’s package index and upgrade any existing packages to their latest versions. This will help guarantee a smooth installation process and ensure compatibility with PHP 8. Utilize the following commands to perform these actions:

sudo apt update sudo apt upgrade


Once your system is up to date, it is time to add the Ondřej Surý PPA (Personal Package Archive) repository, which provides the PHP packages for Ubuntu. Execute the following command to add the repository:

sudo add-apt-repository ppa:ondrej/php


As the repository is added, it is necessary to update the package index once more to fetch the new package information:


sudo apt update


Subsequently, we can proceed with the actual installation of PHP 8. Execute the following command to install the necessary packages:


sudo apt install php8.0


During the installation, you may be prompted to confirm the installation of additional packages required by PHP 8. Enter ‘Y’ or ‘yes’ to proceed.


After the installation completes successfully, verify the PHP version by executing the following command:


php -v


If PHP 8 is installed correctly, you should see the version information displayed in the terminal output.


How To Install PHP 8 Extensions In Ubuntu? 

In addition to PHP itself, it is crucial to install the most commonly used PHP extensions and modules that align with your specific project requirements. You can search for available extensions using the apt package manager, as shown below:

apt search php8.0-


Browse the list and identify the necessary extensions tailored to your project. Install them individually by executing a command in the following format:


sudo apt install php8.0-<extension-name>


Replace <extension-name> with the actual name of the extension you wish to install.


How to Install PHP 8 with Apache or Nginx?

To ensure proper integration, it is advisable to install PHP 8 alongside a web server such as Apache or Nginx. This allows for seamless execution of PHP scripts within a web environment. If you have not installed a web server yet, execute the relevant installation command based on your preferred choice:


For Apache:


sudo apt install apache2


For Nginx:


sudo apt install nginx


Once the web server is installed, there are additional steps required to connect PHP 8 with the chosen web server. These steps involve configuring the webserver to utilize PHP as a module or as a separate service.


For Apache, execute the following command to install the PHP module:


sudo apt install libapache2-mod-php8.0


For Nginx, install PHP-FPM (FastCGI Process Manager) by running the following command:


sudo apt install php8.0-fpm


Once the installation is complete, you will need to configure the webserver to process PHP scripts correctly. Details on configuring Apache or Nginx to work with PHP are beyond the scope of this text, as they can vary based on individual preferences and project requirements. However, numerous tutorials and documentation resources are available to guide you through the configuration process.


How to Upgrade an Older Version of PHP to PHP 8?

For Ubuntu PHP upgrade to PHP 8 on Ubuntu 20.04, The recommended procedure is as follows:

Update the system packages:


sudo apt update


Remove the existing PHP packages (replace php7.x with the version you currently have installed):


sudo apt remove php7.x-common


Add the Ondrej PHP repository, which provides newer PHP versions:

sudo apt install software-properties-common


Update the packages again to include the new repository:


sudo apt update


Install PHP 8 and required extensions:


sudo apt install php8.0


Verify the installation by checking the PHP version:


php -v

Can I have 2 versions of PHP installed?

Yes, you can have multiple versions of PHP installed on the same system. You can manage these versions with tools like `update-alternatives` in Debian-based systems or `phpbrew` in other systems.

How to install all PHP Packages in Ubuntu?

To install all PHP packages in Ubuntu, you will need to use the `apt-get` command:

  • First, update the package list: `sudo apt-get update`.
  • To install all PHP packages, use the command: `sudo apt-get install php*`. 
  • This will install all packages that start with ‘php’. Be cautious of using this approach as it may include packages you don’t need.


You can replace `php7.2`, `php8.1`, and `php*` with your respective PHP version or required packages. Please also note that the process is very similar for most PHP versions, just replace the version number with the one you want


In conclusion, the installation of PHP 8 on Ubuntu 20.04 facilitates the adoption of the latest advancements and features that this scripting language offers. By following the steps outlined in this article, users can install PHP 8 along with the necessary extensions and integrate it seamlessly with popular web servers. This enables developers to harness the full potential of PHP 8 and embark on innovative web development endeavours efficiently.


  • Share:
Send a Message