Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 964effe

Browse files
authored
Merge pull request #8254 from magento/MC38472-remote-storage
MC38472 remote storage
2 parents 02c3ea9 + 62a1eb9 commit 964effe

File tree

8 files changed

+270
-1
lines changed

8 files changed

+270
-1
lines changed

src/_data/toc/configuration-guide.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,20 @@ pages:
286286
- label: Tutorial—Set up multiple websites with Apache
287287
url: /config-guide/multi-site/ms_apache.html
288288

289+
- label: Remote storage
290+
url: /config-guide/remote-storage/config-remote-storage.html
291+
exclude_versions: ["2.3"]
292+
children:
293+
294+
- label: Configure AWS S3 adapter
295+
url: /config-guide/remote-storage/config-remote-storage-aws-s3.html
296+
297+
- label: Configure caching
298+
url: /config-guide/remote-storage/config-remote-storage-caching.html
299+
300+
- label: Configure image resizing
301+
url: /config-guide/remote-storage/config-remote-storage-image-resize.html
302+
289303
- label: Set up a custom cron job and cron group
290304
url: /config-guide/cron/custom-cron.html
291305
children:
Loading
Loading
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
group: configuration-guide
3+
title: Configure AWS S3 bucket for remote storage
4+
functional_areas:
5+
- Configuration
6+
- System
7+
- Setup
8+
---
9+
10+
The [Amazon Simple Storage Service (Amazon S3)][AWS S3] is an object storage service that offers industry-leading scalability, data availability, security, and performance. The AWS S3 service uses buckets, or containers, for data storage. This configuration requires you to create a _private_ bucket.
11+
12+
{:.bs-callout-warning}
13+
Magento highly discourages the use of public buckets because it poses a serious security risk.
14+
15+
{:.procedure}
16+
To enable remote storage with the AWS S3 adapter:
17+
18+
1. Log in to your Amazon S3 dashboard and create a _private_ bucket.
19+
20+
1. Set up [AWS IAM][] roles. Alternatively, generate access and secret keys.
21+
22+
1. Configure Magento to use the private bucket. See [Remote storage options][options] for a full list of parameters.
23+
24+
```bash
25+
bin/magento setup:config:set --remote-storage-driver="aws-s3" --remote-storage-bucket="<bucket-name>" --remote-storage-region="<region-name>" --remote-storage-prefix="<optional-prefix>" --access-key=<optional-access-key> --secret-key=<optional-secret-key> -n
26+
```
27+
28+
## Configure Nginx
29+
30+
Nginx requires an additional configuration to perform Authentication with the `proxy_pass` directive. Add the following proxy information to the `nginx.conf` file:
31+
32+
>nginx.conf
33+
34+
```conf
35+
location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
36+
# Proxying to AWS S3 storage.
37+
resolver 8.8.8.8;
38+
set $bucket "<s3-bucket-name>";
39+
proxy_pass https://s3.amazonaws.com/$bucket$uri;
40+
proxy_pass_request_body off;
41+
proxy_pass_request_headers off;
42+
proxy_intercept_errors on;
43+
proxy_hide_header "x-amz-id-2";
44+
proxy_hide_header "x-amz-request-id";
45+
proxy_hide_header "x-amz-storage-class";
46+
proxy_hide_header "Set-Cookie";
47+
proxy_ignore_headers "Set-Cookie";
48+
}
49+
```
50+
51+
### Authentication
52+
53+
If you use access and secret keys instead of [AWS IAM][] roles, you must include the [`ngx_aws_auth`][ngx repo] Nginx module.
54+
55+
<!-- link definitions -->
56+
[AWS S3]: https://aws.amazon.com/s3
57+
[AWS IAM]: https://aws.amazon.com/iam/
58+
[options]: {{page.baseurl}}/config-guide/remote-storage/config-remote-storage.html#remote-storage-options
59+
[ngx repo]: https://github.com/anomalizer/ngx_aws_auth
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
group: configuration-guide
3+
title: Configure caching for remote storage
4+
functional_areas:
5+
- Configuration
6+
- System
7+
- Setup
8+
---
9+
10+
Remote storage provides a cache layer for external API calls. The caching is based on the [Flysystem caching solution][flysystem], which provides cache adapters. Remote storage includes the following cache types:
11+
12+
- **Memory cache**—Memory cache is enabled by default and provides per-request cache.
13+
- **Redis cache**—Redis cache is a persistent cache that is stored in Redis and requires an active Redis service with additional configuration.
14+
15+
## Set up persistent Redis cache
16+
17+
{:.procedure}
18+
To use Redis cache with [predis/predis][predis] extension:
19+
20+
1. Add the `predis/predis` extension to the `require` section of your `composer.json` file.
21+
22+
```bash
23+
composer require predis/predis
24+
```
25+
26+
1. Use the following example to add a configuration to the `app/etc/env.php` file.
27+
28+
```php
29+
[
30+
'remote_storage' => [
31+
# Remote storage configuration section
32+
'cache' => [
33+
'adapter' => 'predis',
34+
'config' => [
35+
'scheme' => 'tcp', # Required scheme
36+
'host' => 'redis.internal', # Required hostname of Redis service
37+
'port' => 6379 # Required port of Redis service
38+
]
39+
]
40+
]
41+
];
42+
```
43+
44+
<!-- link definitions -->
45+
[flysystem]: https://flysystem.thephpleague.com/v1/docs/advanced/caching
46+
[predis]: https://github.com/predis/predis
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
group: configuration-guide
3+
title: Configure image resizing for remote storage
4+
functional_areas:
5+
- Configuration
6+
- System
7+
---
8+
9+
By default, Magento supports image resizing on the application side. However, by enabling the Remote Storage module, you can use Nginx to offload image resizing to the server side, where you can save disk resources and optimize disk usage.
10+
11+
The following diagram shows how Nginx retrieves, resizes, and stores images in the cache. Resizing is determined by the parameters included in the URL, such as height and width.
12+
13+
![image resize]
14+
15+
## Configure URL format in Magento
16+
17+
To resize images on the server side, you must configure Magento to provide arguments for the height, width, and location (URL) of the image.
18+
19+
{:.procedure}
20+
To configure Magento for server-side image resizing:
21+
22+
1. In the _Admin_ panel, click **Stores** > **Settings** > **Configuration** > **General** > **Web**.
23+
24+
1. In the right pane, expand **Url options**.
25+
26+
1. In the _Catalog media URL format_ section, clear **Use system value**.
27+
28+
1. Select the `Image optimization based on query parameters` URL in the **_Catalog media URL format_** field.
29+
30+
1. Click **Save Config**.
31+
32+
1. Continue to the [Nginx configuration](#configure-nginx).
33+
34+
## Configure Nginx
35+
36+
To continue configuring server-side image resizing, you must prepare the `nginx.conf` file and provide a `proxy_pass` value for your chosen adapter.
37+
38+
{:.procedure}
39+
To enable Nginx to resize images:
40+
41+
1. Install the [Nginx image filter module][nginx-module].
42+
43+
```shell
44+
load_module /etc/nginx/modules/ngx_http_image_filter_module.so;
45+
```
46+
47+
1. Create an `nginx.conf` file based on the included template `nginx.conf.sample` file. For example:
48+
49+
```conf
50+
location ~* \.(ico|jpg|jpeg|png|gif|svg)$ {
51+
set $width "-";
52+
set $height "-";
53+
if ($arg_width != '') {
54+
set $width $arg_width;
55+
}
56+
if ($arg_height != '') {
57+
set $height $arg_height;
58+
}
59+
image_filter resize $width $height;
60+
image_filter_jpeg_quality 90;
61+
}
62+
```
63+
64+
1. [_Optional_] Configure a `proxy_pass` value for your specific adapter.
65+
66+
- [Amazon Simple Storage Service (Amazon S3)][AWS S3]
67+
68+
<!-- link definitions -->
69+
70+
[AWS S3]: {{page.baseurl}}/config-guide/remote-storage/config-remote-storage-aws-s3.html
71+
[image resize]: {{site.baseurl}}/common/images/config-remote-storage-nginx-image-resize.png
72+
{:width="800px"}
73+
[nginx-module]: http://nginx.org/en/docs/http/ngx_http_image_filter_module.html
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
group: configuration-guide
3+
title: Configure remote storage
4+
functional_areas:
5+
- Configuration
6+
- System
7+
- Setup
8+
---
9+
10+
The Remote Storage module provides the option to store media files and schedule imports/exports in a persistent, remote storage container using a storage service, such as AWS S3 or Azure Blob Storage. By default, Magento stores media files in the same filesystem that contains the application. This is inefficient for complex, multi-server configurations, and can result in degraded performance when sharing resources. With the Remote Storage module, you can store media files in the `pub/media` directory and import/export files in the `var` directory of the remote object storage to take advantage of server-side image resizing.
11+
12+
![schema image]
13+
14+
## Remote storage options
15+
16+
You can configure remote storage using the `remote-storage` option with the [`setup` CLI command][setup]. The `remote-storage` option uses the following syntax:
17+
18+
```text
19+
--remote-storage-<parameter-name>="<parameter-value>"
20+
```
21+
22+
The `parameter-name` refers to the specific remote storage parameter name. The following table lists the parameters available for configuring remote storage:
23+
24+
| Command line Parameter | Parameter name | Description | Default value |
25+
|--- |--- |--- |--- |
26+
| `remote-storage-driver` | driver | Adapter name<br>Possible values:<br>**file**: Disables remote storage and uses the local filesystem<br>**aws-s3**: Use the [Amazon Simple Storage Service (Amazon S3)][AWS S3] | none |
27+
| `remote-storage-bucket` | bucket | Object storage or container name | none |
28+
| `remote-storage-prefix` | prefix | Optional prefix (location inside of object storage) | empty |
29+
| `remote-storage-region` | region | Region name | none |
30+
| `remote-storage-key` | access key | Optional access key | empty |
31+
| `remote-storage-secret` | secret key | Optional secret key | empty |
32+
33+
### Storage adapters
34+
35+
The default storage location is in the local filesystem. A _storage adapter_ enables you to connect to a storage service and store your files anywhere. Magento supports configuring the following storage services:
36+
37+
- [Amazon Simple Storage Service (Amazon S3)][AWS S3]
38+
39+
## Enable remote storage
40+
41+
You can install remote storage during a new Magento installation or add it to an existing Magento instance using `remote-storage` parameter name-and-value pairs with `setup` CLI commands. Minimally, you must supply the storage `driver`, `bucket`, and `region`.
42+
43+
The following examples enable the remote storage with an AWS S3 storage adapter in the US:
44+
45+
- Install new Magento with remote storage
46+
47+
```bash
48+
bin/magento setup:install --remote-storage-driver="aws-s3" --remote-storage-bucket="myBucket" --remote-storage-region="us-east-1"
49+
```
50+
51+
- Enable remote storage on existing Magento
52+
53+
```bash
54+
bin/magento setup:config:set --remote-storage-driver="aws-s3" --remote-storage-bucket="myBucket" --remote-storage-region="us-east-1"
55+
```
56+
57+
## Migrate content
58+
59+
After you enable remote storage for a specific adapter, you can use the CLI to migrate existing _media_ files to the remote storage.
60+
61+
```bash
62+
./magento2ce/bin/magento remote-storage:sync
63+
```
64+
65+
{:.bs-callout-info}
66+
The sync command only migrates files in the `pub/media` directory, _not_ the import/export files in the `var` directory. See [Scheduled Import/Export][import-export] in the _Magento 2.4 User Guide_.
67+
68+
<!-- link definitions -->
69+
[AWS S3]: {{site.baseurl}}/guides/v2.4/config-guide/remote-storage/config-remote-storage-aws-s3.html
70+
[import-export]: https://docs.magento.com/user-guide/system/data-scheduled-import-export.html
71+
[nginx-module]: http://nginx.org/en/docs/http/ngx_http_image_filter_module.html
72+
[schema image]: {{site.baseurl}}/common/images/config-remote-storage-schema.png
73+
{:width="500px"}
74+
[setup]: {{site.baseurl}}/guides/v2.4/install-gde/install/cli/install-cli-subcommands-deployment.html#instgde-cli-subcommands-configphp

src/guides/v2.4/install-gde/install/cli/install-cli-install.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ The install command uses the following format:
6666
magento setup:install --<option>=<value> ... --<option>=<value>
6767
```
6868

69-
The following tables describe the installation option names and values. For example installation commands. see [Sample localhost installations](#install-cli-example).
69+
The following tables describe the installation option names and values, such as installation commands. See [Sample localhost installations](#install-cli-example).
7070

7171
{:.bs-callout-info}
7272
Any options that contain spaces or special characters must be enclosed in either single or double quotes.
@@ -113,6 +113,9 @@ In Magento Commerce version 2.2.8 and later, you can create the Magento admin us
113113
|`--db-init-statements`|Advanced MySQL configuration parameter. Uses database initialization statements to run when connecting to the MySQL database. Consult a reference similar to this one before you set any values.<br><br>Default is `SET NAMES utf8;`.|No|
114114
|`--sales-order-increment-prefix`|Specify a string value to use as a prefix for sales orders. Typically, this is used to guarantee unique order numbers for payment processors.|No|
115115

116+
{:.bs-callout-tip}
117+
To enable remote storage services during installation, see [Configure Remote Storage]({{ page.baseurl }}/config-guide/remote-storage/config-remote-storage.html) in the _Configuration Guide_.
118+
116119
**Elasticsearch configuration options:**
117120

118121
|Name|Value|Required?|

0 commit comments

Comments
 (0)