Home PHP How to Install PHP 8 on Ubuntu 22.04/20.04

How to Install PHP 8 on Ubuntu 22.04/20.04

In terms of popularity and domination in server-side programming, PHP has made a name for itself. It is the go-to programming language for the development of dynamic and responsive web applications and CMS platforms like Magento, Drupal, and WordPress.

Therefore, if you wish to run such web-based applications or host CMS applications on your Ubuntu system, you must consider a proper PHP 8 installation guide.

Installing PHP 8 on Ubuntu Linux

For continued and improved performance of your Ubuntu system, make sure it is up-to-date.

$ sudo apt update && sudo apt upgrade -y

To install the latest PHP 8 version, you need to first remove the existing default PHP 7.4 installation from your Ubuntu 20.04 system by executing the following command.

$ sudo apt remove --purge php
Remove PHP in Ubuntu
Remove PHP in Ubuntu

Next, you need to add the Ondřej Surý PPA repository, which provides the latest installable PHP version for your Ubuntu system. Before adding this repository, install the following priority packages:

$ sudo apt install lsb-release ca-certificates apt-transport-https software-properties-common -y
$ sudo apt install -y language-pack-en-base
$ sudo locale-gen en_US.UTF-8

Now add the Ondřej Surý PPA repository to your Ubuntu system:

$ sudo add-apt-repository ppa:ondrej/php
Add Ondřej Surý PPA in Ubuntu
Add Ondřej Surý PPA in Ubuntu

After adding a repository, once again, run a system update to gauge the preparedness of Ubuntu for the installation of PHP 8.

$ sudo apt update 

Proceed to install PHP 8 via Ubuntu’s APT package manager.

$ sudo apt install php8.1
Install PHP 8 in Ubuntu
Install PHP 8 in Ubuntu

Confirm the installed PHP version on your system.

$ php --version 
Check PHP in Ubuntu
Check PHP in Ubuntu

Installing PHP 8 Extensions on Ubuntu 20.04

Your PHP projects will need the support of numerous PHP extensions to function normally. To install them, reference the following syntax:

$ sudo apt install php8.1-<extension>

For instance, popular PHP extensions like fpm, mysql, and soap can be installed in the following manner.

$ sudo apt install php8.1-{fpm,mysql,soap}
Install PHP Extensions in Ubuntu
Install PHP Extensions in Ubuntu

Happy scripting as you explore what PHP 8.1 has to offer on your Ubuntu system projects.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.