Tips & Tutorials

How to install sample data to Magento 2

Magento – one of the most popular eCommerce solution in the market. Built as an open-source platform, Magento allows merchants to customize the store flexibly to meet their business requirements.

 

If you are new to eCommerce and Magento, there are a lot of things to learn about. In this article, we will give you a walkthrough on how to install sample data to Magento 2.

 

What is Magento sample data?

Sample data provided by Magento includes a shopfront using Luma theme, featured with products (more than 250 products), categories, promotion price rules, and so on. This data saves merchant a lot of time when creating storefront for testing since it operates exactly like a Magento storefront.

 

How to install sample data to Magento 2?

Other than installing the sample data along with the Magento installation, you can still add the sample data to your site after the software is set up. There are two main ways to achieve this:

  1. Using Composer
  2. Cloning storage

 

 

  • Installing sample data with Composer

 

This method is applicable for both Magento Open Source and Magento Commerce. You can use composer to install the sample data after Magento, note that you must use the same authentication keys (access keys) that you use for Magento installation.

In order to install the data, run the following command:

 

php <your Magento install dir>/bin/magento sampledata:deploy

 

Then,  log in to your Magento server, or switch to the Magento file system owner and run the following command to update the database and schema:

 

php <your Magento install dir>/bin/magento setup:upgrade

 

Finally, fill in the authentication keys to finish. You can obtain this key from your Magento account.

 

If you run into this error while authenticating

 

[Composer\Downloader\TransportException]
The ‘https://repo.magento.com/packages.json’ URL required authentication.
You must be using the interactive console to authenticate

 

Change to your Magento Installation Directory then run the composer update

 

  1. Installing sample data by cloning repositories

There are 2 ways to clone the repositories

  • Cloning with SSH Protocol
  • Cloning with HTTPS Protocol

 

Cloning with SSH Protocol

 

  1. Go to Magento sample data repository
  2. Beside the name of the branch, click on SSH
  3. On the right, click on Copy to clipboard icon

Credit: devdocs.magento.com

 

  1. Go to your web server’s docroot directory. For Ubuntu, the directory is /var/www and for CentOS it’s /var/www/html.
  2. Enter git clone and paste the value you have copied in step 3

For example,

 

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

  1. Check if the branch of the sample data repository matches with the branch from the main Magento repository

For instance, if the branch of Magento repository is 2.2.4 develop, the sample data branch should be 2.2.4

To check whether it is correct, run this command from the sample data repository root directory

git checkout 2.2.4

  1. Change to <your Magento installation directory>.
  2. Run the following command so as to create symbolic links between the files you just cloned:
  1. Then you have to set the file system permissions and ownership.

9.1 Go to your sample data clone directory

9.2 Set the ownership as the following form:

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

9.3 Set the system permissions:

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

9.4 Clear caches

cd <your Magento Open Source install dir>/var
rm -rf cache/* page_cache/* generation/*

  1. Update the database by entering this command

php <your Magento install dir>/bin/magento setup:upgrade

Cloning with HTTPS Protocol

 

  1. Go to Magento sample data repository
  2. On the right, under the clone URL field, choose HTTPS
  3. On the right, click on Copy to clipboard icon

Credit: devdocs.magento.com

 

  1. Go to your web server’s docroot directory. For Ubuntu, it is /var/www and for CentOS it’s /var/www/html.
  2. Type git clone then paste the value from step 3

For example

git clone https://github.com/magento/magento-sample-data.git

  1. Check to make sure if the sample data repository branch is well-matched with the main Magento repository branch

For example, if the branch of Magento repository is 2.2.4 develop, the sample data branch should be 2.2.4

To check whether it is correct, run this command from the sample data repository root directory

git checkout 2.2.4

  1. Change to <your Magento installation directory>.
  2. Run the following command to create symbolic links between the files you just cloned so sample data can work properly:

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

  1. Then you have to set the file system permissions and ownership.

9.1 Go to your sample data clone directory

9.2 Set the ownership as the following form:

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

9.3 Set the system permissions:

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

9.4 Clear caches

cd <your Magento Open Source install dir>/var
rm -rf cache/* page_cache/* generation/*

 

 

  1. Finally, don’t forget to update the database by entering this command

php <your Magento install dir>/bin/magento setup:upgrade

After that, you can go to the front – end to see if the sample works

Author: Liam

Related Posts


Leave a comment

Your email address will not be published. Required fields are marked *

nine + two =

At Magenest, we help our customers thrive by offering advanced solutions and working with excellent business partners.

We’re proud to be one of the top Magento 2 developers with capability in building integration solutions with third party business systems and applications.

Categories

Please follow & like us

Facebook
Facebook
Google+
Google+
https://store.magenest.com/blog/install-sample-data-magento-2">
YouTube
YouTube