<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/install.unix.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'install.unix.dnf.php',
    1 => '在使用 DNF 的 GNU/Linux 发行版上通过软件包安装',
    2 => '在使用 DNF 的 GNU/Linux 发行版上通过软件包安装',
  ),
  'up' => 
  array (
    0 => 'install.unix.php',
    1 => '在 Unix 系统上安装 PHP',
  ),
  'prev' => 
  array (
    0 => 'install.unix.debian.php',
    1 => 'Debian GNU/Linux 及其相关发行版上从软件包中安装 PHP',
  ),
  'next' => 
  array (
    0 => 'install.unix.openbsd.php',
    1 => 'OpenBSD 上从软件包或者 ports 中安装 PHP',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'install/unix/dnf.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="install.unix.dnf" class="sect1">
 <h2 class="title">在使用 DNF 的 GNU/Linux 发行版上通过软件包安装</h2>
 <p class="simpara">
  PHP 既可从源码安装，也可通过软件包在使用 DNF 的系统上安装，例如
  Red Hat Enterprise Linux、OpenSUSE、Fedora、CentOS、Rocky
  Linux 和 Oracle Enterprise Linux。
 </p>
 <div class="warning"><strong class="warning">警告</strong>
 <p class="para">
  第三方提供的版本被视为非官方版本，不直接受 PHP 项目支持。
  除非可以通过 <a href="https://www.php.net/downloads.php" class="link external">&raquo;&nbsp;官方下载区</a>的构建版重现，
  否则遇到的任何错误都应报告给这些非官方构建版的提供者。
 </p>
</div>
 <p class="simpara">
  这些软件包可通过 <strong class="command">dnf</strong> 命令安装。
 </p>
 <div class="sect2" id="install.unix.dnf.packages">
  <h3 class="title">安装软件包</h3>
  <p class="simpara">
   首先，注意可能还需要安装其他相关软件包，例如用于 <a href="https://pear.php.net/" class="link external">&raquo;&nbsp;PEAR</a> 的
   <code class="literal">php-pear</code>，或用于 <a href="book.mysqlnd.php" class="link">MySQL 扩展</a>的 
   <code class="literal">php-mysqlnd</code>。
  </p>
  <p class="simpara">
   其次，在安装软件包前，建议确保软件包列表为最新状态。通常可通过运行 <strong class="command">dnf update</strong> 命令完成此操作。
  </p>
  <div class="example" id="install.unix.dnf.example">
   <p><strong>示例 #1 DNF 安装示例</strong></p>
   <div class="example-contents">
<div class="shellcode"><pre class="shellcode"># dnf install php php-common</pre>
</div>
   </div>

  </div>
  <p class="simpara">
   DNF 会自动为 Web 服务器安装 PHP 的配置，但可能需要重启 Web 服务器才能使更改生效。例如：
  </p>
  <div class="example" id="install.unix.dnf.example2">
   <p><strong>示例 #2 安装 PHP 后重启 Apache</strong></p>
   <div class="example-contents">
<div class="shellcode"><pre class="shellcode"># sudo systemctl restart httpd</pre>
</div>
   </div>

  </div>
 </div>
 <div class="sect2" id="install.unix.dnf.config">
  <h3 class="title">更精细的配置控制</h3>
  <p class="para">
   上一节中仅安装了 PHP 的核心模块。通常还需要额外的模块，例如 <span class="simplelist"><a href="book.mysql.php" class="link">MySQL</a>, <a href="book.curl.php" class="link">cURL</a>, <a href="book.image.php" class="link">GD</a>, 等</span>，这些模块也可通过 <strong class="command">dnf</strong> 命令进行安装。
  </p>
  <div class="example" id="install.unix.dnf.config.example">
   <p><strong>示例 #3 列出额外 PHP 软件包的方法</strong></p>
   <div class="example-contents">
<div class="shellcode"><pre class="shellcode"># dnf search php</pre>
</div>
   </div>

  </div>
  <p class="simpara">
   软件包列表将包含大量基础 PHP 组件（如 <code class="literal">php-cli</code>、<code class="literal">php-fpm</code>
   和 <code class="literal">php-devel</code>）以及众多 PHP 扩展。安装扩展时，系统会根据依赖关系自动安装所需的其他软件包。
  </p>
  <div class="example" id="install.unix.dnf.config.example2">
   <p><strong>示例 #4 安装 PHP 的 MySQL、GD 扩展</strong></p>
   <div class="example-contents">
<div class="shellcode"><pre class="shellcode"># dnf install php-mysqlnd php-gd</pre>
</div>
   </div>

  </div>
  <p class="simpara">
   DNF 会自动在不同的 <var class="filename">php.ini</var> 相关文件（如 <var class="filename">/etc/php/8.3/php.ini</var>、<var class="filename">/etc/php/8.3/conf.d/*.ini</var>
   等）中添加相应的行，并根据扩展添加类似 <code class="literal">extension=foo.so</code> 的条目。但需重启 Web 服务器（如 Apache）后，这些更改才会生效。
  </p>
 </div>
</div><?php manual_footer($setup); ?>