Building a powerful web development environment can only start with learning how to install PHP 8 on Ubuntu. PHP comes with unprecedented performance improvements, modern syntax, and better error handling that make it a preferred choice by developers in every part of the world. Be it for setting up a personal project or configuring a production server, getting PHP 8 installed with all its dependencies will ensure that everything runs smoothly.
Ubuntu is one of the most developer-friendly Linux distributions, offering the easiest ways to install PHP 8 and manage its extensions. This tutorial shows, how to install PHP 8 on Ubuntu and add common extensions used in real-world applications.
Installing PHP 8 in Ubuntu Operating System
Before installing PHP 8, we will make sure your system is up to date with other ubuntu updates. Run the following commands in your terminal:
sudo apt update
sudo apt upgrade -yNext, add the Ondrej PHP repository, which includes the latest stable PHP versions:
sudo add-apt-repository ppa:ondrej/php -y
sudo apt updateWith this setup, you can install any specific PHP version like 8.0, 8.1, 8.2 or 8.4. In this example, we will install PHP 8 using terminal command:
sudo apt install php8.0 -yHere, you have selected PHP8 and with -y flag it will no ask repeat confirmation about file size and all.
It will take some time to install. Once installed you can verify using below command:
php -vYou will see the output confirm that PHP 8 installed successfully. This setup provides a solid foundation to run modern PHP applications on Ubuntu.
Installing Necessary Extensions for PHP in Ubuntu
To get the best out of PHP 8, install popular extensions. They add database support, improve performance, and enable image processing. Some commonly used ones include php8.0-mysql, php8.0-curl, php8.0-xml, php8.0-mbstring, and php8.0-zip and etc.
sudo apt install php8.0-mysql php8.0-curl php8.0-xml php8.0-mbstring php8.0-zip php8.0-json php8.0-pgsql php8.0-sqlite3 php8.0-zlib php8.0-libxml php8.0-gd php8.0-fpm -yThese extensions are widely used in real-world projects or even some frameworks like Laravel or CI. For instance, php8.0-mysql allows you to connect PHP with MySQL databases, and moreover, php8.0-curl helps you integrate APIs and fetch data from external sources.
Installing them prepares your development or production environment for almost any PHP-based application. Database extensions like pgsql and sqlite integrate different types of databases into your PHP applications.
You can verify the installation of extensions by running below command:
php -mIt will lists all enabled PHP modules, confirming that your setup is complete.
Conclusion
A full PHP 8 installation on Ubuntu, complete with dependencies, provides developers with a stable and optimized environment in which to build dynamic applications. Due to the performance boost entailed in PHP 8 and considering Ubuntu’s reliability, this combination offers a perfect setup both for beginners and professionals.
Once you’ve installed the necessary extensions, you’re ready to create, deploy, and manage high-performance web applications with confidence. Explore our guide on Function in PHP with Types to learn how to write type-safe and efficient functions for your PHP projects.

