2

While I know that php 8 is the default PHP choice on Ubuntu 22.04, I still use php 7 for my project. When installing packages related to PHP, the dependancies always pick php-common, php-*, etc.. and end up installing php 8 on the server.

Currently I have trouble installing Composer via apt install composer

So how do I tell the system that php-* is always mapped to php7.4-* and force libraries to always pick this given php version?

Thanh Trung
  • 121
  • 1
  • 1
  • 4

3 Answers3

2

PHP7 is no longer available in the core repository of Ubuntu 22.04, but you can install it using the PPA documented at https://launchpad.net/~ondrej/+archive/ubuntu/php/

  • I've already installed ondrej PPA. I know it's old but I still want the php core to always pick the prefered version of php. Not possible? – Thanh Trung Sep 29 '22 at 09:17
  • 1
    That might be possible, but as you haven't told how you install any other package, it's difficult to guess where this goes wrong – Nico Haase Sep 29 '22 at 09:23
1

To add support for older php version to be installed:

add-apt-repository ppa:ondrej/php && apt update -y

AFter you install the php7.4 packages you need, the following command will prompt you to select the default php version:

sudo update-alternatives --config php

Alex
  • 11
  • 2
0

This Solution That I followed and worked on myself:

Fix: Point the PPA to a supported suite

You can safely change the suite (plucky) to noble (Ubuntu 24.04) or jammy (22.04). Both have PHP 7.4 builds.

Open the file:

Sudo nano /etc/apt/sources.list.d/ondrej-ubuntu-php-plucky.sources

Change this line:

Suites: plucky
To:
Suites: noble (or jammy if noble fails)

Save & exit.

Update your package lists:

Sudo apt update

Install PHP 7.4:

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

If you have multiple PHP versions, switch the default:

sudo update-alternatives --install /usr/bin/php php /usr/bin/php7.4 74
sudo update-alternatives --config php
kero
  • 1