在Debian 12 上安装 PHP 5.6, 7.4

环境: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里勾选:
在Debian 12 上安装 PHP 5.6, 7.4_第1张图片

2023年7月实测可行

你可能感兴趣的:(Linux,工作环境,web,debian,php)