Magento-Sample-Data

Magento Sample Data: Install, Update, Remove Guide [Updated 2020]

Posted by

Magento is among the most popular CMSs for ecommerce businesses. The platform offers sample data to test the store performance and scalability, thus helping store owners create a great experience for their visitors. Also, developers in the Magento community often ask about the Magento sample data. 

In this blog, we guide you on how to install, remove and update Magento 2 sample data directly on your store.

What is Magento Sample Data?

what-is-sample-data

First, you need to understand what sample data is all about. The concept can be understood differently.

For store admins, sample data simply is a sample store which is completed with more than 250 configurable products, categories, promotional price rules, CMS pages, banners, and so on. Magento 2 sample data visually uses the Luma theme on the storefront.

For technicians, sample data is a set of regular Magento modules, which can be deployed and installed together with the Magento instance, or later in the scope of upgrade. That is the reason why installing sample data is optional. 

Why Need Magento Sample Data

Before opting for any ecommerce platform, there are three crucial factors that an online store must consider. These factors consist of performance, user experience, and scalability. 

The sample data is essential when you need a tool to conduct the store’s performance and scalability tests with ease. Specifically, Magento 2 sample data provides admin to add approximately 250 sample products and categorize them into different groups. 

The number of sample products in stock is enough for admin to test the store performance. Thus, instead of installing Magento extensions, which helps optimize the shopping experience, they can modify their store in advance.

You can also browse the Magento extensions that we have spent all our time and pride in developing HERE.

Magento 2 Sample Data Configuration

Install Magento 2 sample data

how-to-install-sample-data-in-magento

As we mentioned above, you can install Magento 2 sample data either before or after installing the Magento software. 

You can install optional sample data in any of the two following ways:

#1. Install sample data via Composer

  • Download a compressed archive from Magento.
  • Use composer create-project

Installing sample data in production mode fails. So always remember to switch to developer mode. 

To install sample data using the command line, enter the following command as the Magento file system owner in the <magento_root> folder:

bin/magento sampledata:deploy

If you’re installing sample data after installing Magento application, you must also run the following command to update the database and schema in the <magento_root> folder:

bin/magento setup:upgrade

#2. Install sample data by cloning repositories

This method is preferred only by contributing developers. If you’re not a contributing developer, choose Composer as the easiest way to install sample data.

Plus, installing sample data by cloning repositories requires:

  • You use Magento Open Source
  • You cloned the Magento 2 repository

You can follow any of the two ways below to clone the sample data repository:

Clone with SSH

SSH protocol can be used to clone the sample data GitHub repository:

  1. In a web browser, access the sample data repository.
  2. Next to the branch’s name, click SSH from the list.
  3. Click Copy to clipboard

For example:

Clone-the-Magento-GitHub-repository-using-SSH

4. Switch to your web server’s docroot directory.

Typically, for Ubuntu, it’s /var/www and for CentOS it’s /var/www/html.

5. Type git clone and paste the value you obtained from step 1.

6. Wait for your server to clone the repository.

7. Make sure you check out the branch of the sample data repository corresponding with the branch from the main Magento 2 repository.

For example:

If you used the 2.2.5-develop branch of the Magento 2 repository, the Sample Data branch should be 2.2.5-develop.

To check out the correct branch, run the following command from the sample data repository’s root directory (for example, you need the 2.2.5 branch):

git checkout 2.2.5

8. Switch to <magento_root>.

9. Enter this command below to create symbolic links between the files you just cloned so that sample data works properly:

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

10. Wait for the command to complete.

Clone with HTTPS

You can use the HTTPS protocol to clone the sample data GitHub repository:

  1. The first step is the same as SHH
  2. On the right side of the page, below the clone URL field, click HTTPS.
  3. Click Copy to clipboard, as mentioned above.
  4. Change to your web server’s docroot directory.
    Typically, for Ubuntu, it’s /var/www and for CentOS it’s /var/www/html.
  5. Type git clone and paste the value you obtained from step 1.
  6. Wait for your server to clone the repository.
  7. Make sure you check out the branch of the sample data repository corresponding with the branch from the main Magento 2 repository.
  8. Change to <magento_root>.
  9. Enter the following command to create symbolic links between the files you just cloned so sample data works properly:

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

  1. Wait for the command to complete.

Remove sample data modules

remove-sample-data-modules

There is currently no way to uninstall sample data. So we will show you how to remove sample data modules from the Magento installation composer.json. However, this option does not remove sample data from the database.

  1. Log in to the Magento server as a user with permission to write to the Magento file system.

If the Magento file system does not allow owners to log in, you can do the following:

sudo -u <Magento file system owner>  <command>

2. Add <magento_root>/bin to your system PATH, to run Magento commands from any directory.

Sample bash shell for CentOS:

export PATH=$PATH:/var/www/html/magento2/bin

3. Optionally, the commands can be run in the following ways:

  • <magento_root> is a subdirectory of your web server docroot.
  • cd <magento_root>/bin and run them as ./magento <command name>
  • <magento_root>/bin/magento <command name>

4. Enter the following command:

bin/magento sampledata:remove

Update sample data

This command allows you to update sample data before you update the Magento application.

To prepare sample data for updating, enter the following command:

bin/magento sampledata:reset

After that, update the Magento application via composer.

Conclusion

In this tutorial, we have covered every aspect of Magento sample data installation for ecommerce stores. 

If you’re still confused about the process, don’t hesitate to drop your comments below or check out other posts on Mageguides. We will get back to you!

Leave a Reply

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