Magento is a powerful ecommerce platform.
But learning how to use Magento correctly can be challenging. To simplify this task, Adobe provides a sample data module for Magento 2 that transforms a Magento installation into a demo Magento 2 store.
This guide explains the basics of the Magento 2 sample data module and teaches you how to install it correctly.
Here’s what we cover in this tutorial:
- Magento 2 sample data 101
- How to install sample data in Magento
- Common Magento sample data installation errors & steps to fix them
- Final thoughts: how to install Magento 2 sample data
Magento 2 sample data 101
Magento sample data is a module that transforms a Magento instance into a demo store. That store comes with sample data such as customers, orders, categories, CMS pages, and pricing rules. Besides that, it installs the free Luma Magento 2 theme and adds over 250 Magento 2 products.
The sample data module is a collection of 19 packages for Magento Open Source and 24 packages for Adobe Commerce.
You can view the packages for Magento Open Source inside the sample data repository.
Adobe Commerce users get access to those packages plus the following five modules for Commerce-specific features:
You can install Magento sample data in three ways:
- Using the Magento Command Line Interface (CLI).
- Using Composer.
- By cloning the Magento GitHub repository.
The Magento CLI and Composer installation methods can be used when you’ve installed Magento 2 using an archive file from Adobe or a Composer metapackage.
But those methods won’t work if you’ve installed Magento by cloning its GitHub archive.
That’s because the composer.json file in the GitHub archive doesn’t contain the “https://repo.magento.com” URL. If you’ve installed Magento 2 by cloning a GitHub archive, you’ll need to install sample data by cloning its GitHub repository.
Adobe provides you with the sampledata:remove CLI command to uninstall sample data modules. However, that command doesn’t delete Magento database entries.
The only way to remove the Magento 2 sample data module entirely is by dropping the database and reinstalling Magento 2 with a new database.
Get fully managed Magento hosting
Accelerate your store's potential, without the tedious maintenance
How to install sample data in Magento
- Log in to your server and enable developer mode.
- Execute the sample data installation command.
- Update the database and schema and clear the Magento cache.
- Verify the sample data installation.
Follow these steps to install sample data in Magento 2.
Note: Do not install sample data on a production server, as you cannot uninstall the module without deleting the Magento database and reinstalling Magento.
Step 1: log in to your server and enable developer mode
Log in to your server over SSH, switch to the Magento file system user, and navigate to the Magento root directory. Then, enable developer mode using:
$ php bin/magento deploy:mode:set developer
Then, clear previously generated classes and proxies using the following command:
$ rm -rf generated/code/* generated/metadata/*
Step 2: execute the sample data installation command
Install the Magento 2 sample data module using the following command:
$ php bin/magento sampledata:deploy
You should see the following terminal output:
Note: You may need to enter your Magento authentication keys at this point. Follow Adobe’s guide to retrieve the public and private keys used to install your Magento application and use the same keys for the sample data module installation.
Step 3: update the database and schema and clear the Magento cache
Once the Magento 2 sample data installation command executes successfully, update the Magento database and schema using the below command:
$ php bin/magento setup:upgrade
After that, clear all Magento cache types using:
$ php bin/magento cache:clean $ php bin/magento cache:flush
Step 4: verify the sample data installation
Finally, access your storefront in a browser. Here’s how it will look:
Common Magento sample data installation errors & steps to fix them
Here are three common errors you might encounter during sample data installation and the steps to fix them.
1. File system permissions error
File system permission errors are one of the most common errors you might face when you install Magento 2 sample data.
For instance, you might encounter exceptions such as:
- Can’t create directory /var/www/html/magento2/generated/code/Magento/CatalogRule/Model/.
- Class Magento\CatalogRule\Model\RuleFactory does not exist.
If you face such errors, you’ll need to reset file system permissions based on your deployment.
Follow Adobe’s guide demonstrating the steps to set file system access permissions and rerun the sampledata:deploy command.
2. Magento mode error
Installing Magento sample data in production mode can cause a PHP Fatal error or the following error when you run the setup:upgrade command:
To prevent such errors, switch to developer mode and clear generated data before you install Magento 2 sample data.
3. PHP max_execution_time error
The Magento sample data module installation process is a resource-intensive task. Depending on your server configuration, it can take anywhere from a few seconds to several minutes.
Sometimes, it can fail silently when the max_execution_time in your PHP configuration file is inadequate for the sample data script.
To fix this issue, switch to a user with root privileges and edit the php.ini file using your preferred text editor.
For instance, if your PHP version is 7.4, you can run this code:
$ nano /etc/php/7.4/fpm/php.ini
Find the max_execution_time setting and update its value to 600 or more. Save the file and restart PHP to update its configuration.
After that, run the sampledata:deploy command and reset the max_execution_time value to the original value once the Magento 2 sample data installation is completed.
Final thoughts: how to install Magento 2 sample data
We’ve explained the basics of the Magento 2 sample data module, demonstrated a step-by-step installation process, and shared tips to fix common errors.
It’s important to remember that you can’t uninstall sample data without reinstalling Magento. So make sure you only install it in a staging environment.
Don’t have a test server?
Sign up for managed Magento hosting with Nexcess and get access to dedicated staging sites at no extra cost.
Browse our plans to learn more.