我正在按照互联网教程安装 magento2 并使用 Windows cmd.exe 在我的电脑中创建一个项目。
当我尝试安装在文件夹中时,出现此错误:
C:\MAMP\htdocs>composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento2
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Root composer.json requires magento/product-community-edition 2.4.6-p2 -> satisfiable by magento/product-community-edition[2.4.6-p2].
- magento/product-community-edition 2.4.6-p2 requires ext-gd * -> it is missing from your system. Install or enable PHP's gd extension.
Problem 2
- magento/magento2-functional-testing-framework[4.3.1, ..., 4.4.2] require ext-intl * -> it is missing from your system. Install or enable PHP's intl extension.
- Root composer.json requires magento/magento2-functional-testing-framework ^4.3.1 -> satisfiable by magento/magento2-functional-testing-framework[4.3.1, ..., 4.4.2].
您遇到的错误消息与缺少 Magento 2 及其依赖项所需的 PHP 扩展有关。要解决此问题,您需要在 PHP 配置中启用 gd 和 intl 扩展。以下是执行此操作的步骤:
启用GD扩展:
Magento 2 需要 GD(Graphics Draw)扩展来进行图像处理。要启用它,请按照下列步骤操作:
在文本编辑器中打开 PHP 配置文件 (php.ini)。该文件的位置可能会有所不同,具体取决于您的 PHP 安装。常见路径有:
对于 MAMP:/Applications/MAMP/bin/php/php{版本}/php.ini
对于 XAMPP:C:\xampp\php\php.ini
搜索以下行(可能会用分号注释掉;):
;extension=gd
extension=gd
启用国际分机:
Magento 2 还需要 Intl(国际化)扩展。要启用它:
如前所述打开 PHP 配置文件 (php.ini)。
搜索以下行(可能会用分号注释掉;):
;extension=intl
extension=intl
验证扩展安装:
为了确保扩展已安装并启用,您可以创建一个包含以下内容的 PHP 文件(例如 phpinfo.php),并通过您的 Web 服务器访问它:
<?php
phpinfo();
在 PHP 信息页面中搜索“gd”和“intl”部分,以确认这两个扩展均已启用。
重试 Magento 安装:
启用这两个扩展并在 PHP 信息中验证其状态后,请尝试再次运行 Magento 安装命令:
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento2
现在应该可以继续进行,不会出现之前的错误。
通过启用必要的 PHP 扩展,您将确保 Magento 2 及其依赖项具有在您的系统上正常运行所需的功能。