在 Magento 2.4.3 中手动下载和安装样本数据

步骤 1:手动下载样本数据

1. 从 GitHub 获取样本数据包

Magento 官方在 GitHub 上提供了样本数据包,您可以直接从中下载所需的文件。

下载链接
使用 Git 下载样本数据
  1. 打开终端或命令提示符。

  2. 导航到您的 Magento 根目录。

    bash 复制代码
    cd /path/to/magento/root
  3. 克隆样本数据仓库:

    bash 复制代码
    git clone https://github.com/magento/magento2-sample-data.git
  4. 切换到特定版本:

    如果您需要特定的版本,可以切换到该版本的分支。例如,使用 2.4.3 版本:

    bash 复制代码
    cd magento2-sample-data
    git checkout 2.4.3

2. 手动下载 ZIP 文件

如果您不想使用 Git,也可以直接从 GitHub 下载 ZIP 文件。

  1. 访问 GitHub 页面 :Magento 2.4.3 Sample Data
  2. 点击"Code"按钮,然后选择"Download ZIP"。
  3. 解压 ZIP 文件到 Magento 根目录。
bash 复制代码
unzip magento2-sample-data-main.zip -d /path/to/magento/root/

步骤 2:安装样本数据

1. 将样本数据合并到 Magento 项目中

在您将样本数据克隆或解压到 Magento 根目录后,接下来需要将样本数据合并到您的 Magento 项目中。

通过命令行合并样本数据
bash 复制代码
php -f magento2-sample-data/dev/tools/build-sample-data.php -- --ce-source="/path/to/magento/root"

这将把样本数据合并到 Magento 的项目结构中。

2. 运行 Composer 安装

在合并样本数据后,您需要运行 Composer 以安装和更新相关的依赖项。

bash 复制代码
cd /path/to/magento/root
composer install

确保所有的依赖项都安装正确。

3. 执行数据库更新和数据导入

完成样本数据的合并和 Composer 安装后,需要更新数据库并导入样本数据。

更新数据库
bash 复制代码
php bin/magento setup:upgrade

此命令将执行所有必要的数据库迁移,并将样本数据导入到数据库中。

部署静态内容
bash 复制代码
php bin/magento setup:static-content:deploy -f

部署静态内容以确保前端资源可用。

4. 清除缓存和重新索引

最后,确保清除缓存并重新索引数据以更新 Magento 的运行状态。

清除缓存
bash 复制代码
php bin/magento cache:clean
php bin/magento cache:flush
重新索引数据
bash 复制代码
php bin/magento indexer:reindex

这将确保所有的索引器数据与新的样本数据一致。

验证样本数据安装

完成上述步骤后,您可以通过访问 Magento 前台和后台来验证样本数据的安装情况。

前台验证

  1. 打开浏览器并访问商店 URL (如 http://your-magento-domain.com)。
  2. 检查产品、类别、CMS 页面等内容是否已被样本数据填充。

后台验证

  1. 登录到 Magento 管理后台。
  2. 导航到"产品" > "目录",查看样本产品。
  3. 导航到"销售" > "订单",查看样本订单。
  4. 查看客户、促销等其他样本数据的正确性。

常见问题与解决

1. Composer 问题

  • 如果在运行 Composer 命令时遇到问题,确保您使用的是 Composer 2,并且已正确配置。

2. 权限问题

  • 确保您的文件和目录权限设置正确:

    bash 复制代码
    find . -type f -exec chmod 644 {} \;
    find . -type d -exec chmod 755 {} \;
    chmod -R 777 var/ pub/ generated/

3. PHP 内存限制

  • 如果遇到内存限制问题,增加 PHP 内存限制:

    ini 复制代码
    memory_limit = 2G
相关推荐
Linux运维技术栈1 年前
从Docker到宝塔:Magento2 2.3.5 安装全流程踩坑与成功实践
运维·adobe·docker·容器·magento2
T暴风雪2 年前
Magento2根据图片文件包导入产品图片
php·magento2