4

Recently I upgrade my Ubuntu from 20 to 22. I was using Php7.4 in Ubuntu 20 with the Apache server. After upgrading to Ubuntu 22, the Php Upgrades to 8.1 automatically. After that, I install Php7.4 also in my system. I can switch PHP version by using this command:

sudo update-alternatives --config php

If I use terminal I can see different PHP versions using php -v. But I am unable to use Php7.4 in apache. I am trying to install using this command:

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

But it's giving me the following error:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libapache2-mod-php7.4 : Depends: php8.1-common (= 8.1.2-1ubuntu2) but 8.1.5-1+ubuntu22.04.1+deb.sury.org+1.1 is to be installed
E: Unable to correct problems, you have held broken packages.

Again if I try to activate Php7.4 in apache using this command:

sudo a2enmod php7.4

I am getting this error:

ERROR: Module php7.4 does not exist!

Now how can I use Php7.4 in my Apache? Note, that Apache was installed in Ubuntu 20.

2

3 Answers 3

6

The problem seems to be related to Ubuntu 22* not including php 7.4, you need to add an external repository.

Try the following:

  1. sudo apt update && sudo apt upgrade
  2. sudo add-apt-repository ppa:ondrej/php -y
  3. sudo apt install php7.4
  4. sudo apt install php7.4-{cli,common,curl,zip,gd,mysql,xml,mbstring,json,intl}
  5. sudo update-alternatives --config php
  6. Select php 7.4.
  7. sudo apt-get install libapache2-mod-php7.4

And now it will work!

Source.

I had exactly the same problem and this worked for me.

1
  • Hi Martias, welcome to StackOverflow. Just a tip: 'Sauce' should be 'Source'. Commented Oct 4, 2022 at 9:56
3

You need to disable the PHP 8.1 and enable the php 7.4

Try this:

sudo a2dismod php8.1

after:

sudo a2enmod php7.2
1
  • 1
    Not working. I am getting this error when trying to run sudo a2enmod php7.4 ERROR: Module php7.4 does not exist! Commented Apr 28, 2022 at 17:40
1

I posted in AskUbuntu and got the solution. This is the link https://askubuntu.com/questions/1405324/how-can-i-use-php7-4-in-my-apache-in-ubuntu-22.

The solution is, In the "Application & Update" panel "For other packages, subscribe to:" I changed it from "all updates" to "only security patches/updates"- and when I changed it back to "all updates"- I could finally install everything. Then I did

sudo a2dismod php8.1

then

sudo a2enmod php7.4

after that restart apache2. And resolve the issue. I also switch the PHP version using this command:

sudo update-alternatives --config PHP

and restart the apache again. All is good now. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.