Last updated
How to Update PHP on Ubuntu 24.04 and 22.04 (Apache, Nginx, WordPress)
Upgrade PHP to a supported version on Ubuntu 24.04 or 22.04, for Apache with php-fpm, Apache with mod_php, or Nginx with php-fpm. Includes WordPress checks, removing the old version, and fixes for the usual errors.
Related guide: Service won't start after the upgrade? Find the real error
PHP version support (October 2026)
PHP versions reach end of life on a fixed schedule; an end-of-life version gets no security fixes. Ubuntu's own PHP: 22.04 ships 8.1, 24.04 ships 8.3 (20.04 shipped 7.4 and its standard support ended in May 2025). Other versions come from the ondrej/php PPA.
| Version | Status |
|---|---|
| 8.5 | Active support, security fixes until Dec 2029 |
| 8.4 | Active support, security fixes until Dec 2028. Recommended for new sites |
| 8.3 | Security fixes only, until Dec 2027. Ubuntu 24.04 default |
| 8.2 | Security fixes only, until Dec 2026: plan your upgrade |
| 8.1 | End of life since Dec 2025: upgrade now |
| 8.0 and 7.4 | End of life (2023 and 2022): unpatched vulnerabilities |
1. Check your current PHP version
The web server's PHP and the command-line PHP can be different versions; WordPress uses the web server's. Check both.
php --version
ls /run/php/ # php-fpm sockets show the fpm versions
php -i | grep "Loaded Configuration File"
2. Add the ondrej/php PPA
Maintained by Ondřej Surý, a Debian PHP maintainer, it is the standard way to install other PHP versions on Ubuntu. On 24.04, confirm the packages exist with apt-cache search php8.4 after adding it.
sudo apt update
sudo apt install -y software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
3. Install the new version
Replace 8.4 with your target version everywhere. This is a WordPress-ready extension set.
sudo apt install -y php8.4 php8.4-fpm php8.4-cli php8.4-common php8.4-mysql \
php8.4-curl php8.4-gd php8.4-intl php8.4-mbstring php8.4-xml php8.4-zip \
php8.4-bcmath php8.4-imagick php8.4-redis
php8.4 --version
systemctl status php8.4-fpm --no-pager
4a. Apache with php-fpm (recommended for Apache)
php-fpm runs PHP as its own service, allows a different PHP version per site, and is safer than mod_php. Per site, point SetHandler at the socket: SetHandler "proxy:unix:/run/php/php8.4-fpm.sock|fcgi://localhost".
sudo a2enmod proxy_fcgi setenvif
sudo a2disconf php8.3-fpm # old version
sudo a2enconf php8.4-fpm
sudo systemctl enable --now php8.4-fpm
sudo systemctl restart apache2
4b. Apache with mod_php
mod_php loads PHP inside Apache; only one version can be active at a time.
sudo apt install -y libapache2-mod-php8.4
sudo a2dismod php8.3
sudo a2enmod php8.4
sudo systemctl restart apache2
4c. Nginx with php-fpm
Nginx always uses php-fpm. Point fastcgi_pass at the new socket in your site config (in /etc/nginx/sites-available/), test, then reload.
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.4-fpm.sock;
}
sudo systemctl enable --now php8.4-fpm
sudo nginx -t && sudo systemctl reload nginx
5. Set the command-line default (optional)
The php command points at one version; update-alternatives switches it.
sudo update-alternatives --set php /usr/bin/php8.4
php --version
6. Verify and check WordPress
WP Admin > Tools > Site Health shows the PHP version WordPress runs on and flags plugin problems. Turn on logging for a day to catch deprecated functions, check the new php.ini kept your limits, then restart php-fpm (flushes OPcache) and clear any caching plugin.
# wp-config.php (temporarily)
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
tail -f /var/www/html/wp-content/debug.log
grep -E "upload_max_filesize|post_max_size|memory_limit|max_execution_time" /etc/php/8.4/fpm/php.ini
sudo systemctl restart php8.4-fpm
7. Remove the old version
Wait 24 to 48 hours of real traffic first, then remove the old packages to shrink the attack surface.
sudo systemctl disable --now php8.3-fpm
sudo apt purge -y 'php8.3*' libapache2-mod-php8.3
sudo apt autoremove -y
Troubleshooting
Most problems after a PHP upgrade are one of these.
| Symptom | Fix |
|---|---|
| 502 Bad Gateway | php-fpm is not running or the socket path is wrong. Check systemctl status php8.4-fpm and compare the path in your config with ls /run/php/. |
| Site still shows the old version | The web server was not restarted or reloaded, or the page is cached. Restart Apache or reload Nginx and clear caches. |
| Missing extension (GD, intl...) | Install it for the new version, for example sudo apt install php8.4-gd php8.4-intl, then restart php-fpm. |
| WordPress white screen | A plugin uses removed functions. Read debug.log (step 6) and disable plugins one by one to find it. |
| OPcache errors | Restart php-fpm to flush OPcache, or set opcache.enable=0 briefly to test. |
| Permission denied on the socket | In /etc/php/8.4/fpm/pool.d/www.conf set listen.owner and listen.group to www-data, then restart php-fpm. |
FAQ
Which PHP version should I use in 2026?
PHP 8.4 for new sites (8.5 if all your plugins support it). 8.3 is fine until December 2027. Anything older than 8.2 is end of life or close to it.
Is the ondrej/php PPA safe?
It is the widely used, actively maintained source of PHP builds for Ubuntu, run by a Debian PHP maintainer. Like any third-party repository, add it only on servers where you need other PHP versions.
Can I run two PHP versions at once?
Yes, with php-fpm. Each site points at its own socket (php8.3-fpm.sock or php8.4-fpm.sock).
Further reading: PHP supported versions · ondrej/php PPA · WordPress PHP compatibility