Score:0

How to downgrade php-fpm from php-fpm8.1 to php-fpm7.4 in Ubuntu 22.04?

us flag

I installed php-fpm8.1 with nginx in Ubuntu 22.04, but php-fpm8.1 is incompatible with some old code; I want to downgrade to php-fpm7.4 without damaging anything. How can I do that?

Lex Li avatar
vn flag
PHP 7.x are all end of life, so on a modern system like Ubuntu 22.04, you'd better install a container environment and host legacy container images with PHP 7.x instead.
Niyaz avatar
us flag
@LexLi thanks for you suggestion, but my question is related to downgrading the version of php-fpm in Ubuntu 22.04
Lex Li avatar
vn flag
But what have you tried so far? I assume AskUbuntu.com contains all necessary tips in https://askubuntu.com/questions/1432704/force-install-php-7-packages-on-ubuntu-22-04-lts and Ondřej Surý made old PHP versions available on 22.04.
Niyaz avatar
us flag
As I said my question is more related to downgrading in general, now let me simply the problem. How to downgrade php-fpm8.1 to php-fpm8.0. Or how to downgrade php-fpm in Ubuntu 20.04 or 16.04? Regardless of old/new versions.
Lex Li avatar
vn flag
So, you don't know how to uninstall a package and install another instead with `apt` or `apt-get`? Can I understand it that way?
Niyaz avatar
us flag
Yes, I can do that. I'm working with a production server; I need a safe way to do that. Are there any ways to do it directly besides removing/reinstalling? For example, this [link](https://laracasts.com/discuss/channels/guides/downgrade-php-version-ubuntu-2204) downgrade php8.
Score:1
cn flag

You should look to switch PHP version instead of downgrading it. You can have multiple PHP versions running on your server at the same time. You can even have different PHP versions for each of your domains, directories.

I'm adapting these instructions from How to use Multiple PHP Versions with Virtualmin and Nginx.

Add ondrej/php PPA

add-apt-repository ppa:ondrej/php

update apt cache

apt update

install php 7.4 and modules

apt install php7.4-memcache php7.4-imagick php7.4-redis php7.4-bcmath php7.4-intl php7.4-mcrypt php7.4-cgi php7.4-fpm php7.4-mysql php7.4-curl php7.4-gd php7.4-imap php7.4-tidy php7.4-xmlrpc php7.4-xml php7.4-xsl php7.4-mbstring php7.4-zip php7.4-cli php7.4-soap php7.4-gmp php7.4-sqlite3

Now open nginx config file for your domain

nano /etc/nginx/sites-available/domain.com.conf

Update php socket

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    fastcgi_read_timeout 600;
 }

Restart nginx

service nginx restart

Try it.

Niyaz avatar
us flag
Thanks for your answer, I know about this solution, as I know the cloud server provides uses the same technique when they allow to switch between php versions. But my question is: Is there any easy and direct way to downgrade php-fpm in Ubuntu? if yes, then how?
Tharindu Kumara avatar
cn flag
There is no easy way to downgrade. no way without a risk of breaking things anyway. Switching is the safest way IMO.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.