3 Ways to Install Magento Sample Data

3 Ways to Install Magento Sample Data

Magento sample data offers online store owners a storefront powered by the Luma theme. It helps you adjust orders and prices, add new products, and manage your inventory, among other functionalities. This tutorial will guide you through three distinct methods for installing Magento sample data on your e-commerce store.


These methods include using Magento CLI, cloning repositories, and installing via the composer.json file. It is essential for evaluating the performance and scalability of your online store.


Key Takeaways

  • Discover three methods for installing Magento sample data: CLI, Composer.json, and GitHub repository cloning.

  • Explore the prerequisites for installing Magento sample data, including server requirements and system owner access.

  • Learn how to use the Magento CLI to install sample data efficiently.

  • Explore the benefits of using Composer to streamline the installation process and ensure compatibility.

  • Discover cloning the Magento GitHub repository for greater flexibility and control during installation.

  • Verify the correct sample data installation by testing your Magento store's customer registration, price modifications, and CMS functionality.

Overview of Magento Sample Data

Overview highlighting Magento Sample Data

Magento sample data is a valuable resource for those operating e-commerce storefronts. It seamlessly integrates with the Luma theme, offering an accessible and visually appealing interface. Through the Magento Admin Panel, store owners gain the capability to oversee pricing, inventory, and promotional pricing rules efficiently. It empowers businesses to streamline their operations and enhance their online shopping experience for customers.


A certain number of products in stock is essential to assess store performance. Magento sample data facilitates this by enabling you to add around 250 products across various categories. It also installs the Luma Magento 2 theme, incorporating over 250 Magento products.


The sample data module comprises 19 packages designed for Magento Open Source and 24 packages tailored for Adobe Commerce. These packages for Magento Open Source can be found within the sample data repository.


For Adobe Commerce users, these packages are available along with an additional five modules that offer Commerce-specific features:

  • magento/module-target-rule-sample-data.
  • magento/module-customer-balance-sample-data.
  • magento/module-gift-registry-sample-data.
  • magento/module-gift-card-sample-data.
  • magento/module-multiple-wishlist-sample-data.

Prerequisites to Install Magento Sample Data

Before installing Magento sample data, it's essential to confirm that your server configuration aligns with the specified requirements for Magento 2. These requirements include:

  • Apache version 2.2 or 2.4.
  • PHP version 5.6.5 or any higher version.
  • MySQL version 5.6 or higher.

In addition to the server requirements, you must ensure that you have system owner access to your server to execute SSH commands. Contacting your Magento hosting provider for confirmation is recommended to verify your access level.

Methods for Installing Magento Sample Data

Method 1: Using the Magento Command Line Interface (CLI)

One of the easiest ways to install Magento sample data is by using the Magento Command Line Interface (CLI). Here are the steps to install Magento sample data using the CLI:

  1. Open your command line interface and export the path to the Magento CLI using the following command:
export PATH=$PATH:$(pwd)/bin
  1. Switch to the Magento file system user and navigate to the Magento root directory (public_html).

  2. Clear previously generated classes and proxies. You can achieve this using the following command:

$ rm -rf generated/code/* generated/metadata/*
  1. Install the Magento sample data module by running:
$ php bin/magento sampledata:deploy
  1. Authenticate from repo.magento.com by entering your username and password.

  2. Log in to your Magento marketplace account and click My Profile on the top right corner of the page.

  3. Click Access Keys in the My Products section under the Marketplace tab.

Step-by-step guide on using Access Key for Magento Sample Data installation.

  1. If you already have an access key, use that.
  2. Click Create a new access key if you don’t have one. You will get two types of keys: public and private.

Procedure to create a new access key for Magento Sample Data setup.

  • Public Key: Use this key as your username.
  • Private Key: Use this key as your password.
  1. Return to the SSH terminal, enter your username and password, and Type ‘Y.’

  2. Click Enter to start the Magento sample data installation process.

Note: Run the following command if you get a memory error message.

php -d memory_limit=2G bin/magento sampledata:deploy
  1. Next, update the Magento database and schema with this command:
$ php bin/magento setup:upgrade
  1. Following the database update, Clear all Magento cache typesusing these commands:
$ php bin/magento cache:clean
$ php bin/magento cache:flush

It ensures that your Magento installation is up to date and the cache is cleared for optimal performance.

  1. Verify the sample data installation by running the following commands:
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f
  1. Finally, access your Magento storefront through a web browser. It confirms that the sample data is correctly installed and functioning as expected.

Summary of CLI commands for installing Magento sample data:

Command Description
php bin/magento sampledata:deploy Downloads and deploys the sample data modules.
php bin/magento setup:upgrade Updates the database schema and applies any necessary changes.
php bin/magento cache:clean Clears the Magento cache to ensure the sample data is properly loaded.

Method 2: Using Composer.json File

To install sample data in Magento 2 using the composer.json file, follow these steps:

  1. Add the following code to your root composer.json file for Magento version 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." in the above code. For Magento 2.2 and other versions, adjust the version numbers accordingly.

  1. Run the following command: composer update

  2. If prompted for a username and password, use your authentication keys.

Note - The public key is the username, and the private key is the password.

  1. Verify the sample data installation by running the following commands:
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f
  1. Access your Magento storefront and confirm the correct installation and functioning of the sample data.
Benefits of Using Composer Considerations
Efficient and streamlined installation process Requires basic knowledge of Composer commands
Ensures compatibility with other dependencies Some modules may have specific installation requirements
Easier management of sample data version control May require authentication keys for accessing the Magento repository

Method 3: Cloning the Magento GitHub Repository

For more advanced users, an alternative method to install Magento sample data is by cloning the Magento GitHub repository. It provides greater flexibility and control over the installation process.


1. SSH Protocol:

  1. Visit the Magento sample data repository.

  2. Select SSH from the list next to the Branch name.

  3. Click on Copy to clipboard.

  4. Navigate to your web server's docroot directory. For Ubuntu, this directory is typically located at /var/www.

  5. Enter the command: git clone and paste the value copied in the previous step. An example command would be: git clone git@github.com:magento/magento2-sample-data.git

  6. Let the repository clone onto your server.

  7. Ensure that you check out the branch of the sample data repository corresponding to the branch used in the main Magento 2 repository.

  8. Now, change to the <magento_root> directory.

  9. Here, create symbolic links between the files you just cloned by executing the following command:

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

2. HTTPS Protocol:

  1. To clone with the HTTPS protocol, visit the Magento sample data repository.

  2. Locate the HTTP option under the clone URL field.

  3. Click on Copy to clipboard to capture the URL.

  4. Next, navigate to your web server's docroot directory. On Ubuntu, this directory is typically /var/www

  5. Execute the git clone command and paste the URL you copied in the previous step. For instance: git clone git@github.com:magento/magento2-sample-data.git

  6. Wait for the repository to clone onto your server.

  7. Ensure that you check out the branch of the sample data repository that matches the branch you used from the main Magento 2 repository. For example, if the branch of your Magento repository is 2.3.3 develop, the sample data branch should also be the same.

  8. Verify and switch to the correct branch using the following command from the root directory of the sample data repository: git checkout 2.3.3

  9. Finally, return to your Magento root directory and establish symbolic links between the files you've just cloned. You can do this with the following command:

 php -f <sample-data_clone_dir>/dev/tools/build-sample-data.php -- --ce-source="<path_to_your_magento_instance>
  1. After that, set file system ownership and permissions. Go to your sample data clone directory. Set ownership using the command: chown -R :
<your web server group name>
  1. Next, set system permissions with the command:
 find . -type d -exec chmod g+ws {} \;
  1. Finally, clear the cache and update the database.

Verify the Sample Data Installation

After installing Magento sample data, you can verify its installation and perform various tests by following these steps:

1. Customer Registration

Check if the sample data includes pre-registered customers. Go to the frontend of your Magento store and navigate to the customer registration page. Try registering a new customer account using one of the sample data customer email addresses. It ensures that customer registration functionality is working correctly.

2. Modify Prices

Explore the backend of your Magento store and navigate to the product catalog. Check if the sample data includes products with different prices. Modify the prices of some products and check if the changes are reflected correctly on the frontend. It will allow you to change the price and ensure it functions as expected.

3. CMS Pages

Verify if the sample data includes pre-configured CMS (Content Management System) pages. Access the CMS pages section in the backend and view the existing pages. Check if the sample data pages are listed and accessible. It will help you test the CMS functionality and ensure the sample data pages are installed correctly.

FAQ

1. What is Magento sample data, and how does it benefit your Magento store?

Magento sample data provides a means to evaluate your store's performance and offers a ready-made foundation for customizing your online storefront with the Luma Magento theme. This resource is accessible and manageable through the Admin Panel, making it a valuable asset for enhancing your Magento store's capabilities.


2. How can I delete sample data in Magento?

To safely delete sample data in Magento, use the command: bin/magento sampledata:remove. It will efficiently remove the sample data from your Magento setup while keeping your installation intact.


3. How can I fix file system permission errors when installing Magento sample data?

File system errors may include issues like directory creation problems (e.g., /var/www/html/magento2/generated/code/Magento/CatalogRule/Model/) or the absence of Class Magento\CatalogRule\Model\RuleFactory. To resolve these errors, reset your file system permissions according to your deployment requirements. Adjust permissions, and rerun the sampledata:deploy command for a successful installation.


4. How to prevent PHP fatal errors for Magento sample data?

To prevent PHP fatal errors when installing Magento sample data, ensure your server meets Magento's system requirements and follow Magento's installation instructions meticulously.

Summary

Magento sample data is vital to manage products, prices, and inventory. It also helps streamline the setup process for your Magento-based ecommerce store. This tutorial covered three distinct methods for installing Magento sample data - using the Command Line Interface (CLI), Composer.json, and cloning the GitHub repository.


Ready to optimize your ecommerce with sample data? Explore Magento hosting to ensure seamless installation and high performance for your online store.

Maria Ajnawala
Maria Ajnawala
Technical Writer

Maria has over five years of expertise in content marketing, specialising in Magento insights and industry trends. She excels in creating engaging content that resonates within the Magento community.


Get the fastest Magento Hosting! Get Started