Linux VPSPHPUbuntu

How to Install PHP 8.2 on Ubuntu: A Comprehensive Guide

In our previous posts, we’ve discussed the fundamental process of installing PHP on an Ubuntu system and delved into the specifics of installing PHP 7.4. If you haven’t had the chance to read those guides, we recommend checking them out as they provide valuable background information on the installation process. Now, it’s time to explore the installation of a more recent version of PHP, PHP 8.2. This comprehensive guide will take you through the step-by-step process of installing PHP 8.2 on your Ubuntu system.

Reference Posts:

  1. How to Installing PHP on Ubuntu: A Comprehensive Guide
  2. How to Install PHP 7.4 on Ubuntu: A Comprehensive Guide
  3. How to Install PHP 8.0 on Ubuntu: A Comprehensive Guide

Prerequisites:

Before we begin, make sure you have the following prerequisites:

  1. An Ubuntu server or desktop system (this guide is based on Ubuntu 20.04 LTS, but the process should be similar for other versions).
  2. Access to a terminal with administrative privileges (you can use the terminal emulator or SSH).

Let’s get started!

Step 1: Update Your System

As a best practice, ensure your system is up to date before installing any software. Open your terminal and run the following commands:

sudo apt update

The sudo apt update command refreshes the package information on a Debian-based Linux system, ensuring that your system’s package manager has the latest information about available packages and their versions from the configured software repositories.

Next, upgrade your system by running:

sudo apt upgrade

The sudo apt upgrade command is used to upgrade the installed packages on a Debian-based Linux system, such as Ubuntu. This command searches for updates to your installed packages and prompts you to confirm the upgrade. Regularly running this command keeps your system up to date with the latest software updates and security patches.

Step 2: Add a PPA Repository

To manage multiple PHP versions, we’ll use the Ondřej Surý PPA repository, which provides a range of PHP versions, including PHP 8.2. First, add this repository to your system:

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

Step 3: Install PHP Version 8.2

You will need some knowledge of PHP to install the PHP version. In your case you may need different PHP versions. But from our previous post we get the idea that PHP vs PHP-FPM. If you haven’t seen my previous post, click here

To install PHP 8.2 FPM, you’d run:

sudo apt install php8.2-fpm

Or if you don’t want to install PHP-FMP version then follow this command:

sudo apt install php8.2

This command will download and install PHP 8.2, along with any necessary dependencies. Confirm the installation by typing “Y” when prompted.

Step 4: Install PHP Extensions

PHP extensions enhance the functionality of your PHP installation. To install extensions, use the apt package manager. Here’s an example of how to install the MySQL extension for PHP:

sudo apt install php8.2-mysql

You can replace mysql with the name of the extension you need. Some common PHP extensions for PHP 8.2 include gd for GD graphics library, curl for cURL support, xml for XML support, libapache2 for apache2 and json for JSON support. You can install multiple extensions in one command by listing them with spaces.

sudo apt install php8.2-cli libapache2-mod-php8.2 php8.2-common php8.2-curl php8.2-mbstring php8.2-opcache php8.2-readline php8.2-xml php8.2-zip php8.2-mysql php8.2-gd

Step 5: Switching Between PHP Versions

To switch between PHP versions, use the update-alternatives command. For example, to set PHP 8.2 as the active version, run:

sudo update-alternatives --set php /usr/bin/php8.2

Verify the active PHP version with:

php -v

Step 6: Configuring Web Servers

If you’re running web applications, configure your web server to use the desired PHP version. For Apache, you can enable PHP 8.2 as follows:

Disable your current PHP version and then enable PHP 8.2 for the Apache server.

Here are the corrected commands:

For example, if your current PHP version is PHP 7.4:

sudo a2dismod php7.4

And then enable PHP 8.2 for the Apache server:

sudo a2enmod php8.2
For Nginx, you’ll need to configure your Nginx virtual host files to use PHP 8.2.

Conclusion:

In this guide, we’ve walked you through the process of installing PHP 8.2 on your Ubuntu system. PHP 8.2 brings new features and improvements, making it an excellent choice for web development projects. By following these steps, you can have PHP 8.2 up and running on your Ubuntu machine, ready to power your web applications.

If you encounter any questions or issues during the installation process, refer to our previous posts for a deeper understanding of PHP installation on Ubuntu. Happy coding!

IQBAL HASAN

I love to talk on trending ⚡ technology ⚡, I have huge attraction on 😁 Linux 😅 and I am a bit 😄 mad 😄 when I code.

Related Articles

Leave a Reply

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

Back to top button