{"id":707,"date":"2019-12-06T08:06:40","date_gmt":"2019-12-06T08:06:40","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2019\/12\/06\/install-sample-data-in-magento-2\/"},"modified":"2025-05-22T15:16:52","modified_gmt":"2025-05-22T09:46:52","slug":"install-sample-data-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/install-sample-data-in-magento-2\/","title":{"rendered":"Learn 3 Different Ways to Install Sample Data in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/github.com\/magento\/magento2-sample-data\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 sample data<\/a>&nbsp;is a test sample data based on the Luma theme with sample products, categories, customers\u2019 data, etc.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The objective of the sample data after you have&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/install-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">installed Magento 2<\/a>&nbsp;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\u2019s learn the different ways to&nbsp;install sample data in Magento 2.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">There are three methods to install Magento 2 sample data:<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Install using Magento CLI<\/li>\n\n\n\n<li>Install by cloning repositories<\/li>\n\n\n\n<li>Install by composer.json file<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">You can also bookmark this Magento 2 sample data installation guide for future reference to install sample data in Magento 2.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Methods to install Magento 2 Sample Data:<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Method 1: Install using Magento CLI<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">1. Export Magento CLI\u2019s path with the below command<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>export PATH=$PATH:$(pwd)\/bin<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2. Change your current directory to Magento\u2019s Webroot<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>magento sampledata:deploy<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">3. If you get the URL authentication error to repo.magento.com, execute the \u201c<code>composer update<\/code>\u201d command. You\u2019d require the username and password from the Magento Connect Account section.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">4. Recompile the code and&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/clear-magento-2-cache\/\" target=\"_blank\" rel=\"noreferrer noopener\">clear the cache<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>magento setup:upgrade<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"Cloning\">Method 2: Install by cloning repositories<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">1. Cloning with SSH Protocol<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Visit the&nbsp;<a href=\"https:\/\/github.com\/magento\/magento2-sample-data\" target=\"_blank\" rel=\"noreferrer noopener\">Magento sample data repository<\/a><\/li>\n\n\n\n<li>Next to the name of the branch, click&nbsp;<strong>SSH<\/strong>&nbsp;from the list.<\/li>\n\n\n\n<li>Click&nbsp;<strong>Copy to clipboard<\/strong><\/li>\n\n\n\n<li>Go to your web server\u2019s docroot directory. For Ubuntu, the directory is&nbsp;<em>\/var\/www<\/em><em>&nbsp;and for CentOS it\u2019s&nbsp;<\/em><em>\/var\/www\/html<\/em><em>.<\/em><\/li>\n\n\n\n<li>Enter&nbsp;<code>git clone<\/code>&nbsp;and paste the value from the previous step. For example,<br>git clone&nbsp;<a href=\"mailto:git@github.com\" target=\"_blank\" rel=\"noreferrer noopener\">git@github.com<\/a>:magento\/magento2-sample-data.git<\/li>\n\n\n\n<li>Wait for the repository to clone on your server.<\/li>\n\n\n\n<li>Check out the branch of the sample data repository that corresponds with the branch you used from the main Magento 2 repository.<br>For eg: if the branch of the Magento repository is 2.3.3 develop, the sample data branch should be 2.3.3<br>You can check the correct branch using the below command from the sample data repository\u2019s root directory \u2013 $git checkout 2.3.3<\/li>\n\n\n\n<li>Change to&nbsp;<strong>&lt;magento_root&gt;<\/strong><\/li>\n\n\n\n<li>Create symbolic links between the files you just cloned with the below command:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>php -f &lt;sample-data_clone_dir&gt;\/dev\/tools\/build-sample-data.php -- --ce-source=\"&lt;path_to_your_magento_instance&gt;\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2. Cloning with HTTPS Protocol<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Visit&nbsp;<a href=\"https:\/\/github.com\/magento\/magento2-sample-data\" target=\"_blank\" rel=\"noreferrer noopener\">Magento sample data repository<\/a><\/li>\n\n\n\n<li>Click HTTP under the clone URL field on the right side<\/li>\n\n\n\n<li>Click&nbsp;<strong>Copy to clipboard<\/strong><\/li>\n\n\n\n<li>Change to your web server\u2019s docroot directory. For Ubuntu, it\u2019s&nbsp;<code>\/var\/www<\/code>&nbsp;and for CentOS it\u2019s&nbsp;<code>\/var\/www\/html<\/code>.<\/li>\n\n\n\n<li>Enter&nbsp;<code>git clone<\/code>&nbsp;and paste the value from the previous step. For example,<br>git clone&nbsp;<a href=\"mailto:git@github.com\" target=\"_blank\" rel=\"noreferrer noopener\">git@github.com<\/a>:magento\/magento2-sample-data.git<\/li>\n\n\n\n<li>Wait for the repository to clone on your server.<\/li>\n\n\n\n<li>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.<br>For eg:&nbsp;if the branch of Magento repository is 2.3.3 develop, the sample data branch should be 2.3.3<br>You can check the correct branch using the below command from the sample data repository\u2019s root directory \u2013 git checkout 2.3.3<\/li>\n\n\n\n<li>Change to&nbsp;<strong>&lt;magento_root&gt;<\/strong><\/li>\n\n\n\n<li>Create symbolic links between the files you just cloned with the below command:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>php -f &lt;sample-data_clone_dir&gt;\/dev\/tools\/build-sample-data.php -- --ce-source=\"&lt;path_to_your_magento_instance&gt;\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Also Read:<\/strong>&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/create-a-github-repository\/\">How to Create a GitHub Repository?<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Set File System Ownership and permissions:<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">1. Go to your sample data clone directory<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2. Set ownership<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>chown -R :&lt;your web server group name&gt; .<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">3. Set system permission<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>find . -type d -exec chmod g+ws {} ;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">4. Clear cache<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">5. <a href=\"https:\/\/meetanshi.com\/blog\/create-upgrade-database-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">Update database<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-by-composer-json-file\">Method 3: Install by composer.json file<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You can follow these steps to install sample data in Magento 2 by composer.json:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1. Add following code to your root&nbsp;<strong>composer.json<\/strong>&nbsp;file.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>For magento 2.4.*<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\n    \"require\": {\n        \"magento\/module-bundle-sample-data\": \"100.4.*\",\n        \"magento\/module-catalog-rule-sample-data\": \"100.4.*\",\n        \"magento\/module-catalog-sample-data\": \"100.4.*\",\n        \"magento\/module-cms-sample-data\": \"100.4.*\",\n        \"magento\/module-configurable-sample-data\": \"100.4.*\",\n        \"magento\/module-customer-sample-data\": \"100.4.*\",\n        \"magento\/module-downloadable-sample-data\": \"100.4.*\",\n        \"magento\/module-grouped-product-sample-data\": \"100.4.*\",\n        \"magento\/module-msrp-sample-data\": \"100.4.*\",\n        \"magento\/module-offline-shipping-sample-data\": \"100.4.*\",\n        \"magento\/module-product-links-sample-data\": \"100.4.*\",\n        \"magento\/module-review-sample-data\": \"100.4.*\",\n        \"magento\/module-sales-rule-sample-data\": \"100.4.*\",\n        \"magento\/module-sales-sample-data\": \"100.4.*\",\n        \"magento\/module-swatches-sample-data\": \"100.4.*\",\n        \"magento\/module-tax-sample-data\": \"100.4.*\",\n        \"magento\/module-theme-sample-data\": \"100.4.*\",\n        \"magento\/module-widget-sample-data\": \"100.4.*\",\n        \"magento\/module-wishlist-sample-data\": \"100.4.*\",\n        \"magento\/sample-data-media\": \"100.4.*\"\n    }\n}<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>For magento 2.3<br><\/strong>Replace \u201c100.4.*\u201d with \u201c100.3.*\u201d in the above code.<\/li>\n\n\n\n<li><strong>For magento 2.2<br><\/strong>Replace \u201c100.2.*\u201d with \u201c100.2.*\u201d and so on.<\/li>\n\n\n\n<li>Now pass the below command<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>composer update<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If it asks for a username and password, then follow the following guide:<br><a href=\"https:\/\/experienceleague.adobe.com\/en\/docs\/commerce-operations\/installation-guide\/overview\" target=\"_blank\" rel=\"noreferrer noopener\">Get your authentication keys<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Where the public key is username<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The private key is the password<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do not forget to share the tutorial via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Magento 2 sample data&nbsp;is a test sample data based on the Luma theme with sample products, categories, customers\u2019 data, etc. The objective of the sample&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-707","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/707","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=707"}],"version-history":[{"count":4,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/707\/revisions"}],"predecessor-version":[{"id":15157,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/707\/revisions\/15157"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=707"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=707"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}