How to Install Sample Data in Magento 2?

Avatar image of Maarten Maarten
November 7, 2022
Magento community people often ask about the Magento sample data. Sample data can be used to test performance and scalability on your store. In this blog, we will see how you can install sample data on your Magento 2 store.

Magento community people often ask about the Magento sample data. Sample data can be used to test performance and scalability on your store. In this blog, we will see how you can install sample data on your Magento 2 store.

There are three methods to install sample data on Magento 2:

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

Method 1: Install using Magento CLI

  1. Connect your Magento store by launching the SSH terminal
  2. Go to the root directory (public_html) of your Magento 2 store.
  3. To install Magento 2 sample data, run the following command
php bin/magento sampledata:deploy
  1. Now to authenticate from repo.magento.com, you will need your username and password to start
aTROjZz9GsPPPokRAvRdzJLdZx NU04TPs4zQFWOfjEf2w mdNRvQIQGSCSypmvcbLCIJgpsh1qculQtJ7QiSnigH1ZTcmOLPWAyTQ5Q8Hl4kl16Y4dQcR4N2mWAOh54ds9E2ZOQE1IvkpQvK2oNdexM59NZVJ 8jpHwqeFi0LDDM Mt3OGjItFFhP z

To find your username and password, log in to your Magento Marketplace Account and Navigate to My Profile. 

axHydCVXlUas1O9y2

Under the Marketplace tab,  Go to the My Products section and Click Access Keys

m2tzBSmhBztqxg7p3kMed4Xt0SkIg52RuBxUl zmjtMgQQhOClDV2ErG1tz3SlGok6wO9u8Zn3y GCz6vDt2f7IWuOlcIUR gRtQ FCFVNCljJogipv8uDXMRc6UkvCfSIoU0evTByuWBJ7RdeuvmlsrvqxxL bJjVs4V11Qte23WH3UXKH dbtJqior

If you don’t have access keys, you will have to create new keys. To create, click Create A New Access Key.

YcmrPMCAKpRLArLxRN9VWROvovnDSjGlSNDLRN0n0ZTf5m9oeGhQLtC1XHwOdM8y4B93g7qI1FEospGf4puCcPhwNbvinmPRzmh23IwfZHeX6Pu1cav20kYoaXpVTxnX3rATHY1QCh LQLQw1Kh54gJwMXuL6TztpiM9IMqeWCJVbNDtE fmjIbbtH

You will get two kinds of keys: a public and a private key.

  • Public Key: It will be used as your username.
  • Private: It will be used as your password.
  1. Now return to the SSH terminal and enter your username, password and enter ‘Y’:
kiKoLRiEvu69lyxewrxUvFohc64 31bAuegkbi1SmjIMYPy65JZyomnePx22W9 S5vWv0we3AFk9hXJC70wZwYrdvDc63d1kaRgERmXzBrwWLJoNepNoohIM9U825PgaUFR5JY4lNnaPx3of0jwpMIS59nwrSh79IRGUWvbA2GnPtmiMBZKBFkJd KSA
  1. Now click enter to start the installation process of Magento 2 sample data.

If you get a memory error message, use the following command.

php -d memory_limit=2G bin/magento sampledata:dep
  1. After Magento 2 sample data is successfully installed, run the following commands one after one.
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f
  1. Vist your store’s front page.
MljIOfn9HV26s5G4oEqPytXvdQmhrsgCcILxKpCsk7nDWxDm8wnHkr3NqZ7ySOuv3rDPbKoBBmonV MKZPDqg3XfdzrNjQVQp7 VF3BdtMlHPhejgaU mX9t98cRldUUwv bkWYQYZArOSZL77uTijTj1AIAkWAS4ZXNpddjX2ify7Uk5o

Now, you will be able to see the sample data.

Now, let’s move ahead and check other methods to install Magento 2 sample data.

Method 2: Install by cloning repositories


Cloning with SSH Protocol

  1. Visit Magento sample data repository
  2. Click SSH from the list.
  3. Click Copy to clipboard
  4. Visit your web server’s docroot directory. 

     For Ubuntu, the directory is /var/www & 

     For CentOS, the directory is /var/www/html.

  1. Now enter git clone and paste the value copied in the previous step. 

     For example,

     git clone git@github.com:

magento/magento2-sample-data.git
  1. Wait until the repository is cloned on your server.
  2. Check the branch of the sample data repository which corresponds with the branch you used from the main Magento 2 repository.

     For example,

     If the branch of Sample data is 2.3.2, the Magento repository branch should be 2.3.2


Check the correct branch using the command – 

 $git checkout 2.3.2
  1. Change to <magento_root>
  2. Now you will have to create symbolic links between cloned files, use this command to create symbolic links –

   php -f <sample-data_clone_dir>/dev/tools/build-sample-data.php — –ce-source=”<path_to_your_magento_instance>”

Cloning with HTTPs Protocol

  1. Visit Magento sample data repository
  2. On the right side, click HTTP under the clone URL field 
  3. Click Copy to clipboard
  4. Change your web server’s docroot directory. 

     For Ubuntu, the directory is /var/www & 

     For CentOS, the directory is /var/www/html.

  1. Now enter git clone and paste the value copied in the previous step. 

     For example,

     git clone git@github.com:magento/magento2-sample-data.git

  1. Wait until the repository is cloned on your server.
  2. Check the branch of the sample data repository which corresponds with the branch you used from the main Magento 2 repository.

     For example,

     If the branch of Sample data is 2.3.2, the Magento repository branch should be 2.3.2


Check the correct branch using the command – 

  git checkout 2.3.2

  1. Change to <magento_root>
  2. Now you will have to create symbolic links between cloned files; use this command to create symbolic links –
   php -f <sample-data_clone_dir>/dev/tools/build-sample-data.php -- --ce-source="<path_to_your_magento_instance>"

Set File System Ownership and permissions:

  1. Navigate to your sample data clone directory.
  2. Set ownership using command–
chown -R :<your web server group name> .
  1. Set system permission using command–
 find . -type d -exec chmod g+ws {} \;
  1. Clear cache & update database

Method 3: Install by composer.json file


Add this 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.*”
  • For Magento 2.2, Replace “100.2.*” with “100.2.*” and so on.
  • Now run command– composer update
  • If it asks for a username and password, use the method shown in method 1 to get your username and password.

Your sample data will be installed after following the procedure.

That’s all about the sample data installation process. You can test features and functionalities with the data you want. 

Industry news straight to your inbox

Get the latest commerce news, trends, and strategies to grow your business
Subscribe to the newsletter
By submitting this form, you agree to receive promotional messages from Magstack. Unsubscribe any time by clicking the link in our emails.
Select location and language

Contact Our Sales Team

Learn more about our products, features, and pricing options.
By submitting this form, you agree to receive promotional messages from Shopify about its products and services. You can unsubscribe at any time by clicking on the link at the bottom of our emails.
Product
Pricing
Use cases
Recourses
Documentation
Log in
Start a free trial