To install PHP 8.4 on Ubuntu and move a WordPress site onto it, you add a trusted PHP repository, install the 8.4 packages and the extensions WordPress needs, then point your web server at the new PHP-FPM socket. The whole job takes about half an hour on a typical VPS, and most of that time goes to testing, not typing commands. Do the backup and the checks in this guide and the switch stays boring, which is exactly what you want on a live site.
Ubuntu 24.04 ships PHP 8.3 and 22.04 ships PHP 8.1, so neither gives you PHP 8.4 without extra work. Ubuntu 25.04 does include PHP 8.4, so if you run that release, skip the repository step and install straight from apt.
Check Your Current Setup First
Run these three commands so you know what you are replacing. First, check the PHP version the command line uses:
php -v
Then check which PHP-FPM service your web server actually talks to. On Nginx, look at the fastcgi_pass line in your site config, usually under /etc/nginx/sites-available/. It points at a socket like /run/php/php8.3-fpm.sock. That socket name tells you the version to retire later. Finally, check your WordPress version and your plugins. WordPress 6.7 and later support PHP 8.4, but note any plugin not updated in a year or more; an old plugin can still throw fatal errors on the new version.
If you run several WordPress sites on one server and only want to move one of them, the per-site approach works better than a server-wide switch. Our guide to giving each WordPress site its own PHP version on one VPS shows how to keep sites on different versions side by side.
Back Up Your Site Before Touching PHP
A PHP upgrade changes the runtime under your whole site. If a plugin breaks, the fastest way back is a backup you made ten minutes earlier, not a reinstall from memory. Export the database and copy the files:
wp db export ~/backup-$(date +%F).sql --path=/var/www/your-site
tar -czf ~/site-files-$(date +%F).tar.gz -C /var/www your-site
Replace your-site with your real document root. If you do not use WP-CLI, mysqldump plus a file copy does the same job. Confirm both files exist and are not empty before you go on. A staging copy is even better: run the whole upgrade there first if you keep one.
Install PHP 8.4 on Ubuntu with the Ondrej Repository
Ubuntu’s default repositories lag behind PHP releases, so server admins use the Ondrej Sury PHP repository, which carries current PHP builds for both 22.04 and 24.04. Add it and update the package lists:
sudo apt update
sudo apt install -y software-properties-common
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update
Now install PHP 8.4 with FPM, the process manager Nginx uses to run PHP:
sudo apt install -y php8.4-fpm php8.4-cli
Check that the new service exists and is running:
systemctl status php8.4-fpm --no-pager
php8.4 -v
You should see PHP 8.4 and an active FPM service. The old version stays installed and untouched at this point, which is deliberate. Your site still runs on the old socket until you tell Nginx otherwise, so nothing changes for visitors yet.
| Ubuntu release | PHP in default repos | What you need for PHP 8.4 |
|---|---|---|
| 22.04 LTS | PHP 8.1 | Ondrej repository |
| 24.04 LTS | PHP 8.3 | Ondrej repository |
| 25.04 | PHP 8.4 | Install from apt directly |
If you want the full Nginx and PHP-FPM background first, our guide to installing PHP 8.4 on Ubuntu with Nginx and PHP-FPM walks through the stack from a clean server.
Install the Extensions WordPress Needs
PHP itself is not enough. WordPress and its plugins call on a set of extensions, and a missing one shows up as a broken image editor, failed updates, or a blank media library. Install the standard set for PHP 8.4 in one command:
sudo apt install -y php8.4-mysql php8.4-xml php8.4-curl php8.4-mbstring
php8.4-zip php8.4-gd php8.4-intl php8.4-bcmath php8.4-soap php8.4-imagick
php8.4-opcache php8.4-readline
Most sites need everything in that list. If a plugin asks for something extra, its error message names the extension; add it the same way, for example sudo apt install -y php8.4-redis for a Redis object cache. After installing, confirm the modules loaded:
php8.4 -m | grep -Ei 'mysql|mbstring|curl|gd|intl|opcache|imagick'
Each name should appear in the output. OPcache deserves a mention here: PHP ships it, but its default settings are conservative for a busy PHP 8.4 WordPress site. Once the switch is done, tune it using our OPcache settings for WordPress on Ubuntu 24.04, which covers memory size and revalidation for production sites.
Point Nginx at the New PHP-FPM Socket
This is the actual switch. Open your site’s Nginx config, find the PHP location block, and change the socket version number:
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.4-fpm.sock;
}
If your old config said php8.3-fpm.sock, change only that number. Some setups pass PHP to a TCP port such as 127.0.0.1:9000 instead of a socket; check which Ubuntu PHP-FPM 8.4 pool listens on that port in /etc/php/8.4/fpm/pool.d/www.conf and match it.
Test the config, then reload Nginx:
sudo nginx -t
sudo systemctl reload nginx
Never skip nginx -t. A typo in the config file takes every site on the server down on reload, while the test catches it before anything changes. If you run Apache instead of Nginx, the equivalent is sudo a2dismod php8.3 && sudo a2enmod php8.4 && sudo systemctl restart apache2, with the old version number replaced by whatever you currently run.
Switch WordPress to PHP 8.4 and Verify It
With Nginx reloaded, the switch is already live, so verify it right away. The quickest check is a small PHP info file, but delete it the moment you finish, since it exposes server details:
echo '<?php phpinfo();' | sudo tee /var/www/your-site/info.php
curl -s https://your-site.com/info.php | grep -i 'PHP Version'
sudo rm /var/www/your-site/info.php
A safer check that needs no temporary file is WordPress itself. In the admin area go to Tools, then Site Health, then Info, then Server. It lists the PHP version WordPress sees. WP-CLI gives the same answer from the terminal:
wp --info --path=/var/www/your-site | grep 'PHP version'
When that line says 8.4, the switch worked. If it still shows the old version, Nginx is still loading a cached config or pointing at the old socket. Reload Nginx again, then re-read the fastcgi_pass line. The version WordPress reports is the truth here, not the version the command line reports, because the CLI binary and the FPM pool are separate installs and can sit on different versions.
Test the Site and Fix the Usual Problems
Click through the pages that matter instead of trusting the homepage alone. Open a post, submit a comment or a contact form, log in and out, upload an image, and open the checkout page if the site sells anything.
Three problems cover most failed switches. First, a 502 Bad Gateway right after reload means Nginx points at a socket that does not exist. Check that php8.4-fpm is running and that the socket file exists under /run/php/. Second, a white screen or a 500 error on some pages usually means a plugin or theme calls a function PHP 8.4 removed or changed. Turn on WP_DEBUG briefly, read the fatal error in the log, and update or replace the plugin named there. Third, missing image thumbnails or failed uploads point at a missing extension, usually php8.4-gd or php8.4-imagick. Install it, restart FPM with sudo systemctl restart php8.4-fpm, and test again.
If the errors keep coming and you cannot pin them down, roll back. Change fastcgi_pass back to the old socket, reload Nginx, and the site runs on the old PHP again in seconds. Update the offending plugin on a staging copy and try the switch again when it is ready.
Clean Up the Old PHP Version
Wait a few days before removing anything. Let the site run through its normal traffic, a backup cycle, and any scheduled tasks such as cron jobs and automatic updates. Scheduled tasks are the usual surprise, because WP-Cron and system cron may call the PHP CLI, and the CLI version is separate from FPM. Set the CLI default to 8.4 so scripts use the same version:
sudo update-alternatives --set php /usr/bin/php8.4
Once the site has run clean on 8.4 for several days, remove the old packages:
sudo apt remove --purge php8.3*
sudo apt autoremove -y
Replace 8.3 with your actual old version. Keep the Ondrej repository enabled so future PHP updates arrive through normal apt upgrade runs. Our LEMP stack guide for installing WordPress on a VPS with Nginx, PHP 8.4, and MariaDB shows the complete setup this upgrade slots into, and a fresh server built from it starts on PHP 8.4 with no migration step at all.