How to Install PHP 8.0 on Ubuntu 20.04 LTS

Hey guys, here we will learn how to install PHP 8 on Ubuntu 20.04. Before we start first do update your Ubuntu system packages and install some dependencies as shown.

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

Step 1: Add the Ondřej Surý PPA Repository

Ondřej Surý, a Debian developer, maintains a repository that includes multiple PHP versions. To enable the repository , run the below command:

$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt update

Once the PPA is enabled, you can install PHP 8.

Step 2: Installing PHP 8.0 with

a. Apache
To install PHP 8 with apache2 web server you can run below command.

$ sudo apt install php8.0 libapache2-mod-php8.0
$ service apache2 start
$ service apache2 restart
$ service apache2 status

b. Nginx
To install PHP 8 with Nginx web server you can run below command.

$ sudo apt install php8.0-fpm
$ sudo systemctl status php8.0-fpm
$ sudo systemctl restart nginx

After installing PHP 8 you can verify the installation using the following command:

$ php -vOutput:-PHP 8.0.0RC3 (cli) (built: Nov  27 2020 12:26:22) ( 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: Install PHP 8 Extensions on Ubuntu 20.04

It is important to install some basic common extension for your setup requirement. You can easily install extensions using apt package manager.

apt-get install php8.0-common php8.0-mysql php8.0-xml php8.0-curl php8.0-gd php8.0-imagick php8.0-cli php8.0-dev php8.0-imap php8.0-mbstring php8.0-opcache php8.0-soap php8.0-zip -y

Step 4: Verify PHP 8 Installation on Ubuntu

To verify PHP 8, Create a new info.php file inside the Apache default document root directory /var/www/html/

$ sudo vim /var/www/html/info.php

Add the following line:


Press Esc : wq for save and quit from vim editor

Now restart Apache or Nginx service

$ service apache2 start     OR  $ service nginx start
$ service apache2 stop OR $ service nginx stop
$ service apache2 status OR $ service nginx status
$ service apache2 restart OR $ service nginx restart

Now save and close the file then open your web browser and type the URL http://your-server-ip/info.php. You should see your PHP information page

Congratulations! you have successfully installed PHP 8.0 with Apache and Nginx on Ubuntu 20.04 server.

For more details please visit my website

Im Youtuber