14+ years building on WordPress / Replies in under 5 hours
WordPress 8 min read · Updated July 2026

How to Upgrade PHP to 7.4 on Ubuntu (Apache + Nginx)

Photo of Ajay Khandal
Ajay Khandal
WordPress Developer
TL;DR

PHP 7.4 reached end of life in November 2022 — use it as a stepping stone toward PHP 8.2+ if your application blocks a direct jump. This guide covers upgrading from PHP 7.2/7.3 to 7.4 on Ubuntu using the ondrej/php PPA. Apache: add PPA, install php7.4, run a2dismod on the old version and a2enmod php7.4, restart Apache. Nginx: install php7.4-fpm, update the fastcgi_pass socket in your server block to php7.4-fpm.sock, reload Nginx. For production, target PHP 8.2 (supported through December 2026) or 8.4 (current stable) after testing on 7.4.

PHP 7.4 was released in November 2019 and reached end of life in November 2022. Despite that, upgrading to 7.4 from an older 7.x branch remains a relevant step for teams running legacy applications that aren’t yet ready for PHP 8.x, or for incremental migration paths where 7.4 is a deliberate intermediate checkpoint before moving to a currently supported release.

If you’re starting fresh and have no compatibility constraints, skip directly to the PHP 8.2 or 8.4 guides — both are actively maintained. If you’re on PHP 7.2 or 7.3 and stepping up incrementally, or if your stack specifically requires 7.4 as a staging point, this guide covers the full process for Ubuntu with both Apache and Nginx. For the broader case for keeping PHP current on a WordPress site, see why upgrading PHP versions matters for WordPress.

What PHP 7.4 Added Over 7.2 and 7.3

PHP 7.4 was a significant release for modern PHP development. If you’re evaluating whether 7.4 is the right intermediate stop, the key additions are:

  • Typed properties. Class properties can now declare types directly: public int $age; or private string $name;. Previously, type enforcement in properties required workarounds via getters or docblock hints that weren’t enforced at runtime.
  • Arrow functions. Single-expression closures that automatically capture variables from the outer scope: $double = fn($x) => $x * 2;. No use keyword required for outer-scope variables.
  • Spread operator in array expressions. $result = [...$a, ...$b]; — unpack arrays directly in array literals.
  • Null coalescing assignment operator. $data['key'] ??= 'default'; — assign only if the left-hand side is null, replacing the common $x = $x ?? $y pattern.
  • Preloading (OPcache). The opcache.preload directive allows scripts to be loaded into shared memory at server start — reducing bootstrap overhead on repeated requests. Meaningful on high-traffic PHP applications.
  • FFI (Foreign Function Interface). Call C libraries directly from PHP without writing a C extension. Useful for performance-sensitive operations or system-level integrations.

PHP 7.4 also introduced several deprecations that become breaking changes in 8.0: using curly brace syntax for string/array offsets ($string{0}), and the get_magic_quotes_gpc() function. If you’re using 7.4 as a stepping stone toward 8.0, audit for these deprecations before your next upgrade.

Before You Upgrade: Pre-Flight Checklist

Before changing the PHP version on a server running live applications, run through these steps:

  • Back up the database. A PHP version change should not touch the database, but if something goes wrong mid-upgrade and the web server needs to be rolled back, you want a current backup. For WordPress sites, use Updraft Plus, WP Vivid, or mysqldump directly.
  • Test on a staging environment first. Spin up an equivalent Ubuntu instance, replicate the upgrade, and verify your application runs cleanly on 7.4 before touching production. PHP minor-version upgrades are generally compatible within the 7.x branch, but third-party plugins and libraries can behave differently.
  • Check plugin and library compatibility. If you’re running WordPress, verify your active plugins support PHP 7.4. The WordPress health check (Tools → Site Health) will surface PHP-related issues. For other applications, check each dependency’s documented requirements.
  • Note your current PHP version. Run php -v and php --ini before starting. The php.ini location varies by version and server type — you’ll need it if you need to port custom INI settings.
  • Identify your web server. The upgrade steps differ between Apache (uses mod_php via a2dismod/a2enmod) and Nginx (uses PHP-FPM via a FastCGI socket). Both are covered below.

Step 1: Add the ondrej/php PPA

Ubuntu’s default repositories don’t carry all PHP versions. The ondrej/php PPA (maintained by Ondřej Surý, a Debian PHP package maintainer) is the standard source for installing non-default PHP versions on Ubuntu:

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update

The software-properties-common package provides the add-apt-repository command. After adding the PPA and running apt update, PHP 7.4 packages will be available via apt install.

Step 2a: Install PHP 7.4 for Apache

If your web server is Apache, it uses mod_php — PHP runs as an Apache module. Install PHP 7.4 and the commonly required extensions for WordPress and general PHP applications:

sudo apt install php7.4 php7.4-common php7.4-mysql php7.4-xml php7.4-xmlrpc   php7.4-curl php7.4-gd php7.4-imagick php7.4-cli php7.4-dev php7.4-imap   php7.4-mbstring php7.4-opcache php7.4-soap php7.4-zip php7.4-intl -y

After installation, disable the old PHP module and enable 7.4. Replace php7.2 below with your current active PHP version:

sudo a2dismod php7.2
sudo a2enmod php7.4
sudo service apache2 restart

To confirm Apache is now serving PHP 7.4, create a temporary info file:

echo "<?php phpinfo();" | sudo tee /var/www/html/info.php

Open http://your-server-ip/info.php in a browser and look for PHP Version 7.4.x at the top. If it still shows the old version, the old module may still be active — run apache2ctl -M | grep php to see which PHP modules are loaded. Once confirmed, delete the info file:

sudo rm /var/www/html/info.php

Step 2b: Install PHP 7.4 for Nginx (PHP-FPM)

Nginx doesn’t have a native PHP module — it passes PHP requests to a FastCGI process manager (PHP-FPM) via a Unix socket or TCP port. Install PHP 7.4 FPM alongside the extensions:

sudo apt install php7.4-fpm php7.4-common php7.4-mysql php7.4-xml php7.4-xmlrpc   php7.4-curl php7.4-gd php7.4-imagick php7.4-cli php7.4-imap   php7.4-mbstring php7.4-opcache php7.4-soap php7.4-zip php7.4-intl -y

Start and enable the PHP 7.4 FPM service:

sudo systemctl start php7.4-fpm
sudo systemctl enable php7.4-fpm

Verify it’s running and note the socket path:

sudo systemctl status php7.4-fpm
ls /run/php/

The socket will be at /run/php/php7.4-fpm.sock. Update your Nginx server block to point to the new socket — locate the fastcgi_pass line in your site config (typically in /etc/nginx/sites-available/) and update it:

# Change this:
fastcgi_pass unix:/run/php/php7.2-fpm.sock;

# To this:
fastcgi_pass unix:/run/php/php7.4-fpm.sock;

Test the Nginx configuration and reload:

sudo nginx -t
sudo systemctl reload nginx

Stop the old PHP-FPM version if it’s no longer needed:

sudo systemctl stop php7.2-fpm
sudo systemctl disable php7.2-fpm

Step 3: Verify PHP 7.4 is Active

Confirm both the CLI and web server versions:

php -v

This shows the CLI PHP version. For the web server version, use the phpinfo() approach described in Step 2a. Note that the CLI and web server can run different PHP versions — if you’re managing multiple projects or CLI cron jobs, both should be verified independently.

Check that your key extensions are loaded:

php -m | grep -E "mbstring|mysql|xml|curl|gd|opcache|zip"

Troubleshooting Common Issues

Apache returns 500 after switching modules

If Apache returns a 500 error after a2enmod php7.4, the old module may still be loaded alongside the new one — Apache won’t start cleanly with two PHP modules active. Run:

apache2ctl -M | grep php

You should see only php7_4_module. If an old version appears, disable it explicitly:

sudo a2dismod php7.2   # or php7.3, whichever is listed
sudo service apache2 restart

Check /var/log/apache2/error.log for the specific error if restarting still fails.

Nginx returns 502 Bad Gateway

A 502 from Nginx after switching to PHP-FPM 7.4 means Nginx can’t reach the FPM socket. Check:

sudo systemctl status php7.4-fpm
ls -la /run/php/php7.4-fpm.sock

If the socket doesn’t exist, PHP-FPM isn’t running — start it with sudo systemctl start php7.4-fpm. If it exists but Nginx still 502s, verify the socket path in your site config matches exactly what ls /run/php/ shows. Check /var/log/nginx/error.log for the specific socket path Nginx is trying to reach.

WordPress white screen or fatal errors after upgrade

A white screen or PHP fatal error typically means a required extension isn’t installed. WordPress needs at minimum: mbstring, mysql (or mysqli), xml, curl, gd, and zip. Check which are missing:

php -m | grep -E "mbstring|mysqli|xml|curl|gd|zip|imagick"

Install any that don’t appear:

sudo apt install php7.4-mbstring php7.4-xml php7.4-curl php7.4-gd php7.4-zip -y
sudo service apache2 restart   # or: sudo systemctl reload nginx

For more on diagnosing WordPress white screen errors, see how to fix the WordPress White Screen of Death.

PHP CLI version doesn’t match web server

If php -v shows a different version than your web server’s phpinfo(), the system’s default PHP CLI symlink points to a different version. To update it:

sudo update-alternatives --set php /usr/bin/php7.4

This is optional — many setups intentionally run different CLI and web server versions — but if your deployment scripts or WP-CLI depend on CLI PHP, align them.

PHP 7.4 End of Life: Next Steps

PHP 7.4 reached end of life on 28 November 2022. It no longer receives security patches. If 7.4 was a stepping stone in your upgrade path, the target should be a currently supported release:

  • PHP 8.0 (EOL November 2023) — also expired; skip unless your application blocks you here. See upgrading PHP to 8.0 on Ubuntu if you’re stepping incrementally.
  • PHP 8.2 (security support through December 2026) — the minimum recommended version for new deployments in 2026. See the PHP 8.2 upgrade guide.
  • PHP 8.4 (current stable, active support) — the recommended target for production deployments in 2026. See the PHP 8.4 upgrade guide.
  • PHP 8.5 (development/pre-release) — not recommended for production. See the PHP 8.5 on Ubuntu preview.

The process for each subsequent upgrade follows the same pattern as this guide: add the ondrej/php PPA (already done if you followed this guide), install the target PHP version and extensions, switch the web server module (Apache) or update the FPM socket path (Nginx), verify, and test the application.

Frequently asked questions

Yes. The upgrade from PHP 7.2 (or 7.3) to 7.4 follows the same process regardless of the starting version within the 7.x series: add the ondrej/php PPA, install the php7.4 packages, switch the web server module (Apache) or FPM socket (Nginx), and verify. You don't need to upgrade to 7.3 first before jumping to 7.4 — both 7.2 and 7.3 can be upgraded directly to 7.4 in one step. That said, PHP 7.4 reached end of life in November 2022, so if your application can run on 8.x, upgrade to PHP 8.2 or 8.4 instead.

No — PHP 7.4 has been end of life since November 2022 and no longer receives security patches. Running PHP 7.4 on a production server in 2026 means unpatched vulnerabilities in the PHP runtime itself. The currently supported PHP releases are 8.2 (security support through December 2026), 8.3 (active support), and 8.4 (active support, current stable). If you're on 7.4 and can't immediately move to 8.x, reducing attack surface (disabling unused extensions, using a WAF, keeping WordPress and plugins updated) is the short-term mitigation — but the proper fix is upgrading the PHP version.

The ondrej/php PPA is maintained by Ondřej Surý, who is also the official Debian PHP package maintainer. It provides PHP packages for Ubuntu that the default Ubuntu repositories don't include — either because Ubuntu's PHP version is pinned to a specific release, or because a newer PHP version was released after the Ubuntu LTS version shipped. It's the standard recommended source for non-default PHP versions on Ubuntu, used by millions of servers. The PPA is hosted on Launchpad (Ubuntu's official PPA infrastructure), not an unverified external source.

In Apache, PHP versions are managed via modules: a2dismod disables an active module, a2enmod enables a new one. The safe sequence is: (1) Install the new PHP version and extensions first. (2) Run a2dismod php7.x (replacing 7.x with your current version). (3) Run a2enmod php7.4. (4) Test the Apache configuration with apache2ctl configtest. (5) Restart Apache only after the config test passes. If you need to roll back, reverse the a2enmod/a2dismod steps and restart. Apache's module system makes PHP version switches reversible without reinstalling anything.

Nginx uses PHP-FPM via a FastCGI socket path configured in your server block. To switch versions: (1) Install php7.4-fpm and start the service. (2) Locate the fastcgi_pass line in your site config (e.g. /etc/nginx/sites-available/your-site) and update the socket from php7.2-fpm.sock (or php7.3-fpm.sock) to php7.4-fpm.sock. (3) Run nginx -t to validate the config. (4) Run systemctl reload nginx. You can run multiple PHP-FPM versions simultaneously — each has its own socket — which lets you serve different sites on different PHP versions from the same Nginx instance.

WordPress on PHP 7.4 requires: mysql (or mysqli and pdo_mysql), xml, curl, gd, mbstring, and zip. The WordPress health check (Tools → Site Health → Info → Server) lists which extensions are present. Commonly needed but sometimes omitted: imagick (for image processing in the media library), intl (for date/number formatting in multilingual sites), opcache (for PHP bytecode caching — significant performance improvement), and soap (for some payment gateway integrations). The extension install command is: sudo apt install php7.4-extension-name, followed by a web server restart to load the new module.

Photo of Ajay Khandal

Written by Ajay Khandal

I'm a freelance WordPress developer with 14+ years of experience building, fixing, and speeding up sites for businesses, agencies, and store owners across the US, UK, Europe, and Australia. I specialize in custom themes, WooCommerce, and performance — the kind of work that shows up as faster load times and fewer support tickets. No account managers, no outsourced tickets — you work directly with me, with replies typically inside 5 hours.

Work with me →