在Debian 11/10/9上安装PHP 8.0及PHP 8.0扩展的方法

本文介绍如何在Debian 11/10/9 Linux操作系统上安装PHP 8.0版本及其PHP 8.0扩展的方法。PHP是一种用于WEB开发的强大脚本语言,任何PHP脚本都可以在安装了PHP运行时的Linux、Windows、macOS和Unix系统上执行,当前经过测试,PHP 8可安装在Debian 11/10/9 Linux机器上。

按照以下方法在Debian 11/10/9系统上安装PHP 8.0版本

1、更新系统

在Debian 11/10/9上开始安装PHP 8之前,请将系统更新到最新版本:

sudo apt update

sudo apt -y upgrade

由于可能有内核更新,请考虑在升级后重新启动系统:

sudo reboot

2、添加SurýAPT存储库

Debian的PHP 8包可以在DEB.SURY.ORG存储库中找到。安装所需的依赖项:

sudo apt update

sudo apt install -y lsb-release ca-certificates apt-transport-https software-properties-common gnupg2

将PHP包APT存储库添加到Debian服务器:

echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/sury-php.list

导入存储库密钥:

wget -qO - https://packages.sury.org/php/apt.gpg | sudo apt-key add -

执行包索引更新以确认已添加存储库:

$ sudo apt update

Hit:1 http://mirror.hetzner.de/debian/packages buster InRelease

Hit:2 http://security.debian.org buster/updates InRelease

Hit:3 http://mirror.hetzner.de/debian/packages buster-updates InRelease

Hit:4 http://mirror.hetzner.de/debian/packages buster-backports InRelease

Hit:5 http://mirror.hetzner.de/debian/security buster/updates InRelease

Hit:6 http://deb.debian.org/debian buster InRelease

Hit:7 http://deb.debian.org/debian buster-updates InRelease

Hit:8 http://deb.debian.org/debian buster-backports InRelease

Get:9 https://packages.sury.org/php buster InRelease [6,759 B]

Get:10 https://packages.sury.org/php buster/main amd64 Packages [148 kB]

Fetched 155 kB in 2s (83.2 kB/s)

Reading package lists... Done

Building dependency tree

Reading state information... Done

7 packages can be upgraded. Run 'apt list --upgradable' to see them.

3、在Debian 11、Debian 10、Debian 9上安装PHP 8

随着存储库的添加,您可以开始在Debian 11/10/9上安装PHP 8.0:

sudo apt update 

sudo apt install php8.0

按y键开始安装,输出的信息如下:

Reading state information... Done

The following additional packages will be installed:

  apache2-bin libapache2-mod-php8.0 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libbrotli1 libgdbm-compat4 libjansson4 liblua5.2-0 libperl5.28

  libsodium23 perl php-common php8.0-cli php8.0-common php8.0-opcache php8.0-readline psmisc

Suggested packages:

  apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser php-pear perl-doc libterm-readline-gnu-perl | libterm-readline-perl-perl make

  libb-debug-perl liblocale-codes-perl

Recommended packages:

  apache2

The following NEW packages will be installed:

  apache2-bin libapache2-mod-php8.0 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libbrotli1 libgdbm-compat4 libjansson4 liblua5.2-0 libperl5.28

  libsodium23 perl php-common php8.0 php8.0-cli php8.0-common php8.0-opcache php8.0-readline psmisc

0 upgraded, 20 newly installed, 0 to remove and 7 not upgraded.

Need to get 10.4 MB of archives.

After this operation, 55.1 MB of additional disk space will be used.

Do you want to continue? [Y/n] y

确认服务器上的默认PHP版本:

$ php -v

PHP 8.0.9 (cli)

4、在Debian 11/10/9上安装PHP 8扩展

要在Debian上安装PHP 8扩展,请使用以下命令语法:

sudo apt install php8.0-<extension>

注:<extension>替换为实际的扩展名。

一些可用的扩展如下所示:

$ sudo apt install php8.0-

在Debian 11/10/9上安装PHP 8.0及PHP 8.0扩展的方法

例子:

sudo apt install php8.0-{mysql,cli,common,imap,ldap,xml,fpm,curl,mbstring,zip}

用y键接受安装提示,输出的信息如下:

The following additional packages will be installed:

  libc-client2007e libonig5 libxslt1.1 libzip4 mlock

Suggested packages:

  uw-mailutils php-pear

The following NEW packages will be installed:

  libc-client2007e libonig5 libxslt1.1 libzip4 mlock php8.0-curl php8.0-fpm php8.0-imap php8.0-ldap php8.0-mbstring php8.0-mysql php8.0-xml php8.0-zip

0 upgraded, 13 newly installed, 0 to remove and 7 not upgraded.

Need to get 3,308 kB of archives.

After this operation, 10.3 MB of additional disk space will be used.

Do you want to continue? [Y/n] y

对存储库中可用的所有其他PHP扩展使用相同的安装格式。如果要检查加载的PHP模块,请使用以下命令:

$ php -m

至此,在Debian 11/10/9系统上安装PHP 8.0及其扩展完成。

栏目相关文章