Hamsa K
Editor
7 min read | 3 years ago

How to Install PHP 8 on Ubuntu 20 04

Install PHP8 on Ubuntu 20.04

PHP is a general-purpose scripting language especially suited to web development to create dynamic websites such as E-commerce sites, Blogs, and frameworks such as WordPress, Magento, and Laravel are written in PHP.

A the time of writing this article php 8 is the latest version and released on 26th November 2020.It having many new features like named arguments, null safe operator, match expression, JIT, union types etc.

In this tutorial we will see how to install php8.0 on ubuntu 20.04 system.

First we will update packages using apt.

sudo apt update
sudo apt install software-properties-common

Also Read -> How to Install PHP 7.4 on Centos 8

Next, add below PPA repository to the system.

sudo add-apt-repository ppa:ondrej/php

when it prompts,press Enter to continue.

then update the packages cache and install php 8 along with apache module.

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

once it is installed check php version with following command.

php -v

output:

PHP 8.0.0 (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.0, Copyright (c), by Zend Technologies

Then install required php extensions as below.

sudo apt install php8.0-cli php8.0-common php8.0-bcmath php8.0-mbstring php8.0-mysql php8.0-soap php8.0-gd php8.0-xml

Now restart webserver to enable php module.

systemctl restart apache2

Also Read -> How to Install PHP 7.4 on Ubuntu 18 04

Apache with php-fpm

php-fpm is the FastCGI process manager for Php.if you want to use php-fpm with apache then run the following command.

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

enable php-fpm in apache with the following command.

sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.0-fpm

Then restart apache service using systemctl.

systemctl reload apache2

Also Read -> How to Install PHP 8 on Centos 8

nginx with php-fpm

First we need to install nginx and to have PHP support for Nginx, we can use the PHP FastCGI Process Manager to handle PHP requests.

apt install nginx php8.0-fpm

 PHP-FPM service should start automatically and to check status service.

systemctl status nginx
systemctl status php8.0-fpm
 php8.0-fpm.service - The PHP 8.0 FastCGI Process Manager
     Loaded: loaded (/lib/systemd/system/php8.0-fpm.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2020-12-15 09:30:13 UTC; 19min ago
       Docs: man:php-fpm8.0(8)
    Process: 11864 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock /etc/php/8.0/fpm/pool.d/www.conf 80 (code=exited, status=0/SUCCESS)
   Main PID: 11852 (php-fpm8.0)
     Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
      Tasks: 3 (limit: 1685)
     Memory: 7.0M
     CGroup: /system.slice/php8.0-fpm.service
             ├─11852 php-fpm: master process (/etc/php/8.0/fpm/php-fpm.conf)
             ├─11862 php-fpm: pool www
             └─11863 php-fpm: pool www
Dec 15 09:30:12 ubuntu20 systemd[1]: Starting The PHP 8.0 FastCGI Process Manager...

To configure server nginx block 

# pass PHP scripts to FastCGI serve
server {
   #----------------
   #----------------
   #----------------
   location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.0-fpm.sock;
    }
}

restart nginx service once

systemctl restart nginx

Also Read -> How to Install CouchDB on Ubuntu 20 04

Test PHP 

you can create one test file in /var/www/html as below.

nano /var/www/html/info.php

Paste below code to above file.

<?php
phpinfo();
?>

save the file and exit.

then,open your favorite browser and type http://ip_address/info.php

Now you have successfully installed php 8.0 on ubuntu 20.04 system.

Also Read -> How to Install CouchDB on Ubuntu 20 04



Warning! This site uses cookies
By continuing to browse the site, you are agreeing to our use of cookies. Read our terms and privacy policy