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;orprivate 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;. Nousekeyword 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 ?? $ypattern. - Preloading (OPcache). The
opcache.preloaddirective 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
mysqldumpdirectly. - 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 -vandphp --inibefore starting. Thephp.inilocation 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_phpviaa2dismod/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.


