更新升级 专属应用 系统故障 硬件故障 电脑汽车 鸿蒙刷机 鸿蒙开发Linux教程 鸿蒙开发Linux命令
当前位置:HMXT之家 > 鸿蒙开发Linux教程 > 在Ubuntu 22.04上安装PHP 8.0和PHP 8.0扩展的步骤

在Ubuntu 22.04上安装PHP 8.0和PHP 8.0扩展的步骤

更新时间:2022-12-26 16:02:15浏览次数:63+次

本文介绍在Ubuntu 22.04 Linux系统上安装PHP 8.0和PHP 8.0扩展的具体步骤,同样的方法也适用于Ubuntu 20.04、18.04发行版上。

在Ubuntu 22.04上安装PHP 8.0和PHP 8.0扩展的具体步骤

步骤1:更新Ubuntu系统

通过运行以下命令将所有系统包更新到最新版本:

sudo apt update

sudo apt -y upgrade

任何升级后都必须重新启动,运行以下命令即可:

sudo systemctl reboot

步骤2:添加PPA存储库以安装PHP 8.0,仅适用于Ubuntu 20.04/18.04

Ubuntu 22.04附带了PHP 8包和许多其他PHP 8集成所需的扩展。对于Ubuntu 20.04/18.04,最新的PHP包可以在PPA存储库中找到。运行下面共享的命令将此存储库添加到Ubuntu系统中:

Ubuntu 20.04/18.04,Ubuntu 22.04不需要:

sudo apt update

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

sudo add-apt-repository ppa:ondrej/php

当提示添加存储库时,按enter键,如下信息:

Debian oldstable and stable packages are provided as well: https://deb.sury.org/#debian-dpa

You can get more information about the packages at https://deb.sury.org

IMPORTANT: The <foo>-backports is now required on older Ubuntu releases.

BUGS&FEATURES: This PPA now has a issue tracker:

https://deb.sury.org/#bug-reporting

CAVEATS:

1. If you are using php-gearman, you need to add ppa:ondrej/pkg-gearman

2. If you are using apache2, you are advised to add ppa:ondrej/apache2

3. If you are using nginx, you are advised to add ppa:ondrej/nginx-mainline

   or ppa:ondrej/nginx

PLEASE READ: If you like my work and want to give me a little motivation, please consider donating regularly: https://donate.sury.org/

WARNING: add-apt-repository is broken with non-UTF-8 locales, see

https://github.com/oerdnj/deb.sury.org/issues/56 for workaround:

# LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php

 More info: https://launchpad.net/~ondrej/+archive/ubuntu/php

Press [ENTER] to continue or Ctrl-c to cancel adding it.

从更新输出中,您应该看到添加的存储库,如下图所示:

\

步骤3:在Ubuntu 22.04、20.04、18.04上安装PHP 8.0

更新APT索引,以确保包安装正常:

sudo apt update

然后在Ubuntu 22.04、20.04、18.04 Linux机器上安装PHP 8.0:

sudo apt install php8.0

按y键开始安装:

\

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

$ php -v

返回信息如下:

PHP 8.0.11 (cli)

表示已成功安装PHP 8.0版本。

步骤4:在Ubuntu 22.04、20.04、18.04上安装PHP 8扩展

要在Ubuntu 22.04、20.04、18.04上安装PHP 8扩展,请使用以下命令语法:

sudo apt install php8.0-<extension>

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

$ sudo apt install php8.0-

\

例子,比如运行以下命令:

sudo apt install php8.0-cli php8.0-common php8.0-imap php8.0-redis php8.0-snmp php8.0-xml php8.0-zip php8.0-mbstring

如果要列出所有PHP 8.0加载的模块,请使用以下命令:

$ php -m

如果在Nginx web浏览器中使用PHP,请确保PHP-fpm服务已启动并运行:

$ systemctl status php*-fpm.service

会返回如下截图:

\

表明PHP 8.0正在启动状态。