分享最新优惠信息
购买主机更加划算

Debian 9 | Debian 10系统安装PHP 8.0详细过程介绍

PHP是用于Web开发的功能强大的脚本语言,任何PHP脚本语言都可以在已安装PHP的Linux、Windows、macOS和Unix系统上运行。在本文中,小编将简单介绍下Debian 9 | Debian 10系统安装PHP 8.0的简单过程。

需要注意的是,PHP 8.0的正式发布时间是2020年11月26日,该版本的PHP将具有许多新功能和性能改进,比较值得期待,这意味着可能需要对代码进行一些修改才能使其在PHP 8.0上运行。此外,PHP 8.0附带的一些不错的新功能包括JIT编译器,命名参数,联合类型,属性等新的特色功能。

步骤1:更新系统系统

在安装PHP8.0之前,需要将Debian 9 | Debian 10系统更新到最新版本,执行命令如下:

sudo apt update
sudo apt -y upgrade

由于可能会有内核更新,因此升级之前建议重新启动系统。

sudo reboot

步骤2:添加SurýAPT存储库

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

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

将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:安装PHP 8.0版本

添加存储库后就可以开始在Debian 9 | Debian 10系统上安装PHP 8.0,执行以下命令:

sudo apt update 
sudo apt install php8.0

按 键开始安装:

....
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.0RC3 (cli) (built: Nov  3 2020 14:33:19) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.0RC3, Copyright (c), by Zend Technologies

步骤4:安装PHP 8.0扩展

在Debian 9 | Debian 10系统安装PHP 8.0扩展,可以使用以下命令语法:

sudo apt install php8.0-<extension>
  • 注意:<extension>替换为实际的扩展名。

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

$ sudo apt install php8.0-
php8.0-bcmath            php8.0-curl-dbgsym       php8.0-gmp-dbgsym        php8.0-mysql             php8.0-pspell-dbgsym     php8.0-tidy
php8.0-bcmath-dbgsym     php8.0-dba               php8.0-imap              php8.0-mysql-dbgsym      php8.0-readline          php8.0-tidy-dbgsym
php8.0-bz2               php8.0-dba-dbgsym        php8.0-imap-dbgsym       php8.0-odbc              php8.0-readline-dbgsym   php8.0-xdebug
php8.0-bz2-dbgsym        php8.0-dev               php8.0-interbase         php8.0-odbc-dbgsym       php8.0-snmp              php8.0-xml
php8.0-cgi               php8.0-enchant           php8.0-interbase-dbgsym  php8.0-opcache           php8.0-snmp-dbgsym       php8.0-xml-dbgsym
php8.0-cgi-dbgsym        php8.0-enchant-dbgsym    php8.0-intl              php8.0-opcache-dbgsym    php8.0-soap              php8.0-xsl
php8.0-cli               php8.0-fpm               php8.0-intl-dbgsym       php8.0-pgsql             php8.0-soap-dbgsym       php8.0-zip
php8.0-cli-dbgsym        php8.0-fpm-dbgsym        php8.0-ldap              php8.0-pgsql-dbgsym      php8.0-sqlite3           php8.0-zip-dbgsym
php8.0-common            php8.0-gd                php8.0-ldap-dbgsym       php8.0-phpdbg            php8.0-sqlite3-dbgsym
php8.0-common-dbgsym     php8.0-gd-dbgsym         php8.0-mbstring          php8.0-phpdbg-dbgsym     php8.0-sybase
php8.0-curl              php8.0-gmp               php8.0-mbstring-dbgsym   php8.0-pspell            php8.0-sybase-dbgsym

例如:

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 9 | Debian 10系统安装PHP 8.0的全部过程,仅供参考。目前PHP 8.0即将正式发布,有需要在Debian 9 | Debian 10系统安装PHP 8.0的小伙伴可以参考上述教程进行设置。

未经允许不得转载:惠主机 » Debian 9 | Debian 10系统安装PHP 8.0详细过程介绍

说点什么?

  • 昵称 (必填)
  • 邮箱 (必填)