Upgrade from PHP 7.x to PHP 8.4 on Linux: A Step-by-Step Guide for Ubuntu, Debian, Fedora, CentOS, & Arch

Last updated on | 22 replies

Introduction

This guide details how to upgrade from PHP 7.x to the latest PHP 8.x release – currently PHP 8.4 – on various Linux distributions. Upgrading improves performance, security, and grants access to modern PHP features. Whether you’re on Ubuntu, Debian, Fedora, CentOS/RHEL, or Arch Linux, this step-by-step guide has you covered.

If you’re already running PHP 8.x and want to upgrade to a newer PHP 8 version (for example, from 8.4 to a future release), please refer to our dedicated guide on upgrading PHP 8 on Linux: How to Upgrade PHP 8 on Linux.

This guide is designed for tech-savvy users. Commands are provided for Debian-based systems; users of Fedora, CentOS/RHEL, or Arch Linux should adapt the instructions using dnf/yum or pacman as needed.

Prerequisites

  • Backup or snapshot your server before making any changes.
  • Ensure you have sudo or root privileges.
  • Test commands in a staging environment if possible.
  • Be familiar with your distro’s package manager (apt, yum/dnf, or pacman).

Before proceeding, check your current PHP version:

php -v

If you’re running PHP 7.x, continue with the steps below to upgrade to PHP 8.4.

Step 1: List Installed PHP Extensions

It’s a good idea to list your currently installed PHP extensions. Save this list to a file so you can reinstall the necessary extensions for PHP 8.4 later.

dpkg -l | grep php | tee packages.txt

Step 2: Uninstall PHP 7.x and Its Extensions

Remove PHP 7.x and its extensions. Important: Ensure you have backed up your configuration files before proceeding.

sudo apt-get purge php7.*

When prompted, press y and ENTER.

If you have phpMyAdmin installed, you might see a prompt regarding its database. Choose NO to preserve your database.

Step 3: Autoclean and Autoremove

After uninstalling PHP 7.x, remove any lingering dependencies:

sudo apt-get autoclean
sudo apt-get autoremove

Confirm by pressing Y and ENTER when asked.

Step 4: Add the PHP Repository (If Needed)

For Ubuntu 18.04 and 20.04, PHP 8.4 is only available via Ondřej Surý’s PPA. Even though newer Ubuntu versions (22.04/24.04) and Debian may include PHP 8.x, they might not offer PHP 8.4 by default. To install PHP 8.4 specifically, add the repository:

sudo add-apt-repository ppa:ondrej/php

Press ENTER when prompted. Fedora, CentOS/RHEL, and Arch Linux users should consult the Remi repository or their distro’s documentation for equivalent instructions.

Step 5: Install PHP 8.4

Update your package list and install PHP 8.4. Replace 8.4 with a newer version number if available.

sudo apt-get update
sudo apt-get install php8.4

When prompted, press Y and ENTER. Then, restart your web server:

sudo systemctl restart apache2

Step 6: Install PHP 8.4 Extensions

Install commonly used PHP extensions. Modify this list as needed for your application:

  • php8.4-common
  • php8.4-mysql
  • php8.4-xml
  • php8.4-xmlrpc
  • php8.4-curl
  • php8.4-gd
  • php8.4-imagick
  • php8.4-cli
  • php8.4-dev
  • php8.4-imap
  • php8.4-mbstring
  • php8.4-opcache
  • php8.4-soap
  • php8.4-zip
  • php8.4-intl

For Debian/Ubuntu, execute:

sudo apt install php8.4-common php8.4-mysql php8.4-xml php8.4-xmlrpc php8.4-curl php8.4-gd php8.4-imagick php8.4-cli php8.4-dev php8.4-imap php8.4-mbstring php8.4-opcache php8.4-soap php8.4-zip php8.4-intl -y

For Nginx users, install PHP-FPM:

sudo apt install php8.4-fpm -y

After installing extensions, restart your web server. For Apache:

sudo systemctl restart apache2

For Nginx:

sudo systemctl restart nginx
sudo systemctl restart php8.4-fpm

Step 7: Verify PHP Installation

Finally, confirm that PHP 8.4 is running:

php -v

Output:

PHP 8.4.1 (cli) (built: Dec 29 2024 10:15:00) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.4.1, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.1, Copyright (c), by Zend Technologies

Troubleshooting Tips

If you encounter issues during or after the upgrade, consider the following troubleshooting steps:

  • Review Logs: Check Apache logs (/var/log/apache2/error.log) or Nginx logs (/var/log/nginx/error.log) for errors.
  • Module Configuration: Verify that only the correct PHP module is enabled (e.g., libapache2-mod-php8.4 for Apache).
  • PHP Configuration: Ensure any custom settings from your old php.ini have been migrated to the new configuration file.
  • Use phpinfo: Create a phpinfo.php file with <?php phpinfo(); ?> in your web root to confirm the PHP version via a browser.
  • Clear Caches: Clear OPcache and any application caches if changes are not reflected.

Conclusion

You have now successfully upgraded to PHP 8.4. Be sure to test your website or web application thoroughly for compatibility. Stay informed about future PHP releases and consider revisiting your configuration for further performance optimizations.

Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.

22 replies

Leave a reply

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

  1. Hi,

    I have an ubuntu OS 18.04.4 LTS and php7.2, but I have followed this steps and it didn’t work for me to upgrade my php to 8.1. Anyone with a suggestion?.. Thank you.

  2. I also have to say thank you! Quick and easy steps. Works on the first try. I only had to adapt my nginx config and it works fine. Thanks again 🙂

  3. Thanks a bunch! I’d tried other postings without success to the point of busting the whole setup.
    This one worked perfectly.

    1. Ondřej Surý is the maintainer of the PHP package in the Debian and Ubuntu operating systems. By adding his Personal Package Archive (PPA) repository to your system, you will be able to install the latest version of PHP directly from the source package maintained by Surý, rather than from the version included in the official Ubuntu repositories, which may not be the latest version.

  4. Thank you for the info! Very useful!!

    Just a side note:
    If anyone is using memcache and redis, the extensions names are different:
    For php-memcache and php-redis that used to work with php 7.x, the extensions php8.0-memcache and php8.0-redis should be used instead

    Greetings

  5. This looks excellent, thank you. One question before I start – in my /etc directory there is are these files and directories. Will they be converted or do I need to do it manually:
    /etc/apache2/mods-enabled/php7.4.load
    /etc/apache2/mods-enabled/php7.4.conf
    /etc/apache2/mods-available/php7.4.load
    /etc/apache2/mods-available/php7.4.conf
    /etc/php/7.4/cli/php.ini
    /etc/php/7.4/apache2/php.ini

  6. Hello,

    I updated the php 8 on wordpress, via command line.

    Everything went fine, I only had 2 plugins to disable renaming the folder, in the end everything worked out!

    Greetings from Brazil.

    Thank you very much for the content, it helped me!