Skip to content

Install PHP 7.4 on Ubuntu 26.04

How to Install PHP 7.4 on Ubuntu 26.04

PHP 7.4 reached end of life in November 2022 but is still needed for legacy applications. Ubuntu 26.04 ships with PHP 8.5 by default. To install PHP 7.4, you must use the Ondřej Surý PPA. This guide covers installation and configuration.


Prerequisites

  • Ubuntu 26.04 LTS
  • Root or sudo access
  • Internet connection
  • Apache or Nginx web server (optional)
Warning: PHP 7.4 is End-of-Life and no longer receives security updates. Use only for legacy development or isolated environments, not production.

Method 1: Install PHP 7.4 from Ondřej Surý PPA

Step 1: Install Dependencies

sudo apt update && sudo apt install -y software-properties-common

Step 2: Add PHP PPA

sudo add-apt-repository ppa:ondrej/php

Press ENTER when prompted to add the repository.

Step 3: Update Package Lists

sudo apt update

Step 4: Install PHP 7.4

sudo apt install -y php7.4 php7.4-cli php7.4-common

Step 5: Install Common Extensions

sudo apt install -y php7.4-mysql php7.4-gd php7.4-xml php7.4-zip php7.4-mbstring php7.4-curl php7.4-json php7.4-intl php7.4-bcmath php7.4-soap

Step 6: Verify Installation

php7.4 -v

Should output: PHP 7.4.33

Success! PHP 7.4 is installed!

Method 2: Install with PHP-FPM (Nginx)

Step 1: Install PHP 7.4 FPM

sudo apt install -y php7.4-fpm

Step 2: Start and Enable FPM

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

Step 3: Check FPM Status

sudo systemctl status php7.4-fpm

Switch Default PHP Version

Ubuntu 26.04 ships with PHP 8.5. To set PHP 7.4 as default:

For CLI

sudo update-alternatives --config php

Select the number for PHP 7.4 from the list.

Set Apache Module

sudo a2dismod php8.5
sudo a2enmod php7.4
sudo systemctl restart apache2

Switch FPM for Nginx

Update your Nginx server block to use PHP 7.4 socket:

fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;

Install PHP 7.4 with Apache

sudo apt install -y php7.4 libapache2-mod-php7.4

Available PHP 7.4 Extensions

  • php7.4-mysql – MySQL/MariaDB
  • php7.4-pgsql – PostgreSQL
  • php7.4-sqlite3 – SQLite
  • php7.4-curl – cURL
  • php7.4-gd – Image processing
  • php7.4-xml – XML parsing
  • php7.4-zip – ZIP compression
  • php7.4-mbstring – Multibyte string
  • php7.4-json – JSON support
  • php7.4-intl – Internationalization
  • php7.4-bcmath – BCMath precision math
  • php7.4-soap – SOAP client
  • php7.4-imagick – ImageMagick

Useful Commands

List Installed PHP Modules

php7.4 -m

Check PHP Info

php7.4 -i | grep "Loaded Configuration File"

PHP Config File Location

/etc/php/7.4/cli/php.ini
/etc/php/7.4/apache2/php.ini
/etc/php/7.4/fpm/php.ini

Uninstall PHP 7.4

Remove PHP 7.4 and Extensions

sudo apt autoremove --purge php7.4* -y

Remove PPA Repository

sudo add-apt-repository --remove ppa:ondrej/php

Troubleshooting

PPA Add Fails (Locale Error)

LC_ALL=C.UTF-8 sudo add-apt-repository ppa:ondrej/php

PHP 7.4 Package Not Found

Ensure PPA was added correctly and update:

sudo apt update
apt-cache search php7.4

Multiple PHP Versions Conflict

Use full binary path to avoid conflicts:

/usr/bin/php7.4 -v

FPM Socket Missing

ls -la /var/run/php/
sudo systemctl restart php7.4-fpm
Note: Ubuntu 26.04 defaults to PHP 8.5. Use php7.4 explicitly instead of php to run the correct version.

PHP Version Summary

  • Ubuntu 26.04 default: PHP 8.5
  • PHP 7.4 status: End of Life (Nov 2022)
  • PPA version: 7.4.33 (latest)
  • Last release: 7.4.33

Conclusion

PHP 7.4 is now installed on Ubuntu 26.04! Key points:

  • Installed via ppa:ondrej/php
  • Use php7.4 for version-specific commands
  • Switch between versions with update-alternatives
  • EOL – not recommended for production
Pro Tip: Consider upgrading to PHP 8.3+ for security support. Use Docker with PHP 7.4 for legacy app isolation.