How to Install Sample Data in Magento 2

How-to-Install-Sample-Data-in-Magento-2

Magento sample data provides a Luma theme-based storefront. It has 250 products, CMS pages, banners, categories, promotional price rules, etc.

Although installing the sample data is optional, it can be used as a test environment. Let’s dive straight into the topic and learn how to install sample data in Magento 2.

    1. Log in to your Magento server over SSH and navigate to the root directory of your Magento 2 store.
    2. Enable developer mode by using this command:
      php bin/magento deploy:mode:set developer
    3. Run the following command to install the sample data:
      php bin/magento sampledata:deploy

      You’ll see the following authentication error if the Access Keys aren’t stored:

      [ComposerDownloaderTransportException]
      The 'https://repo.magento.com/packages.json' URL required authentication.
      You must be using the interactive console to authenticate

      In that case, go to your Magento marketplace account and click on My Profile > Access Keys.

      Profile in Magento Marketplace
      Click Access Keys

      Copy and paste the Public Key as the Username in the SSH terminal. Similarly, use the Private Key as the Password and hit the Enter key.

      If there’s no access key available, use the Create a New Access Key button to generate a new key.

      Access Keys in Magento Marketplace
      Copy and paste the Private key and Public key into the terminal

      Enter the Y key after receiving the following prompt to start the installation process:

      Do you want to store credentials for repo.magento.com in /htdocs/sampledata/var/composer_home/auth.json ? [Yn]
    4. Execute the following commands to update the database, recompile the code, and deploy static view files:
      php bin/magento setup:upgrade
      php bin/magento setup:di:compile
      php bin/magento setup:static-content:deploy -f
    5. Open your front end and verify sample data.

      Magento store frontend
      Magento store frontend

Leave a comment