在Debian 12 上安装 PHP 5.6, 7.4

30 篇文章 0 订阅
13 篇文章 0 订阅

环境:Debian 12

Debian 12 默认的PHP版本为 8.2

如果直接安装php7.4就出现下面的报错:

sudo apt-get install libapache2-mod-php7.4 php7.4 php7.4-gd php7.4-opcache php7.4-mbstring php7.4-xml php7.4-json php7.4-zip php7.4-curl php7.4-imap php7.4-mysql php7.4-fpm
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package php7.4 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package libapache2-mod-php7.4 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package php7.4-fpm is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'libapache2-mod-php7.4' has no installation candidate
E: Package 'php7.4' has no installation candidate
E: Unable to locate package php7.4-gd
E: Couldn't find any package by glob 'php7.4-gd'
E: Couldn't find any package by regex 'php7.4-gd'
E: Unable to locate package php7.4-opcache
E: Couldn't find any package by glob 'php7.4-opcache'
E: Couldn't find any package by regex 'php7.4-opcache'
E: Unable to locate package php7.4-mbstring
E: Couldn't find any package by glob 'php7.4-mbstring'
E: Couldn't find any package by regex 'php7.4-mbstring'
E: Unable to locate package php7.4-xml
E: Couldn't find any package by glob 'php7.4-xml'
E: Couldn't find any package by regex 'php7.4-xml'
E: Unable to locate package php7.4-json
E: Couldn't find any package by glob 'php7.4-json'
E: Couldn't find any package by regex 'php7.4-json'
E: Unable to locate package php7.4-zip
E: Couldn't find any package by glob 'php7.4-zip'
E: Couldn't find any package by regex 'php7.4-zip'
E: Unable to locate package php7.4-curl
E: Couldn't find any package by glob 'php7.4-curl'
E: Couldn't find any package by regex 'php7.4-curl'
E: Unable to locate package php7.4-imap
E: Couldn't find any package by glob 'php7.4-imap'
E: Couldn't find any package by regex 'php7.4-imap'
E: Unable to locate package php7.4-mysql
E: Couldn't find any package by glob 'php7.4-mysql'
E: Couldn't find any package by regex 'php7.4-mysql'
E: Package 'php7.4-fpm' has no installation candidate

安装5.6和7.4正确的姿势为:

sudo apt update
sudo apt install software-properties-common ca-certificates lsb-release apt-transport-https
sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
wget -qO - https://packages.sury.org/php/apt.gpg | sudo apt-key add -
sudo apt update
sudo apt-get install libapache2-mod-php5.6
sudo apt-get install libapache2-mod-php7.4

多版本切换可以用下面的命令:
sudo update-alternatives --config php

也可以直接在Web Server里勾选:
在这里插入图片描述

2023年7月实测可行

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值