If you don’t know what is the Magento 2 sample data, then you’ve come to the right place. Below, we will explain why is it useful and how to leverage it on the platform. Using the Magento 2 sample data is the most convenient way to get a storefront with products, categories, and other data. You get a store which is based on the Luma theme and functions just like a default Magento website – a perfect opportunity to learn how to manage prices, pricing rules, inventory, etc. In other words, with the Magento 2 sample data, you can easily master the Magento 2 Admin.
And it is possible to install sample data even before installing the Magento 2 software. Of course, you can do it right after. Also note that the Magento 2 sample data can be either removed or freshed.
There are two ways of installing optional Magento 2 sample data: via Composer and by installing cloning repositories.
If you decide to use Composer, don’t forget to change the root composer.json file of Magento 2 to enable sample data modules. This approach requires understanding Composer and accessing the Magento 2 file system.
In case you are going to clone the repository of Magento 2, note that it is also necessary to clone the sample data repository as well as create symbolic links. This method is intended for contributing developers only.
Below, we shed light on the installation of the Magento 2 sample data if your Magento software has been downloaded as a compressed archive or via the composer create-project command.
The method is suitable for both Magento Community Edition and Enterprise Edition.
Magento 2 sample data prerequisites
The only requirement in this section is related to Magento’s composer.json. It should be able to get components from repo.magento.com. In order to achieve this goal, you should:
be logged as the Magento file system owner into the Magento server;
Installing Magento 2 sample data by cloning repositories
The following section of the article describes the Magento 2 sample data installation by cloning the Magento 2 GitHub repository. Use this method only if you are a contributing developer. Otherwise, rely on the method described above.
And even if you are a contributing developer, there are two strict requirements: 1) you should use Magento CE, 2) you should clone only the Magento 2 develop branch.
It is also necessary to mention that there are two types of Magento 2 sample data. The more current one – the develop branch; and more stable – a released branch. As mentioned above, Magento 2 contributors should use the develop branch.
In both cases, it is necessary to clone the corresponding branch of the Magento 2 GitHub repository. For instance, the develop branch sample data can be used only with the appropriate branch – Magento 2 develop branch.
Cloning the Magento 2 sample data repository
You can install the Magento 2 sample data by cloning the sample data repository with the SSH protocol or with the HTTPS protocol.
SSH
If you’ve decided to use the SSH protocol for cloning the Magento 2 sample data GitHub repository, perform the following actions:
Choose SSH from the list of available options situated next to the ‘Find file’ button.
Click ‘Copy to clipboard’ which is right after the URL.
Now, it is necessary to change to the docroot directory of your web server. In case of Ubuntu, it often has the following structure /var/www. For CentOS, it can be /var/www/html.
The next step requires entering git clone and pasting the value from step 1. The official documentation provides the following example:
Choose SSH from the list of available options situated next to the ‘Find file’ button.
Click ‘Copy to clipboard’ which is right after the URL.
Now, it is necessary to change to the docroot directory of your web server. In case of Ubuntu, it often has the following structure /var/www. For CentOS, it can be /var/www/html.
The next step requires entering git clone and pasting the value from step 1. The official documentation provides the following example:
The completion of the command will take several minutes. Then you can start the next section.
How to set up file system ownership and permissions
Since the php build-sample-data.php script is responsible for creating symlinks between the repositories with sample data and Magento 2, it is required tj set file system permissions and ownership related to the Magento 2 sample data repository; otherwise, you won’t access the storefront. In order to do so, perform the following actions:
First of all, you should change to your clone directory with sample data and set ownership:
1
chown-R:<your web server group name>.
In case of CentOS, use chown -R :apache .; in case of Ubuntu – chown -R :www-data .