Logo
  • Ubuntu
  • CentOS
  • Debian
  • Fedora
  • RedHat

How to Install PHP 8.0 on Ubuntu 20.04 / 18.04 - DesignLinux

Dec 09 2020
designlinux 0 Comments

PHP is arguably one of the most widely used server-side programming languages. It’s the language of choice when developing dynamic and responsive websites. In fact, popular CM platforms such as WordPress, Drupal, and Magento are based on PHP.

At the time of penning down this guide, the latest version of PHP is PHP 8.0. It was released on November 26, 2020. It boasts of new features and optimizations such as union types, named arguments, null safe operator, match expression, JIT, and improvements in error handling and consistency.

This tutorial walks you through the installation of PHP 8.0 on Ubuntu 20.04 / 18.04.

On this page

  • Add the Ondřej Surý PPA Repository on Ubuntu
  • Install PHP 8.0 with Apache on Ubuntu
  • Install PHP 8.0 with Nginx on Ubuntu
  • Install PHP 8 Extensions in Ubuntu
  • Verify PHP 8 Installation in Ubuntu

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

PHP 7.4 is the default PHP version in Ubuntu 20.04 repositories at the time of writing this tutorial. To install the latest version of PHP, we are going to use the Ondrej PPA repositories. This repository contains multiple PHP versions and PHP extensions.

But first, let’s update your Ubuntu system packages and install some dependencies as shown.

$ sudo apt update
$ sudo apt upgrade
$ sudo apt install  ca-certificates apt-transport-https software-properties-common

Next, add the Ondrej PPA.

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

When prompted, press ENTER to proceed with adding the repository.

Add Ondrej PPA
Add Ondrej PPA

Step 2: Install PHP 8.0 with Apache on Ubuntu

Next, update the system repositories to start using the PPA.

$ sudo apt update

If you are running the Apache web server, install PHP 8.0 with the Apache module as shown.

$ sudo apt install php8.0 libapache2-mod-php8.0 
Install PHP 8 in Ubuntu
Install PHP 8 in Ubuntu

Next, restart the Apache webserver to enable the module.

$ sudo systemctl restart apache2

If you want to use Apache webserver with PHP-FPM, run the command below to install the required packages:

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

Since PHP-FPM is not enabled by default, enable it by invoking the following commands:

$ sudo a2enmod proxy_fcgi setenvif
$ sudo a2enconf php8.0-fpm

Then restart the Apache webserver for the changes to come into effect.

$ sudo systemctl restart apache2
Enable PHP-FPM in Apache
Enable PHP-FPM in Apache

Step 2: Install PHP 8.0 with Nginx on Ubuntu

If you choose to use PHP 8.0 with Nginx installation, the most recommended step to take is to install PHP-FPM to process PHP files.

Therefore, install PHP and PHP-FPM using the following command:

$ sudo apt install php8.0-fpm

The PHP-FPM service should start automatically. You can verify this as shown:

$ sudo systemctl status php8.0-fpm
Verify PHP-FPM in Nginx
Verify PHP-FPM in Nginx

For Nginx to process PHP files, configure your Nginx server block by updating the server section as shown:

server {

   # ... some other code

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

Finally, restart the Nginx web server for the changes to come into effect.

$ sudo systemctl restart nginx

Step 4: Install PHP 8 Extensions in Ubuntu

PHP extensions are libraries that extend the functionality of PHP. These extensions exist as packages and can be installed as follows:

$ sudo apt install php8.0-[extension-name]

For instance, the example below installs the SNMP, Memcached, and MySQL extensions.

$ sudo apt install php8.0-snmp php-memcached php8.0-mysql

Step 5: Verify PHP 8 Installation in Ubuntu

To confirm the version of PHP installed, run the command:

$ php -v
Verify PHP in Ubuntu
Verify PHP in Ubuntu

Additionally, you can create a sample php file at /var/www/html as shown:

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

Paste the following lines and save the file.

<?php

phpinfo();

?>

Finally, head over to your browser and browse the server’s IP address as shown.

http://server-ip/info.php

You should get the webpage shown.

Check PHP 8 Info in Ubuntu
Check PHP 8 Info in Ubuntu
Conclusion

It’s our hope that you can now install PHP 8.0 and comfortably integrate it with either Apache or Nginx web servers. Your feedback is most welcome.

Related

Tags: PHP Tips, Ubuntu Tips

How to Boot into Rescue Mode Or Emergency Mode In Ubuntu 20.04 / 18.04

Prev Post

Chattr Command in Linux (File Attributes)

Next Post
Archives
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • July 2022
  • June 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
Categories
  • AlmaLinux
  • Android
  • Ansible
  • Apache
  • Arch Linux
  • AWS
  • Backups
  • Bash Shell
  • Bodhi Linux
  • CentOS
  • CentOS Stream
  • Chef
  • Cloud Software
  • CMS
  • Commandline Tools
  • Control Panels
  • CouchDB
  • Data Recovery Tools
  • Databases
  • Debian
  • Deepin Linux
  • Desktops
  • Development Tools
  • Docker
  • Download Managers
  • Drupal
  • Editors
  • Elementary OS
  • Encryption Tools
  • Fedora
  • Firewalls
  • FreeBSD
  • FTP
  • GIMP
  • Git
  • Hadoop
  • HAProxy
  • Java
  • Jenkins
  • Joomla
  • Kali Linux
  • KDE
  • Kubernetes
  • KVM
  • Laravel
  • Let's Encrypt
  • LFCA
  • Linux Certifications
  • Linux Commands
  • Linux Desktop
  • Linux Distros
  • Linux IDE
  • Linux Mint
  • Linux Talks
  • Lubuntu
  • LXC
  • Mail Server
  • Manjaro
  • MariaDB
  • MongoDB
  • Monitoring Tools
  • MySQL
  • Network
  • Networking Commands
  • NFS
  • Nginx
  • Nodejs
  • NTP
  • Open Source
  • OpenSUSE
  • Oracle Linux
  • Package Managers
  • Pentoo
  • PHP
  • Podman
  • Postfix Mail Server
  • PostgreSQL
  • Python
  • Questions
  • RedHat
  • Redis Server
  • Rocky Linux
  • Security
  • Shell Scripting
  • SQLite
  • SSH
  • Storage
  • Suse
  • Terminals
  • Text Editors
  • Top Tools
  • Torrent Clients
  • Tutorial
  • Ubuntu
  • Udemy Courses
  • Uncategorized
  • VirtualBox
  • Virtualization
  • VMware
  • VPN
  • VSCode Editor
  • Web Browsers
  • Web Design
  • Web Hosting
  • Web Servers
  • Webmin
  • Windows
  • Windows Subsystem
  • WordPress
  • Zabbix
  • Zentyal
  • Zorin OS
Visits
  • 0
  • 259
  • 614,631

DesignLinux.com © All rights reserved

Go to mobile version