Sunday, November 22, 2026
TR
LinuxOpen Source

Installing PHP 8 on Ubuntu 20.04

Installing PHP 8 on Ubuntu 20.04
Contents
  1. Step 1 – Installing PHP 8 on Ubuntu
  2. Step 2 – Installing PHP Modules
  3. Step 3 – Check the PHP Version
  4. Step 4 – Change the Default PHP Version

PHP stands for "Hypertext Preprocessor" and is a scripting language widely used to develop web applications. It is a server-side language that can be embedded in HTML. It is used to manage dynamic content, databases and session tracking, and even to build entire e-commerce websites.

PHP 8.0 is the latest stable release available for production use. Debian packages for PHP 8 are available for Ubuntu systems under the ppa: ondrej / php PPA .

This tutorial will help you install PHP 8.0 on an Ubuntu 20.04 LTS Focal system.

Step 1 – Installing PHP 8 on Ubuntu

Use the following commands to add the PPA to your Ubuntu 20.04 system and install PHP 8.0.

Enable the PPA – Use the following command

sudo add-apt-repository ppa:ondrej/php 

Update the cache – After enabling the apt repository, update the cache on your system.

sudo apt update 

Install PHP – Next, install PHP 8.0 on the Ubuntu system

sudo apt install php8.0 

Press 'Y' for any confirmation prompted by the installer.

Once you have completed the commands above, you have successfully installed PHP 8.0 on your Ubuntu system.

Step 2 – Installing PHP Modules

Now, install the PHP modules required by your application. Use the following command to search all available PHP 8.0 modules.

sudo apt search php8.0-* 

Then install the required PHP modules. The following command will install some commonly used PHP modules on your system.

sudo apt install php8.0-gd php8.0-xml php8.0-soap php8.0-mbstring php8.0-mysql 

Step 3 – Check the PHP Version

Now use the following command to check the PHP version installed on your system. You can also use other methods to check the PHP version .

php -v 

PHP 8.0.1 (cli) (built: Jan 13 2021 08:22:35) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.1, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.1, Copyright (c), by Zend Technologies

Step 4 – Change the Default PHP Version

You can easily switch between multiple PHP versions installed on any system. Run the following command in the terminal:

sudo updatsudo update-alternatives --config php  

This system has PHP 8.0 and PHP 7.4 installed. Select a PHP version according to your preference.

There are 2 choices for the alternative php (providing /usr/bin/php). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/bin/php8.0 80 auto mode 1 /usr/bin/php7.4 74 manual mode 2 /usr/bin/php8.0 80 manual mode Press to keep the current choice[*], or type selection number: [ENTER CHOICE HERE]

Kerim Koç

Systems and infrastructure engineer. I write about Linux, open source, high availability and security.