1080*80 ad

PHP 8.4 Upgrade on Ubuntu 22.04 and 24.04

How to Install PHP 8.4 on Ubuntu 22.04 & 24.04: A Step-by-Step Guide

Keeping your development environment up-to-date is crucial for performance, security, and access to the latest language features. PHP 8.4 continues this trend, offering new capabilities and optimizations that developers can leverage. This guide provides a clear, step-by-step process for installing PHP 8.4 on Ubuntu 22.04 (Jammy Jellyfish) and Ubuntu 24.04 (Noble Numbat).

Whether you are setting up a new server or upgrading an existing one, following these instructions will ensure a smooth and successful installation.

Prerequisites: Preparing Your System

Before adding new software, it’s a best practice to ensure your system’s package list and installed packages are current. This helps prevent potential conflicts and ensures a stable foundation.

Open your terminal and run the following commands:

sudo apt update
sudo apt upgrade

This will synchronize your package index files and upgrade any outdated packages on your system.

Step 1: Add the Ondřej Surý PPA

The default Ubuntu repositories often contain older, more stable versions of PHP. To get the very latest release, including PHP 8.4, we need to add a trusted Personal Package Archive (PPA). The most reliable and widely used PPA for PHP on Ubuntu is maintained by Ondřej Surý.

First, install the software-properties-common package, which allows you to manage PPAs easily:

sudo apt install software-properties-common

Next, add the PHP PPA to your system’s software sources:

sudo add-apt-repository ppa:ondrej/php

Press Enter when prompted to confirm the addition of the repository. Your system will automatically run apt update after the PPA is successfully added.

Step 2: Install PHP 8.4 and Common Extensions

With the PPA configured, you can now install PHP 8.4. It’s highly recommended to install not only the core PHP package but also a set of common extensions that most modern web applications, like WordPress or Laravel, require.

Here is a single command to install PHP 8.4 along with several essential extensions:

sudo apt install php8.4 php8.4-cli php8.4-fpm php8.4-mysql php8.4-mbstring php8.4-xml php8.4-curl php8.4-zip php8.4-gd php8.4-intl

Let’s break down what these key packages do:

  • php8.4: The core PHP package.
  • php8.4-cli: Provides the command-line interface for running PHP scripts in the terminal.
  • php8.4-fpm: The FastCGI Process Manager, which is essential for integrating PHP with web servers like Nginx.
  • php8.4-mysql: Allows PHP to communicate with MySQL/MariaDB databases.
  • php8.4-mbstring: Used for handling multi-byte strings (Unicode).
  • php8.4-xml: Provides XML manipulation capabilities.
  • php8.4-curl: Enables PHP to make requests to other servers via the cURL library.

Step 3: Verify the Installation

Once the installation is complete, you should verify that PHP 8.4 is correctly installed and is the active version on your command line.

Run the following command in your terminal:

php -v

You should see output similar to this, confirming the version:

PHP 8.4.0 (cli) (built: ... )
Copyright (c) The PHP Group
Zend Engine v4.4.0, Copyright (c) Zend Technologies

This confirms that the PHP 8.4 command-line interface is working correctly.

Step 4: Configure Your Web Server

Most developers use PHP with a web server like Apache or Nginx. Here’s how to integrate your new PHP 8.4 installation.

For Nginx Users

If you use Nginx, you’ll primarily use the PHP-FPM service you installed earlier. You need to configure your Nginx server block to pass PHP script processing to the PHP-FPM service.

  1. Check that the PHP-FPM service is running:

    sudo systemctl status php8.4-fpm
    

    If it’s not active, start and enable it:

    sudo systemctl start php8.4-fpm
    sudo systemctl enable php8.4-fpm
    
  2. Edit your Nginx server block configuration:
    Open your site’s configuration file (e.g., /etc/nginx/sites-available/default) and ensure the location ~ \.php$ block points to the correct PHP-FPM socket.

    server {
        # ... other directives
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        # Make sure this path is correct for PHP 8.4
        fastcgi_pass unix:/var/run/php/php8.4-fpm.sock; 
    }
    
    # ... other directives
    

    }

  3. Test and restart Nginx:
    bash
    sudo nginx -t
    sudo systemctl restart nginx

For Apache Users

If you are using Apache, you need to install the corresponding module to integrate PHP 8.4.

  1. Install the Apache PHP module:

    sudo apt install libapache2-mod-php8.4
    
  2. Enable the module and restart Apache: The installation process should automatically enable the new module. However, if you are switching from an older PHP version, you may need to disable the old one and enable the new one.
    bash
    sudo a2dismod php8.3 # Example: disable old version
    sudo a2enmod php8.4
    sudo systemctl restart apache2

Managing Multiple PHP Versions (Optional)

If you have multiple PHP versions installed, you can easily switch between them for command-line usage with the update-alternatives utility.

To see available versions and choose a default, run:

sudo update-alternatives --config php

This will present a menu allowing you to select which PHP version the /usr/bin/php symlink should point to. This is incredibly useful for developers managing projects with different PHP requirements.

By following these steps, you have successfully installed PHP 8.4 on your Ubuntu system, ready for modern web development. Staying on an actively supported PHP version is one of the most important security measures you can take for your applications, ensuring you receive timely patches and benefit from the latest performance improvements.

Source: https://infotechys.com/upgrade-php-8-4-ubuntu-22-04-24-04/

900*80 ad

      1080*80 ad