|
| 1 | + |
| 2 | +## Install sample data by cloning repositories {#sample-clone} |
| 3 | + |
| 4 | +This topic discusses how to clone and add Magento sample data if you cloned the Magento GitHub repository. This method is intended only for contributing developers (that is, developers who plan to contribute to the Magento 2 codebase). |
| 5 | + |
| 6 | +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. |
| 7 | + |
| 8 | +Contributing developers can use this method of installing sample data *only* if all of the following are true: |
| 9 | + |
| 10 | +* You use {{site.data.var.ce}} |
| 11 | +* You [cloned the Magento 2 repository]({{ page.baseurl }}/install-gde/prereq/dev_install.html). |
| 12 | + |
| 13 | +{:.bs-callout-warning} |
| 14 | +You can use sample data with either the `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 Magento 2 repository and you need the most recent code, use the `develop` branch. Regardless of the branch you choose, you must [clone]({{ page.baseurl }}/install-gde/prereq/dev_install.html) the corresponding branch of the Magento 2 GitHub repository. For example, sample data for the `develop` branch can be used *only* with the Magento 2 `develop` branch. |
| 15 | + |
| 16 | +See the following sections: |
| 17 | + |
| 18 | +* [Clone the sample data repository](#clone-sample-repo) |
| 19 | +* [Set file system ownership and permissions](#samp-data-perms) |
| 20 | + |
| 21 | +## Clone the sample data repository {#clone-sample-repo} |
| 22 | + |
| 23 | +This section discusses how to install Magento sample data by cloning the sample data repository. You can clone the sample data repository in any of the following ways: |
| 24 | + |
| 25 | +* Clone with the [SSH protocol](#clone-sample-repo-ssh) |
| 26 | +* Clone with the [HTTPS protocol](#instgde-prereq-compose-clone-https) |
| 27 | + |
| 28 | +### Clone with SSH {#clone-sample-repo-ssh} |
| 29 | + |
| 30 | +To clone the Magento sample data GitHub repository using the SSH protocol: |
| 31 | + |
| 32 | +1. In a web browser, go to [the Magento sample data repository](https://github.com/magento/magento2-sample-data). |
| 33 | +1. Next to the name of the branch, click **SSH** from the list. |
| 34 | +1. Click **Copy to clipboard** |
| 35 | + |
| 36 | + The following figure shows an example. |
| 37 | + |
| 38 | + {:width="650px"} |
| 39 | + |
| 40 | +1. Change to your web server's docroot directory. |
| 41 | + |
| 42 | + Typically, for Ubuntu, it's `/var/www` and for CentOS it's `/var/www/html`. |
| 43 | + |
| 44 | + Need [help locating the docroot?]({{ page.baseurl }}/install-gde/basics/basics_docroot.html) |
| 45 | + |
| 46 | +1. Enter `git clone` and paste the value you obtained from step 1. |
| 47 | + |
| 48 | + An example follows: |
| 49 | + |
| 50 | + ```bash |
| 51 | + git clone git@github.com:magento/magento2-sample-data.git |
| 52 | + ``` |
| 53 | + |
| 54 | +1. Wait for the repository to clone on your server. |
| 55 | + |
| 56 | + {:.bs-callout-info} |
| 57 | + If the following error displays, make sure you [shared your SSH key](https://help.github.com/articles/generating-ssh-keys/) with GitHub:<br> |
| 58 | + |
| 59 | + ```terminal |
| 60 | + Cloning into 'magento2'... |
| 61 | + Permission denied (publickey). |
| 62 | + fatal: The remote end hung up unexpectedly |
| 63 | + ``` |
| 64 | + |
| 65 | +1. Ensure you checkout the branch of the sample data repository that corresponds with the branch you used from the main `magento2` repository. |
| 66 | + |
| 67 | + For example: |
| 68 | + |
| 69 | + If you used the `2.4-develop` branch of the Magento 2 repository, the Sample Data branch should be `2.4-develop`. |
| 70 | + |
| 71 | + If you used the `2.4.1` branch of the Magento 2 repository, the Sample Data branch should be `2.4.1`. |
| 72 | + |
| 73 | + To checkout the correct branch, run the following command from the sample data repository's root directory (assuming you need the `2.4.1` branch): |
| 74 | + |
| 75 | + ```bash |
| 76 | + git checkout 2.4.1 |
| 77 | + ``` |
| 78 | + |
| 79 | +1. Change to `<magento_root>`. |
| 80 | +1. Enter the following command to create symbolic links between the files you just cloned so sample data works properly: |
| 81 | + |
| 82 | + ```bash |
| 83 | + php -f <sample-data_clone_dir>/dev/tools/build-sample-data.php -- --ce-source="<path_to_your_magento_instance>" |
| 84 | + ``` |
| 85 | + |
| 86 | +1. Wait for the command to complete. |
| 87 | + |
| 88 | +1. See [Set file system permissions and ownership](#samp-data-perms). |
| 89 | + |
| 90 | +### Clone with HTTPS {#instgde-prereq-compose-clone-https} |
| 91 | + |
| 92 | +To clone the Magento sample data GitHub repository using the HTTPS protocol: |
| 93 | + |
| 94 | +1. In a web browser, go to [the Magento sample data repository](https://github.com/magento/magento2-sample-data). |
| 95 | +1. On the right side of the page, under the **clone URL** field, click **HTTPS**. |
| 96 | +1. Click **Copy to clipboard**. |
| 97 | + |
| 98 | + The following figure shows an example. |
| 99 | + |
| 100 | + {:width="650px"} |
| 101 | + |
| 102 | +1. Change to your web server's docroot directory. |
| 103 | + |
| 104 | + Typically, for Ubuntu, it's `/var/www` and for CentOS it's `/var/www/html`. |
| 105 | + |
| 106 | +1. Enter `git clone` and paste the value you obtained from step 1. |
| 107 | + |
| 108 | + An example follows: |
| 109 | + |
| 110 | + ```bash |
| 111 | + git clone https://github.com/magento/magento2-sample-data.git |
| 112 | + ``` |
| 113 | + |
| 114 | +1. Wait for the repository to clone on your server. |
| 115 | +1. Ensure you checkout the branch of the sample data repository that corresponds with the branch you used from the main `magento2` repository. |
| 116 | + |
| 117 | + For example: |
| 118 | + |
| 119 | + If you used the `2.4-develop` branch of the Magento 2 repository, the Sample Data branch should be `2.4-develop`. |
| 120 | + |
| 121 | + If you used the `2.4.1` branch of the Magento 2 repository, the Sample Data branch should be `2.4.1`. |
| 122 | + |
| 123 | + To checkout the correct branch, run the following command from the sample data repository's root directory (assuming you need the `2.4.1` branch): |
| 124 | + |
| 125 | + ```bash |
| 126 | + git checkout 2.4.1 |
| 127 | + ``` |
| 128 | + |
| 129 | +1. Change to `<magento_root>`. |
| 130 | +1. Enter the following command to create symbolic links between the files you just cloned so sample data works properly: |
| 131 | + |
| 132 | + ```bash |
| 133 | + php -f <sample-data_clone_dir>/dev/tools/build-sample-data.php -- --ce-source="<path_to_your_magento_instance>" |
| 134 | + ``` |
| 135 | + |
| 136 | + For example, |
| 137 | + |
| 138 | + ```bash |
| 139 | + php -f <sample-data_clone_dir>/dev/tools/build-sample-data.php -- --ce-source="/var/www/magento2" |
| 140 | + ``` |
| 141 | + |
| 142 | +1. Wait for the command to complete. |
| 143 | +1. See the next section. |
| 144 | + |
| 145 | +{:.bs-callout-warning} |
| 146 | +If you're installing sample data _after_ installing Magento, you must also run the following command to update the database and schema: |
| 147 | + |
| 148 | +```bash |
| 149 | +<magento_root>/bin/magento setup:upgrade |
| 150 | +``` |
| 151 | + |
| 152 | +## Set file system ownership and permissions {#samp-data-perms} |
| 153 | + |
| 154 | +Because the `php build-sample-data.php` script creates symlinks between the sample data repository and your Magento 2 repository, you must set file system permissions and ownership in the sample data repository. Failure to do so results in errors accessing the storefront. |
| 155 | + |
| 156 | +To set file system permissions and ownership on the sample data repository: |
| 157 | + |
| 158 | +1. Change to your sample data clone directory. |
| 159 | +1. Set ownership: |
| 160 | + |
| 161 | + ```bash |
| 162 | + chown -R :<your web server group name> . |
| 163 | + ``` |
| 164 | + |
| 165 | + Typical examples: |
| 166 | + |
| 167 | + * CentOS: `chown -R :apache .` |
| 168 | + |
| 169 | + * Ubuntu: `chown -R :www-data .` |
| 170 | + |
| 171 | +1. Set permissions: |
| 172 | + |
| 173 | + ```bash |
| 174 | + find . -type d -exec chmod g+ws {} + |
| 175 | + ``` |
| 176 | + |
| 177 | +1. Clear static files: |
| 178 | + |
| 179 | + ```bash |
| 180 | + cd <your {{site.data.var.ce}} install dir> |
| 181 | + ``` |
| 182 | + |
| 183 | + ```bash |
| 184 | + rm -rf var/cache/* var/page_cache/* generated/* |
| 185 | + ``` |
| 186 | + |
| 187 | +<!-- ABBREVIATIONS --> |
| 188 | + |
| 189 | +*[contributing developer]: A developer who contributes code to the Magento 2 CE codebase |
| 190 | +*[contributing developers]: Developers who contribute code to the Magento 2 CE codebase |
| 191 | +*[Contributing developers]: Developers who contribute code to the Magento 2 CE codebase |
0 commit comments