🔥 Just Launched! Werra Premium Template for HyväSee it in Action

Learn 3 Different Ways to Install Sample Data in Magento 2

By Sanjay JethvaUpdated on May 22, 2025 3 min read

Magento 2 sample data is a test sample data based on the Luma theme with sample products, categories, customers’ data, etc.

The objective of the sample data after you have installed Magento 2 is to use it as a test environment where you can tweak the orders, and prices, add products, manage inventory, test the pricing rules, and so on. Let’s learn the different ways to install sample data in Magento 2.

There are three methods to install Magento 2 sample data:

  1. Install using Magento CLI
  2. Install by cloning repositories
  3. Install by composer.json file

You can also bookmark this Magento 2 sample data installation guide for future reference to install sample data in Magento 2.

Methods to install Magento 2 Sample Data:

Method 1: Install using Magento CLI

1. Export Magento CLI’s path with the below command

export PATH=$PATH:$(pwd)/bin

2. Change your current directory to Magento’s Webroot

magento sampledata:deploy

3. If you get the URL authentication error to repo.magento.com, execute the “composer update” command. You’d require the username and password from the Magento Connect Account section.

4. Recompile the code and clear the cache

magento setup:upgrade

Method 2: Install by cloning repositories

1. Cloning with SSH Protocol

  • Visit the Magento sample data repository
  • Next to the name of the branch, click SSH from the list.
  • Click Copy to clipboard
  • Go to your web server’s docroot directory. For Ubuntu, the directory is /var/www and for CentOS it’s /var/www/html.
  • Enter git clone and paste the value from the previous step. For example,
    git clone [email protected]:magento/magento2-sample-data.git
  • Wait for the repository to clone on your server.
  • Check out the branch of the sample data repository that corresponds with the branch you used from the main Magento 2 repository.
    For eg: if the branch of the Magento repository is 2.3.3 develop, the sample data branch should be 2.3.3
    You can check the correct branch using the below command from the sample data repository’s root directory – $git checkout 2.3.3
  • Change to <magento_root>
  • Create symbolic links between the files you just cloned with the below command:
php -f <sample-data_clone_dir>/dev/tools/build-sample-data.php -- --ce-source="<path_to_your_magento_instance>"

2. Cloning with HTTPS Protocol

  • Visit Magento sample data repository
  • Click HTTP under the clone URL field on the right side
  • Click Copy to clipboard
  • Change to your web server’s docroot directory. For Ubuntu, it’s /var/www and for CentOS it’s /var/www/html.
  • Enter git clone and paste the value from the previous step. For example,
    git clone [email protected]:magento/magento2-sample-data.git
  • Wait for the repository to clone on your server.
  • Make sure to check out the branch of the sample data repository that corresponds with the branch you used from the main Magento 2 repository.
    For eg: if the branch of Magento repository is 2.3.3 develop, the sample data branch should be 2.3.3
    You can check the correct branch using the below command from the sample data repository’s root directory – git checkout 2.3.3
  • Change to <magento_root>
  • Create symbolic links between the files you just cloned with the below command:
php -f <sample-data_clone_dir>/dev/tools/build-sample-data.php -- --ce-source="<path_to_your_magento_instance>"

Also Read: How to Create a GitHub Repository?

Set File System Ownership and permissions:

1. Go to your sample data clone directory

2. Set ownership

chown -R :<your web server group name> .

3. Set system permission

find . -type d -exec chmod g+ws {} ;

4. Clear cache

5. Update database

Method 3: Install by composer.json file

You can follow these steps to install sample data in Magento 2 by composer.json:

1. Add following code to your root composer.json file.

  • For magento 2.4.*
{
    "require": {
        "magento/module-bundle-sample-data": "100.4.*",
        "magento/module-catalog-rule-sample-data": "100.4.*",
        "magento/module-catalog-sample-data": "100.4.*",
        "magento/module-cms-sample-data": "100.4.*",
        "magento/module-configurable-sample-data": "100.4.*",
        "magento/module-customer-sample-data": "100.4.*",
        "magento/module-downloadable-sample-data": "100.4.*",
        "magento/module-grouped-product-sample-data": "100.4.*",
        "magento/module-msrp-sample-data": "100.4.*",
        "magento/module-offline-shipping-sample-data": "100.4.*",
        "magento/module-product-links-sample-data": "100.4.*",
        "magento/module-review-sample-data": "100.4.*",
        "magento/module-sales-rule-sample-data": "100.4.*",
        "magento/module-sales-sample-data": "100.4.*",
        "magento/module-swatches-sample-data": "100.4.*",
        "magento/module-tax-sample-data": "100.4.*",
        "magento/module-theme-sample-data": "100.4.*",
        "magento/module-widget-sample-data": "100.4.*",
        "magento/module-wishlist-sample-data": "100.4.*",
        "magento/sample-data-media": "100.4.*"
    }
}
  • For magento 2.3
    Replace “100.4.*” with “100.3.*” in the above code.
  • For magento 2.2
    Replace “100.2.*” with “100.2.*” and so on.
  • Now pass the below command
composer update

If it asks for a username and password, then follow the following guide:
Get your authentication keys

Where the public key is username

The private key is the password

That was all about Magento 2 sample data installation. Once you have installed sample data in Magento 2 store, you can test the functionalities with the test data as much as you want.

Do not forget to share the tutorial via social media.

Thank you.

Sanjay Jethva Full Image
Article bySanjay Jethva

Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe. His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.