Report this

What is the reason for this report?

How can I install php7.4 on my Ubuntu 2204

Posted on December 5, 2024
CCST

By CCST

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…



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!

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.

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

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.

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.