Question

How can I install php7.4 on my Ubuntu 2204

Hello, I hope to install php7.4 but failed with some article which posted in last year or before…

the current default is 8.1 but still need 7.4 for old website…

Please help and big thanks in advance…


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
December 5, 2024

Hi there!

Installing PHP 7.4 on Ubuntu 22.04 can be tricky since it’s no longer included in the default repositories. However, you can still install it using the Ondřej Surý PPA, which maintains older PHP versions.

Here’s how you can do it step-by-step:

This repository contains all supported PHP versions:

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

Press Enter when prompted to confirm.

Once the PPA is added, refresh your package list:

sudo apt update

Now, you can install PHP 7.4 and any required modules:

sudo apt install -y php7.4 php7.4-cli php7.4-fpm php7.4-mysql php7.4-curl php7.4-mbstring php7.4-xml

Replace or add modules as per your project’s requirements.

If multiple PHP versions are installed, you can set PHP 7.4 as the default:

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

Verify by checking the PHP version:

php -v

Don’t forget to restart your web server to apply the changes:

For Nginx:

sudo systemctl restart php7.4-fpm
sudo systemctl restart nginx

For Apache:

sudo systemctl restart apache2

One thing to keep in mind is that PHP 7.4 reached its end of life (EOL) on November 28, 2022, and no longer receives security updates. For production websites, consider upgrading to a supported version like PHP 8.1 or 8.2 if possible.

Let me know if you run into any issues!

- Bobby

KFSys
Site Moderator
Site Moderator badge
December 7, 2024

Heya,

You just need to add the proper repo and you are good to go:

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

and now you are good to go. You can install php7.4 by using:

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

You can add as much php7.4-extensions as you like and need.

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.