• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Install PHP 8 on Ubuntu 20.04

Written by Admin, Updated On December 20, 2020
php, ubuntu
How to Install Php 8 on Ubuntu 20.04

PHP is a most popular server scripting language used for creating dynamic and interactive Web pages. PHP is widely-used programming language in the Web. This tutorial explains how to install PHP 8.0 on Ubuntu 20.04 system.

PHP 8.0 is the latest major release and includes performance improvements, and lots of new features such as named arguments, JIT compiler, union types, match expression, and more. By default, Ubuntu 20.04 ships with PHP version 7.4, which is supported by the most popular CMS and frameworks such as WordPress, Magento, and Laravel. We’ll install PHP from the ondrej/php PPA repository.

Before upgrading to or installing PHP 8, make sure that your applications support it.

Enable PHP Repository#

First of all we need to enable the PHP repository, run the below command:

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php

Now, we can go ahead to install PHP 8.

Install PHP 8.0 with Apache#

Apache is the most used web server in the world. If you’re using Apache as a web server, you can run PHP as an Apache module or PHP-FPM.

Install PHP as Apache Module#

It is very easy task to install Apache Module. Run the below commands:

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

After the packages installed, you must restart the Apache to take the effect of changes.

sudo systemctl restart apache2

Configure Apache with PHP-FPM#

Php-FPM is a FastCGI process manager for PHP. Execute the below commands to install:

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

PHP-FPM is not enabled in Apache by default, You should enable it by typing:

sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.0-fpm

To get the changes, restart Apache:

systemctl restart apache2

Installing PHP 8.0 with Nginx#

By default, Nginx doesn’t have a built-in support for processing PHP files. So we need to use PHP FPM service 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

The FPM service will start automatically, once the installation has been finished. You can check the status of the service by typing:

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 Thu 2020-12-20 11:09:17 UTC; 26s ago

After that, you need to edit domain Nginx server block and add following lines to work PHP file using Nginx:

server {

    # . . . other code

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.0-fpm.sock;
    }
}

Save the configuration file and restart the nginx service for the new configuration take effect:

sudo systemctl restart nginx

Installing PHP Extensions#

You can install PHP extensions as per requirements. You can easily install extensions using apt package manager in following form:

sudo apt install php8.0-[extname]

For example, to install CLI and PDO extensions, you would run the following command:

sudo apt install php8.0-cli php8.0-pdo

Again, restart the Apache or PHP FPM service as per your setup.

Testing PHP#

Once the installation complete, you can verify version by typing:

php --version
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

Conclusion#

This tutorial shown you how to install PHP 8.0 and configure with Apache and Nginx on your Ubuntu 20.04 system.

If you have any questions or feedback, please leave a comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Install GIMP 2.10 on Debian 10
Next Article   How to Install GIMP 2.10 on CentOS 8

Related Posts

  • How to Install Apache, MySQL, PHP (LAMP) on Ubuntu 22.04

    How to Install LAMP on Ubuntu 22.04

    March 20, 2023
  • How to Install LEMP Stack on Ubuntu 22.04

    How to Install LEMP Stack on Ubuntu 22.04

    March 18, 2023
  • How to Install Memcached on Ubuntu 22.04

    How to Install Memcached on Ubuntu 22.04

    March 16, 2023

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install Microsoft Edge Browser on Ubuntu 22.04
    How to Install Microsoft Edge Browser on Ubuntu 22.04 March 14, 2023
  • How to Install Ruby on Ubuntu 22.04 LTS
    How to Install Ruby on Ubuntu 22.04 LTS February 27, 2023
  • How to Install LEMP Stack on Ubuntu 22.04
    How to Install LEMP Stack on Ubuntu 22.04 March 18, 2023
  • How to Install Set Up Apache Virtual Hosts on Ubuntu 22.04
    How to Set Up Apache Virtual Hosts on Ubuntu 22.04 March 2, 2023
  • How to Install MariaDB on Debian 11 Bullseye
    How to Install MariaDB on Debian 11 Bullseye March 8, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook