Planning to upgrade to PHP 8.4 on your Ubuntu or Debian system? Great choice — PHP 8.4 brings performance improvements, updated syntax, and new features that make development smoother and faster.
In this guide, you’ll learn how to install or upgrade to PHP 8.4 the right way — with support for Apache, Nginx, or CLI setups – while preserving your existing environment.
🚀 Why Upgrade to PHP 8.4?
- Improved performance and reduced memory usage
- Enhanced type safety and language features
- Updated core functions and better error handling
🔐 Backup First!
Before you upgrade anything:
dpkg -l | grep php | tee installed-php-packages.txt
This helps you log current PHP packages before replacing them with PHP 8.4 versions.
🧱 Add PHP 8.4 Repository
PHP 8.4 isn’t available in official Ubuntu/Debian repos yet. Use the trusted third-party repository by Ondřej Surý:
Ubuntu:
sudo add-apt-repository ppa:ondrej/php
sudo apt update
Debian:
sudo apt-get install -y lsb-release ca-certificates curl apt-transport-https
curl -sSLo debsuryorg.deb https://packages.sury.org/php/debsuryorg-archive-keyring.deb
sudo dpkg -i debsuryorg.deb
sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
sudo apt update
🖥️ Install PHP 8.4 (Choose Your Setup)
For CLI Only:
sudo apt install php8.4-cli
For Apache:
sudo apt install php8.4-cli libapache2-mod-php8.4
For Nginx + PHP-FPM:
sudo apt install php8.4-cli php8.4-fpm
📦 Install Common PHP Extensions
Install core extensions like curl
, mbstring
, xml
, and gd
:
sudo apt install php8.4-{curl,mbstring,xml,gd}
🌐 Configure Your Web Server
For Apache with FPM:
sudo a2enconf php8.4-fpm
sudo systemctl reload apache2
For Nginx:
Update your Nginx config block:
fastcgi_pass unix:/run/php/php8.4-fpm.sock;
Then reload:
sudo systemctl reload nginx
✅ Verify PHP Installation
php -v
You should see PHP 8.4 listed in the output.
⚙️ Migrate Your PHP Configuration
Compare your old PHP config with the new one:
diff /etc/php/8.3/cli/php.ini /etc/php/8.4/cli/php.ini
Tweak settings as needed.
🧹 Clean Up Old PHP Versions
Once everything is working:
sudo apt purge '^php8.3.*'
🧠 Final Thoughts
PHP 8.4 is a worthy upgrade with better security, speed, and modern features. Whether you’re using Apache, Nginx, or CLI, this guide sets you up for a clean and stable transition.
Leave a Reply