Installing Apache and PHP 8.1 on Ubuntu 21.10

Installing Apache and PHP 8.1 on Ubuntu 21.10 x64. This post covers creating an HTTP web server using Apache with the new PHP 8.1 version.

ubuntu 21.10 php 8.1 apache install

You will need sudo permissions for this.

Start by updating the package list with

sudo apt update

Installing Apache HTTP webserver

Once that has finished running, install apache2

sudo apt install apache2

Apache is the number one, open-sourced HTTP server and comes ready to use.

If you have UFW (firewall) running you will need to allow Apache through

sudo ufw allow 'Apache'

You can check Apache’s status with

sudo systemctl status apache2

This will tell you if Apache is running or not.

Installing PHP 8.1

PHP version 8.1 was released November 25th 2021, as of this blog post the latest version is 8.1.1

You may need to install the independent software sources, this can be done with

sudo apt install software-properties-common

This is needed for the latest PHP versions repository

sudo add-apt-repository ppa:ondrej/php

ubuntu 21.10 php 8.1 sourceNow to install PHP 8.1 and the PHP 8.1 module for Apache

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

Installing PHP 8.1 extensions is done in the following format:

sudo apt install php8.1-[extension_name]

An example with a few common extensions

sudo apt install php8.1-{curl,mysql,xml}

Restart Apache

sudo systemctl restart apache2

Check and confirm the PHP version

php -v

ubuntu 21.10 php 8.1 install version