Install PHP 8.0 for Apache and Nginx on Ubuntu 20.04

29 January 2021

Install PHP 8.0 for Apache and Nginx on Ubuntu 20.04

To have your Ubuntu 20.04 server installed with the latest version of PHP is actually really easy. And I mean, super easy. See for yourself by reading the rest of this article. The only thing that has to be done is add the well-known Ondrej repository, like this:

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

Install PHP8 as module for Apache

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

Don't forget to restart Apache after this:

sudo systemctl restart apache2

Setup PHP-FPM for Apache

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

Afterward, you'll need to enable the modules for Apache like this:

sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.0-fpm
sudo systemctl restart apache2

Installing PHP 8.0 for Nginx

Nginx doesn't have inbuilt support for PHP so we'll just use fpm and have it run as a separate service.

sudo apt install php8.0-fpm

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

server {
    # . . . your other code

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

We must also edit the php.ini for php-fpm for use with Nginx. This is not required if you only use Apache.

sudo nano /etc/php/8.0/fpm/php.ini

Search for "cgi.fix_pathinfo" (it's on line 807 approx) and uncomment this line and change the variable to "0" so it looks like this:

cgi.fix_pathinfo=0

Save the file and restart the php-fpm process. And of course we'll need to restart Nginx to load this new config we changed earlier.

sudo systemctl restart nginx php8.0-fpm

Installing additional PHP extensions

PHP can be enhanced by installing some PHP extensions, although this is not required. A lot of extensions exist, and it is for you to decide if you need this functionality. As an example, we'll install these handful of very popular extensions.

sudo apt install -y php8.0 php8.0-common php8.0-gd php8.0-mysql php8.0-imap php8.0-cli php8.0-cgi php8.0-curl php8.0-intl php8.0-pspell php8.0-sqlite3 php8.0-tidy php8.0-xmlrpc php8.0-xsl php8.0-zip php8.0-mbstring php8.0-soap php8.0-opcache php-pear php-imagick php-apcu

Test it out

Let's see if it works! Create a new file in your web server's root folder.

sudo nano /var/www/html/info.php

Paste this one line of code in the new file and save it:

<?php phpinfo();

To set the proper user and group, use this command

sudo chown -R www-data:www-data /var/www/html

Now open a browser and go to this address: http://your_server_ip/info.php
You'll see a page looking like the screenshot below. This means it's working! Good job!

Pick a star to rate this
Table of Contents

Leave a Reply

Your email address will not be published. Required fields are marked *

Unrelated Content

26 June 2025
Why Self-Hosting Your Livestream Is Safer, Cheaper, and More Flexible Than Commercial Platforms

With livestreaming more popular than ever, platforms like YouTube Live, Twitch, Vimeo, and Facebook Live have become household names. But are they really the best option for everyone? If you're a tech-savvy creator, a privacy-conscious broadcaster, or someone who just wants full control, self-hosting your own livestream server might be a better choice. In this […]

READ MORE
27 November 2020
Motivation behind this website

For every service that is offered for a lot of money on the internet, there's always a free or much cheaper alternative, especially if you embrace open-source software. For live-streaming this is also very much the case. We love that,

READ MORE
23 January 2021
Introduction to the new how-to article in the Knowledge Base.

I wrote a new guide on setting up your own live-stream server. Mostly due to your requests. I took the opportunity to simplify and shorten the guide a bit. If you follow this guide step by step, and use your brain a tiny bit, you'll be fine. This guide has so far been tested on […]

READ MORE
25 January 2021
Optimizing First-Frame Bitrate for HLS

When responding to an HLS request, the streaming server determines which video quality (i.e., ts file) the client will attempt to play before switching to a lower or higher quality video. This switch depends on available bandwidth and device type. Switching to the wrong quality first degrades the user experience considerably. For instance, sending a […]

READ MORE
25 January 2021
Adaptive Bit-rate Streaming

“What is adaptive streaming?” This question often leads to answers filled with technical terms like “HLS”, “MPEG-DASH”, “segments” and “codec“. This article is written for people who need to understand the principles, but don’t need to actually implement the technology. If you are looking for specific technical information on adaptive streaming then I recommend you read up on it on this website and elsewhere.

READ MORE
2 February 2021
About Bradmax Video Player WordPress plugin

Let's talk about our favorite video player plugin for WordPress. Here are some reasons why Bradmax Player is our favorite. And below that are detailed instructions on how to set it up. Setting it up may at first seem a bit awkward, but it really isn't. First you must obviously install the Bradmax Player plugin […]

READ MORE
Copyright © 2025. 
All rights reserved.
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram