0

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?

Niyaz
  • 113
  • 5
  • 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. – Lex Li Mar 18 '23 at 17:18
  • @LexLi thanks for you suggestion, but my question is related to downgrading the version of php-fpm in Ubuntu 22.04 – Niyaz Mar 18 '23 at 17:31
  • 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. – Lex Li Mar 18 '23 at 17:51
  • 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. – Niyaz Mar 18 '23 at 18:18
  • 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? – Lex Li Mar 18 '23 at 19:04
  • 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. – Niyaz Mar 18 '23 at 19:29

1 Answers1

1

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.

  • 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? – Niyaz Mar 19 '23 at 07:49
  • There is no easy way to downgrade. no way without a risk of breaking things anyway. Switching is the safest way IMO. – Sandakelum Kumara Mar 19 '23 at 16:24