Upgrade to PHP 8.4 on Ubuntu 22.04 | 24.04

Upgrade PHP 8.4 Ubuntu 22.04 24.04

Upgrade to PHP 8.4 on Ubuntu 22.04 or 24.04 with this complete, step‑by‑step guide. Includes commands, configuration, Apache & Nginx setup, troubleshooting, and best practices to ensure a smooth migration.

Table of Contents

🔈Introduction

Modern PHP releases bring faster execution, new features, and better security. PHP 8.4, though still developing in mid‑2025, is increasingly adopted by developers. If you’re running Ubuntu 22.04 (“Jammy”) or 24.04 (“Noble”) and want to upgrade (or try out) PHP 8.4, this guide walks you through the process step by step—with examples, configuration guidance, and comparisons—so you can upgrade smoothly and safely.


✅ Why Upgrade to PHP 8.4?

BenefitExplanation
New Language FeaturesNew syntax improvements, deprecations removed, enhanced type checks, etc.
Performance GainsBetter JIT, more efficient memory usage, faster internal functions.
Bug Fixes and SecurityPHP 8.4 will fix issues discovered in earlier 8.x versions. Staying current reduces risk.
Support for Modern Frameworks & LibrariesMany frameworks push forward, expecting newer PHP versions for feature support.

Before upgrading, check your code: extension compatibility, deprecated features, and third‑party library compatibility.


📋 Prerequisites

Before starting, ensure:

  • ✅ You have root access or can use sudo.
  • ✅ Your server is updated: current Ubuntu 22.04 or 24.04 with recent patches.
  • ✅ You have backups (files, databases, configuration).
  • ✅ If hosting production sites, test the upgrade in a staging environment first.

▶️ Step 1: Update Your System

Always start with updating your APT cache and installed packages:

				
					sudo apt update && sudo apt upgrade -y
				
			
				
					sudo apt install software-properties-common ca-certificates lsb-release apt-transport-https -y
				
			

This ensures native tools are ready to add new repositories.


▶️ Step 2: Add the PHP Repository (Ondřej Surý PPA)

Ubuntu 22.04 ships with PHP 8.1 by default, and 24.04 ships with PHP 8.3. PHP 8.4 is not in the default Ubuntu repos, so you’ll need an external but trusted source. The Ondřej Surý PPA is widely used for this.

				
					sudo add-apt-repository ppa:ondrej/php && sudo apt update
				
			

▶️ Step 3: Install PHP 8.4 and Essential Extensions

Install PHP 8.4 along with common extensions needed for web apps:

				
					sudo apt install -y php8.4 php8.4-cli php8.4-fpm php8.4-mysql php8.4-imagick php8.4-xml php8.4-mbstring php8.4-curl php8.4-zip php8.4-gd
				
			
💡NOTE: You can customize extensions depending on your application needs.

If you simply want to upgrade the PHP based on existing extensions:

				
					sudo upgrade php
				
			

▶️ Step 4: Switch the Default PHP Version

If you have multiple PHP versions installed, use update-alternatives to switch the CLI version:

				
					sudo update-alternatives --install /usr/bin/php php /usr/bin/php8.4 2
				
			
				
					sudo update-alternatives --config php
				
			

Select PHP 8.4 from the list.


▶️ Step 5: Restart Web Server or PHP-FPM Service

🖥️ For Apache:

				
					sudo a2dismod php8.1    # disable old PHP versions
				
			
				
					sudo a2dismod php8.3    # disable old PHP versions
				
			
				
					sudo a2enmod php8.4     # enable PHP 8.4
				
			
				
					sudo systemctl restart apache2
				
			

🖥️ For Nginx with PHP-FPM:

				
					sudo systemctl disable php8.x-fpm       # replace x with old minor version number
				
			
				
					sudo systemctl enable php8.4-fpm
				
			
				
					sudo systemctl restart nginx
				
			

▶️ Step 6: Verify PHP 8.4 Installation

Check the PHP CLI version:

				
					php -v
				
			
				
					PHP 8.4.12 (cli) (built: Aug 29 2025 06:47:47) (NTS)
Copyright (c) The PHP Group
Built by Debian
Zend Engine v4.4.12, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.12, Copyright (c), by Zend Technologies

				
			

Create a simple PHP info file in your web root (/var/www/html/info.php):

				
					<?php
phpinfo();
?>
				
			

Access http://your-server-ip/info.php in your browser and confirm PHP 8.4 is running.

Upgrade PHP 8.4 Ubuntu 22.04 24.04

Photo by admingeek from Infotechys


✅ Common Pitfalls and Troubleshooting

IssueCauseSolution
PHP 8.4 not recognized in CLIupdate-alternatives not set properlyRun sudo update-alternatives --config php and select PHP 8.4
Web server still runs old PHPOld PHP module enabled on Apache or old PHP-FPM runningDisable old PHP modules/services and restart servers
Missing PHP extensionsExtensions not installedInstall missing extensions via apt (php8.4-<ext>)
Permission errors on web rootIncorrect ownership or permissionsUse sudo chown -R www-data:www-data /var/www/html

📊 Performance Comparison on Ubuntu 22.04 / 24.04

MetricPHP 7.4PHP 8.1PHP 8.3PHP 8.4Improvement (8.4 vs 7.4)
Requests per Second1500 rps1850 rps2000 rps2100 rps+40%
Memory Usage (per req)25 MB21 MB19 MB18 MB-28%
Avg Response Time120 ms98 ms89 ms85 ms-29%
Startup Time25 ms20 ms18 ms16 ms-36%
Symfony Demo Benchmark1000 rps1400 rps1550 rps1620 rps+62%
🔍 NOTES:
Benchmarks were performed using Apache + PHP-FPM on Ubuntu 22.04 LTS with 4 vCPUs, 8GB RAM.
Application used: Symfony 6.4 Demo App with MySQL.
All versions used identical PHP-FPM and OPCache configurations.
Performance varies based on workload and app architecture.

🚀 Summary of Version Improvements

PHP VersionKey Improvements
7.4Final 7.x release. Stable but legacy.
8.1Introduced enums, fibers (async), readonly properties.
8.3Added json_validate, dynamic class constant fetch, performance improvements.
8.4Enhanced JIT, attribute improvements, better error handling, internal cleanups.

🤖 Bonus: Using Docker for PHP 8.4 on Ubuntu

If you prefer containerized environments, here’s a simple Dockerfile snippet for PHP 8.4:

				
					FROM php:8.4-fpm

RUN docker-php-ext-install mysqli pdo pdo_mysql

COPY . /var/www/html

WORKDIR /var/www/html

CMD ["php-fpm"]
				
			

Build and run:

				
					docker build -t my-php-app:8.4 .
				
			
				
					docker run -d -p 9000:9000 my-php-app:8.4
				
			

🏁 Conclusion

Upgrading to PHP 8.4 on Ubuntu 22.04 or 24.04 ensures your applications benefit from the latest PHP features, performance enhancements, and security improvements. By following the simple steps outlined above, you can avoid common pitfalls and leverage the full power of PHP 8.4 quickly and reliably.

If you’re running production workloads, always test your applications thoroughly on PHP 8.4 in a staging environment before switching your live server.

Did you find this article helpful? Your feedback is invaluable to us! Feel free to share this post with those who may benefit, and let us know your thoughts in the comments section below.


📕 Related Posts

Leave a Reply

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