On this page
- When should you upgrade PHP?
- What should you check before starting?
- How do you install the new version with the same extensions?
- How do you carry over php.ini values and pools?
- How do you switch Nginx to the new socket?
- How do you switch Apache?
- How do you update the command line PHP and Composer?
- How do you verify the upgrade worked?
- How do you roll back or clean up?
- Questions
When should you upgrade PHP?
Upgrade before your current branch leaves security support, and ideally soon after your applications declare support for the next one. Each PHP branch gets two years of active fixes followed by two years of security-only releases, so PHP 8.2 stops receiving security fixes at the end of 2026, while 8.3, 8.4 and 8.5 continue for longer.
If you use the distribution PHP, the version is tied to the release: Debian 12 carries 8.2 and Debian 13 carries 8.4, Ubuntu 22.04 carries 8.1 and Ubuntu 24.04 carries 8.3. Distribution packages keep receiving backported fixes for the life of the release, so one path is a release upgrade, covered in upgrading Debian and upgrading Ubuntu. The other path, shown here, uses the Ondrej PPA on Ubuntu or the Sury repository on Debian to move PHP alone.
What should you check before starting?
Confirm the application supports the target version, take a backup and note what is installed now.
php -v
ls /etc/php/
systemctl list-units --type=service | grep fpm
dpkg -l | awk '/^ii php8\.2/ {print $2}'
php8.2 -m > ~/php82-modules.txt- Read the release notes of your CMS, framework and plugins for a minimum and maximum PHP version.
- Run
composer check-platform-reqsin each Composer project to see extension requirements. - Dump the databases and copy the site files, or rely on the console daily backups described in daily backups.
If the third-party repository is not yet added, follow PHP and PHP-FPM to add the Ondrej PPA or the Sury repository first.
How do you install the new version with the same extensions?
Turn the list of installed 8.2 packages into 8.4 names and install them in one go.
dpkg -l | awk '/^ii php8\.2-/ {print $2}' | sed 's/php8\.2/php8.4/' > ~/php84-packages.txt
cat ~/php84-packages.txt
sudo apt update
sudo apt install -y $(cat ~/php84-packages.txt)
php8.4 -v
php8.4 -m > ~/php84-modules.txt
diff ~/php82-modules.txt ~/php84-modules.txtIf apt reports that a package has no install candidate, remove that line and check whether the extension changed. In PHP 8.4, for example, IMAP, Pspell and OCI8 left the core distribution and are now separate PECL extensions, so their package names or availability can differ. The diff output should show only those intended changes.
How do you carry over php.ini values and pools?
Copy your own override files and pool definitions into the new tree; leave the shipped files alone.
ls /etc/php/8.2/fpm/conf.d/ | grep -v '^[0-9][0-9]-[a-z]*\.ini$'
sudo cp /etc/php/8.2/fpm/conf.d/99-site.ini /etc/php/8.4/fpm/conf.d/
sudo cp /etc/php/8.2/fpm/pool.d/*.conf /etc/php/8.4/fpm/pool.d/
sudo grep -l 'php8.2' /etc/php/8.4/fpm/pool.d/*.confPool files often name their socket with the version, such as listen = /run/php/php8.2-shop.sock. Change those to php8.4 in the copies so the two services do not fight over the same socket, then test and start the new service:
sudo sed -i 's#/run/php/php8\.2-#/run/php/php8.4-#' /etc/php/8.4/fpm/pool.d/*.conf
sudo php-fpm8.4 -t
sudo systemctl enable --now php8.4-fpm
ls -l /run/php/How do you switch Nginx to the new socket?
Edit the fastcgi_pass line of each server block, test the configuration and reload.
grep -rn 'fastcgi_pass' /etc/nginx/sites-enabled/ /etc/nginx/conf.d/
sudo sed -i 's#unix:/run/php/php8\.2-#unix:/run/php/php8.4-#' /etc/nginx/sites-available/example.net
sudo nginx -t && sudo systemctl reload nginxA reload keeps open connections alive, so visitors do not see an outage. To move one site at a time, change only that site's file, which is also a good way to try the new version on a staging host name first, such as staging.example.net.
How do you switch Apache?
The command depends on whether Apache runs PHP through FPM or as a module.
# Apache with PHP-FPM (event worker)
sudo a2disconf php8.2-fpm
sudo a2enconf php8.4-fpm
sudo apachectl configtest && sudo systemctl reload apache2
# Apache with mod_php (prefork worker)
sudo apt install -y libapache2-mod-php8.4
sudo a2dismod php8.2
sudo a2enmod php8.4
sudo apachectl configtest && sudo systemctl restart apache2Virtual hosts with their own SetHandler "proxy:unix:/run/php/php8.2-....sock|fcgi://localhost" line need that path edited too. Check with grep -rn SetHandler /etc/apache2/sites-enabled/. The module route needs a restart, not a reload, so pick a quiet moment for it.
How do you update the command line PHP and Composer?
Point the php alternative at the new binary so cron jobs, Composer and artisan-style tools use it.
sudo update-alternatives --set php /usr/bin/php8.4
php -v
crontab -l | grep -n php
cd /var/www/example.net && composer install --no-dev --optimize-autoloaderCron lines that call /usr/bin/php8.2 by full path keep using the old version until you edit them. Rebuilding the Composer vendor folder makes sure platform checks and any optimised autoloader files match the new runtime.
How do you verify the upgrade worked?
Check the version seen by the web server, then watch logs while you click through the important pages.
echo '<?php echo PHP_VERSION;' | sudo tee /var/www/example.net/public/v.php >/dev/null
curl -s https://example.net/v.php; echo
sudo rm /var/www/example.net/public/v.php
sudo journalctl -u php8.4-fpm --since "15 min ago"
sudo tail -f /var/log/nginx/error.logLog in, submit a form, upload a file and run any scheduled task by hand. New deprecation notices are normal after a jump and do not stop pages; fatal errors such as calls to removed functions need fixing or a rollback.
How do you roll back or clean up?
To roll back, point the web server at the old socket again; to finish, stop and purge the old branch.
# roll back (Nginx example)
sudo sed -i 's#unix:/run/php/php8\.4-#unix:/run/php/php8.2-#' /etc/nginx/sites-available/example.net
sudo nginx -t && sudo systemctl reload nginx
# clean up once everything runs on 8.4
sudo systemctl disable --now php8.2-fpm
sudo apt purge 'php8.2*'
sudo apt autoremove --purgeWait a few days with both versions installed before purging, so a late problem in a rarely used page still has an easy way back. Running two FPM services costs only the memory of their idle workers.
Plans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
Questions about Upgrade PHP to a newer version
Can I skip from PHP 8.1 straight to 8.4?
Yes, the install steps are the same. Read the migration notes of every branch in between, because deprecations from 8.2 and 8.3 become relevant together.
Will upgrading PHP break WordPress plugins?
Plugins that are maintained usually support current PHP releases. Test on a staging copy first and check that each plugin lists the new version as supported.
Why does the site still show the old version?
The web server still points at the old socket or module, or OPcache served a cached page during the switch. Check fastcgi_pass or the enabled Apache conf and reload.
Do I need to restart the server?
No. Starting the new FPM service and reloading the web server is enough. Only the mod_php route needs an Apache restart.
How do I upgrade PHP on Rocky Linux or AlmaLinux?
Switch the module stream with dnf module reset php and dnf module enable php:remi-8.4 (or an AppStream stream), then run dnf distro-sync and restart php-fpm. That replaces PHP in place, so test on a second server first.