Clone sample data Git repositories
This topic discusses how to clone and add sample data if you cloned the Magento Open Source GitHub repository. This method is intended only for contributing developers (that is, developers who plan to contribute to the Magento Open Source codebase).
If you’re not a contributing developer, choose one of the other options displayed in the table of contents on the left side of the page.
Contributing developers can use this method of installing sample data only if the following is true:
- You use Magento Open Source
- You cloned the GitHub repository
develop
branch (more current) or a released branch (such as 2.4
(more stable)). We recommend you use a released branch because it’s more stable. If you’re contributing code to the repository and you need the most recent code, use the develop
branch. Regardless of the branch you choose, you must clone the corresponding branch of the Magento Open Source GitHub repository. For example, sample data for the develop
branch can be used only with the Magento Open Source develop
branch.Clone the sample data repository
This section discusses how to install sample data by cloning the sample data repository. You can clone the sample data repository in any of the following ways:
- Clone with the SSH protocol
- Clone with the HTTPS protocol
Clone with SSH
To clone the sample data GitHub repository using the SSH protocol:
-
In a web browser, go to the sample data repository.
-
Next to the name of the branch, click SSH from the list.
-
Click Copy to clipboard
The following figure shows an example.
-
Change to your web server’s docroot directory.
Typically, for Ubuntu, it’s
/var/www
and for CentOS it’s/var/www/html
. -
Enter
git clone
and paste the value you obtained previously.An example follows:
code language-bash git clone git@github.com:magento/magento2-sample-data.git
-
Wait for the repository to clone on your server.
note note NOTE If the following error displays, make sure you shared your SSH key with GitHub: code language-none Cloning into 'magento2'... Permission denied (publickey). fatal: The remote end hung up unexpectedly
-
Ensure you check out the branch of the sample data repository that corresponds with the branch you used from the main
magento2
repository.For example:
If you used the
2.4-develop
branch of the Magento Open Source GitHub repository, the Sample Data branch should be2.4-develop
.To checkout the correct branch, run the following command from the sample data repository’s root directory (assuming you need the
2.4-develop
branch):code language-bash git checkout 2.4-develop
-
Change to
<app_root>
. -
Enter the following command to create symbolic links between the files that you cloned so sample data works properly:
code language-bash php -f <sample-data_clone_dir>/dev/tools/build-sample-data.php -- --ce-source="<path_to_your_magento_instance>"
-
Wait for the command to complete.
-
Run the following command:
code language-bash bin/magento setup:upgrade
Clone with HTTPS
To clone the sample data GitHub repository using the HTTPS protocol:
-
In a web browser, go to the sample data repository.
-
On the right side of the page, under the clone URL field, click HTTPS.
-
Click Copy to clipboard.
The following figure shows an example.
-
Change to your web server’s docroot directory.
Typically, for Ubuntu, it’s
/var/www
and for CentOS it’s/var/www/html
. -
Enter
git clone
and paste the value you obtained previously.An example follows:
code language-bash git clone https://github.com/magento/magento2-sample-data.git
-
Wait for the repository to clone on your server.
-
Ensure you check out the branch of the sample data repository that corresponds with the branch you used from the main
magento2
repository.For example:
If you used the
2.4-develop
branch of the Magento Open Source GitHub repository, the Sample Data branch should be2.4-develop
.To checkout the correct branch, run the following command from the sample data repository’s root directory (assuming you need the
2.4-develop
branch):code language-bash git checkout 2.4-develop
-
Change to
<magento_root>
. -
Enter the following command to create symbolic links between the files that you cloned so sample data works properly:
code language-bash php -f <sample-data_clone_dir>/dev/tools/build-sample-data.php -- --ce-source="<path_to_your_magento_instance>"
For example,
code language-bash php -f <sample-data_clone_dir>/dev/tools/build-sample-data.php -- --ce-source="/var/www/magento2"
-
Wait for the command to complete.
-
See the next section.
code language-bash |
---|
|
Set file system ownership and permissions
Because the php build-sample-data.php
script creates symlinks between the sample data repository and your Magento Open Source repository, you must set file system permissions and ownership in the sample data repository. Failure to do so results in errors accessing the storefront.
To set file system permissions and ownership on the sample data repository:
-
Change to your sample data clone directory.
-
Set ownership:
code language-bash chown -R :<your web server group name> .
Typical examples:
-
CentOS:
chown -R :apache .
-
Ubuntu:
chown -R :www-data .
-
-
Set permissions:
code language-bash find . -type d -exec chmod g+ws {} +
-
Clear static files:
code language-bash cd <your Magento Open Source install dir>
code language-bash rm -rf var/cache/* var/page_cache/* generated/*
Complete the sample data installation
After you download the sample data packages, log in to your application server as, or switch to, the file system owner and enter the following command in <app_root>
directory:
bin/magento setup:upgrade