Composer 是现代 PHP 开发的重要工具。它是一个依赖项管理器,允许开发人员管理和控制 PHP 项目所需的包。通过自动安装和更新项目依赖项的过程,Composer 大大简化了 PHP 开发人员的工作流程。
在 Fedora 39 上安装 Composer
步骤 1。首先,更新系统软件包以确保您拥有最新版本。这可以使用以下命令完成:
<span class="pln">sudo dnf clean all sudo dnf update</span>
第2步。在 Fedora 上安装 Composer 39.
接下来,您需要使用 curl
命令下载 Composer 安装程序脚本。在终端中运行以下命令:
<span class="pln">curl </span><span class="pun">-</span><span class="pln">sS https</span><span class="pun">:</span><span class="com">//getcomposer.org/installer -o composer-setup.php</span>
为确保脚本完整性,请使用 Composer 网站上发布的哈希值:
<span class="pln">HASH</span><span class="pun">=</span><span class="str">"$(curl -sS https://composer.github.io/installer.sig)"</span><span class="pln"> php </span><span class="pun">-</span><span class="pln">r </span><span class="str">"if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"</span>
现在,您可以使用安装程序脚本安装 Composer。在终端中运行以下命令:
<span class="pln">sudo php composer</span><span class="pun">-</span><span class="pln">setup</span><span class="pun">.</span><span class="pln">php </span><span class="pun">--</span><span class="pln">install</span><span class="pun">-</span><span class="pln">dir</span><span class="pun">=</span><span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">bin </span><span class="pun">--</span><span class="pln">filename</span><span class="pun">=</span><span class="pln">composer</span>
要验证 Composer 是否已成功安装,您可以在终端中运行以下命令:
<span class="pln">composer </span><span class="pun">--</span><span class="pln">version</span>
下载 Composer 后,让我们将其配置为可全局访问。将 Composer 可执行文件移动到系统范围的目录,并将其添加到系统路径中:
<span class="pln">sudo mv composer </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">composer </span><span class="kwd">export</span><span class="pln"> PATH</span><span class="pun">=</span><span class="pln">$PATH</span><span class="pun">:</span><span class="pln">$HOME</span><span class="pun">/.</span><span class="pln">composer</span><span class="pun">/</span><span class="pln">vendor</span><span class="pun">/</span><span class="pln">bin source </span><span class="pun">~/.</span><span class="pln">bashrc</span>
第 3 步。在 PHP 项目中使用 Composer。
Composer 简化了项目初始化、依赖项管理和安装。导航到项目目录并执行:
<span class="pln">composer init</span>
按照交互式提示创建文件。完成后,安装项目依赖项:composer.json
<span class="pln">composer install</span>
Composer 会智能地获取和安装指定的依赖项,从而优化您的开发工作流程。
感谢您使用本教程在您的 Fedora 39 系统上安装 PHP 编写器。如需更多或有用的信息,我们建议您查看 Composer 官方网站。