Logo
  • Ubuntu
  • CentOS
  • Debian
  • Fedora
  • RedHat

How to Install PHP 8 on Ubuntu 20.04 - DesignLinux

Dec 03 2020
designlinux 0 Comments

PHP is one of the most widely used server-side programming languages. Many popular CMS and frameworks such as WordPress, Magento, and Laravel are written in PHP.

PHP 8.0 is the latest major release of the PHP language. It introduces several breaking changes, performance improvements, and lots of new features such as named arguments, JIT compiler, union types, match expression, and more.

This article will show you how to install PHP 8 on Ubuntu 20.04 and integrate it with Nginx and Apache.

At the time of writing, the default Ubuntu 20.04 repositories include PHP 7.4 version. We’ll install PHP from the ondrej/php PPA repository.

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

The same steps apply for Ubuntu 18.04 and all Ubuntu-based distribution, including Kubuntu, Linux Mint, and Elementary OS.

Enabling PHP Repository #

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

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

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

Installing PHP 7.4 with Apache #

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 #

Installing PHP as an Apache module is a straightforward task:

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

Once the packages are installed, restart Apache for the PHP module to get loaded:

sudo systemctl restart apache2

Configure Apache with PHP-FPM #

Php-FPM is a FastCGI process manager for PHP. Run the following command to install the necessary packages:

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

By default PHP-FPM is not enabled in Apache. To enable it, run:

sudo a2enmod proxy_fcgi setenvifsudo a2enconf php8.0-fpm

To activate the changes, restart Apache:

systemctl restart apache2

Installing PHP 7.4 with Nginx #

Nginx doesn’t have built-in support for processing PHP files. We’ll use PHP-FPM (“fastCGI process manager”) to handle the PHP files.

Run the following commands to install PHP and PHP FPM packages:

sudo apt updatesudo apt install php8.0-fpm

Once the installation is completed, the FPM service will start automatically. To check the status of the service, run

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-03 16:10:47 UTC; 6s ago

You can now edit the Nginx server block and add the following lines so that Nginx can process PHP files:

server {

    # . . . other code

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

Do not forget to restart the Nginx service so that the new configuration takes effect:

sudo systemctl restart nginx

Installing PHP extensions #

PHP extensions are compiled libraries that extend the core functionality of PHP. Extensions are available as packages and can be easily installed with apt :

sudo apt install php8.0-[extname]

For example, to install MySQL and GD extensions, you would run the following command:

sudo apt install php8.0-mysql php8.0-gd

After installing a new PHP extension, do not forget to restart Apache or PHP FPM service, depending on your setup.

Testing PHP Processing #

To test whether the web server is configured properly for PHP processing, create a new file named info.php inside the /var/www/html directory with the following code:

/var/www/html/info.php
<?php

phpinfo();

Save the file, open your browser, and visit: http://your_server_ip/info.php.

You’ll see information about your PHP configuration similar to the following:

phpinfo Ubuntu

Conclusion #

Installing PHP 8 on Ubuntu 20.04 server is a simple task. All you need to do is to enable the “ondrej/php” repository and install PHP 8 with apt.

If you have any questions or feedback, do not hesitate to leave a comment.

php ubuntu

Related

Tags: php, ubuntu

How to Fix “MySQL ERROR 1819 (HY000):” in Linux

Prev Post

How to Install CDH and Configure Service Placements on CentOS/RHEL 7 – Part 4

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
  • 1
  • 71
  • 574,561

DesignLinux.com © All rights reserved

Go to mobile version