When I needed to keep a legacy CodeIgniter project alive, figuring out how to install PHP 7.4 on Ubuntu in 2025 felt like digital archaeology.
Most guides were either outdated, overly complex, or assumed I had a time machine back to 2020. But with a little persistence—and a few broken dependencies later—I finally pieced together a clean, conflict-free way to run PHP 7.4 on a modern Ubuntu system.
Whether you’re maintaining an old app, contributing to a legacy FOSS project, or just love tinkering under the hood, this step-by-step guide will help you get PHP 7.4 running smoothly—no guesswork, no system bloat.
Let’s dive in and get your environment ready for action.
Why Use PHP 7.4 on Ubuntu?
Many web applications, including CodeIgniter, are built to run smoothly on PHP 7.4 due to its stability and broad extension support. While newer versions of PHP provide additional features, your application may not yet support them, necessitating the use of PHP 7.4 on Ubuntu. This guide helps ensure your environment matches the required PHP version.
· · ─ ·𖥸· ─ · ·
Preparing for a Clean PHP 7.4 Installation on Ubuntu
Before we dive into terminal commands, it’s important to understand why this process needs extra care in 2025. PHP 7.4 is no longer officially supported, and most modern Ubuntu repositories no longer include it by default. That means installing it requires tapping into trusted third-party sources, managing potential version conflicts, and ensuring your web server plays nicely with the setup.
This guide walks you through a clean, minimal, and stable install—especially useful if you’re maintaining a CodeIgniter project or deploying a legacy system. We’ll keep things simple, focused, and beginner-friendly.
Let’s get your system ready to roll.
Step 1: Remove Existing PHP Version
If you have already installed a newer version of PHP (like PHP 8.x), it must be removed before installing PHP 7.4 on Ubuntu.
sudo apt remove php8.*
sudo apt autoremove
This command removes PHP 8.x and its dependencies, freeing up your system for PHP 7.4 installation.
Related: Ubuntu CodeIgniter Setup: A Step-by-Step Installation Guide
Step 2: Add the PHP PPA Repository
Since PHP 7.4 is not included in the default Ubuntu repositories, you need to add the Ondřej Surý PPA, which maintains older versions of PHP.
Add the PPA:
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php sudo
apt update
This repository provides access to PHP 7.4 on Ubuntu along with other older PHP versions.
Step 3: Install PHP 7.4 and Necessary Extensions
Install PHP 7.4 along with the required extensions to run your CodeIgniter application. These extensions include mysql
, xml
, mbstring
, and more.
sudo apt install php7.4 php7.4-cli php7.4-fpm php7.4-mysql php7.4-xml php7.4-mbstring php7.4-json php7.4-curl php7.4-zip php7.4-intl
Step 4: Set PHP 7.4 as the Default Version
After installing PHP 7.4, ensure that it is set as the default version on your system. If multiple versions of PHP are installed, you can configure Ubuntu to use PHP 7.4 on Ubuntu by default:
sudo update-alternatives --set php /usr/bin/php7.4
sudo update-alternatives --set phpize /usr/bin/phpize7.4
sudo update-alternatives --set php-config /usr/bin/php-config7.4
Step 5: Configure Your Web Server
Now that PHP 7.4 on Ubuntu is installed, you need to configure your web server to work with PHP 7.4. Instructions are provided below for both Apache and Nginx.
Apache
If you’re using Apache, disable the current PHP module (for versions like PHP 8.x) and enable PHP 7.4:
sudo a2dismod php8.*
sudo a2enmod php7.4
sudo systemctl restart apache2
Nginx
For Nginx, update your site configuration to point to the PHP 7.4 FPM socket:
Edit your site’s Nginx configuration file (usually located at /etc/nginx/sites-available/your-site
).
Update the fastcgi_pass
directive to use the PHP 7.4 socket:
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
Restart Nginx and PHP-FPM:
sudo systemctl restart nginx
sudo systemctl restart php7.4-fpm
Step 6: Verify PHP Version
To confirm that PHP 7.4 is installed correctly, run the following command:
php -v
You should see output like:
PHP 7.4.33 (cli) (built: ...)
Step 7: Test Your CodeIgniter Application
Now that PHP 7.4 on Ubuntu is installed, test your CodeIgniter application by navigating to your site in a browser. Ensure that all required PHP extensions are enabled for your application to function correctly. You can check installed PHP modules using:
php -m
If any necessary extensions are missing, install them using:
sudo apt install php7.4-<extension-name>
For more information on configuring PHP for CodeIgniter, refer to the official CodeIgniter documentation.
· · ─ ·𖥸· ─ · ·
Troubleshooting Tips
Permission Errors
Verify that your application files have the correct permissions and ownership.
Missing Extensions
If you encounter errors about missing PHP extensions, install them using
sudo apt install php7.4-<extension>.
Web Server Issues
Ensure your web server is correctly configured to use PHP 7.4. Restart the server after making changes.
· · ─ ·𖥸· ─ · ·
Wrapping Up: PHP 7.4 on Ubuntu Without the Headaches
Setting up PHP 7.4 on Ubuntu might feel like fighting upstream in 2025, but once you’ve got it dialed in, everything—from CodeIgniter apps to old deployment scripts—just works.
I’ve found that keeping lean, well-documented environments like this not only helps with legacy maintenance, but also keeps you sharp in navigating package conflicts and system-level tweaks—skills every FOSS dev should have in their toolkit.
If this guide helped save your weekend (or your production server), consider bookmarking it for future use—or better yet, share it with a teammate who’s stuck in PHP version limbo.
· · ─ ·𖥸· ─ · ·
Like This? Get More FOSS-Focused Dev Guides Straight to Your Inbox
If this guide helped you navigate the quirks of PHP 7.4 on Ubuntu, you’ll love what’s coming next. I regularly publish hands-on tutorials, system hacks, and real-world dev workflows—always FOSS-first, always beginner-friendly.
Subscribe now and stay ahead of the curve without getting buried in outdated Stack Overflow threads.
Leave a Reply