When you are using repository approach to install your Magento instance. Then you need to follow below steps to ensure sample data works in your Magento instance.
Pull your sample data first.
Pull sample data repository to a separate directory other than your Magento instance. For example, if your M2 instance is at /var/www/html/magento2
directory, then you can create a new directory at var/www/html/m2-sampledata
.
Also, when you pull the sample data, you should make sure that you are pulling the corresponding branch to your M2 instance. For example, here you are using develop
branch, so you should also use develop
branch of sample data
Note: Magento recommends to use a stable release even if you are using repository approach to install your Magento instance. Develop branch is for those who would like to contribute to the Magento code base.
All these you can achieve using below steps. (if you are using ubuntu)
mkdir /var/www/html/m2-sampledata
cd /var/www/html/m2-sampledata
git init
git remote add origin https://github.com/magento/magento2-sample-data
git pull origin develop
So here we just created a directory, cd into that directory, initialized git, added the remote repository and then pulled the develop
branch. If you are using some other branch in your M2 instance then you need to pull that branch.
Create Symlinks
Now we have downloaded sample data. But it is available in another directory and our M2 instance has no clue about this sample data. So we need to let our M2 instance to know about the sample data files.
Luckily, M2 sample data provide us some tricks to achieve this. Execute below steps.
(Assumes you are at m2-sampledata
directory in your CLI)
cd dev/tools
php -f build-sample-data.php -- --ce-source="<your Magento Open Source install dir>"
Replace the install directory with your M2 instance absolute path. For ubuntu, it would be most probably looks like
php -f build-sample-data.php -- --ce-source="/var/www/html/magento2"
If your m2 instance directory is magento2
.
This will create symlinks between your M2 instance and M2 Sample data directory.
Install Sample Data
cd /var/www/html/magento2
php bin/magento setup:upgrade
php bin/magento setup:di:compile
Now we are CD into our M2 instance directory, then perform upgrade and compilation. You are done.
In addition to this, there should be some permissions to be correctly set in order to make it work. For more info, you can see all these in the official documentation