A Tutorial On Using A Content Delivery Network For Magento 2 Media Storage

As we said in previous articles, store administrators can use a Content Delivery Network (CDN) to store media files. Although the version of Magento that is installed “on-premise” does not include integration with any specific CDN, store administrators can choose and use their CDN. Magento Commerce (Cloud) consists of the Fastly CDN. To learn more, see Fastly in the Magento developer documentation.

After configuring the CDN, you must complete the configuration from the Admin. You can make the changes at either the global or website level. When a CDN is used for media storage, all paths to media on store pages are changed to the CDN paths that are specified in the configuration.

CDN Workflow

  1. Browser requests media: A page from the web store opens in the browser, and the browser requests the media that is specified in the HTML.
  2. Request sent to CDN; images found and served. First, the request is sent to the CDN. If the CDN has the images in storage, the media files will be served to the browser.
  3. Media not found, request sent to Magento web server. If the media files are not available in the CDN, the request is sent to the Magento web server. If the media files are available in the file system, the web server sends them to the browser.

For security reason, JavaScript may not work correctly if the CDN is placed outside of the subdomain when a CDN is used as media storage.

Follow these steps to configure a content delivery network for Magento 2 media storage:

On Admin sidebar click Stores > Under Settings click Configuration > Under General click Web. Set Store View as needed, open the Base URLs tab and follow these steps:

Content Delivery Network For Magento 2_1

Enter the URL of the location on the CDN where static view files are stored to the Base URL for Static View Files.

Enter the URL of the JS files on the CDN to the Base URL for User Media Files.

You can empty these field or can start with the placeholder: {{unsecure_base_url}}

Open the Base URLs (Secure) tab:

Base URLs (Secure)
Base URLs (Secure)

Do the same as above and click the Save Config

Tutorial On Using Database In Magento 2 Media Files Storage

In the default installation of Magento 2 Open Source, images, compiled CSS files, and JS files of the Magento instance are saved in the file system on the server. Store administrators can store these files in a database on a database server. This method allows you to select between auto-sync and reverse-sync between the web server file system and the database. You can use the default database to store media or create a new one. To use a newly created database as media storage, you must include information about it and its access credentials in the local .xml file.

The database workflow of using database In Magento 2 media files storage below:

  1. Browser requests media: The browser requests the media that is specified in the HTML while opening a page in the store on the browser.
  2. The system looks for media in the file system: The media files will be searched and found in the file system and send to the browser.
  3. The system locates media in database: If the file is not available in the system, a request is sent to the database that is specified in the configuration.
  4. The system locates media in database: A PHP script sends the files from the database to the file system and sent to the browser.

If the server is supported and web server rewrites are enabled for Magento, the PHP script runs only when the requested media files are not in the file system.

If the server is not supported or web server rewrites are disabled for Magento, the PHP script runs even if the requested media files exist in the file system.

To configure a database for media storage, please follow these steps:

On the admin sidebar click Stores, under Settings click Configuration, under Advanced, click System. To apply the configuration at the global level, set Store View to Default Config. Open the Storage Configuration for Media tab and follow these steps:

Storage Configuration for Media (Database)
Storage Configuration for Media (Database)
  • Uncheck the Use system value checkbox
  • Set Media Storage to “Database.”
  • Set Select Media Database to the database you want to use.
  • Click Synchronize, enter the Environment Update Time and click Save Config.

In the next article, we will describe tutorial on using a CDN as a media storage for Magento 2 online store. Keep tracking Magestandard and see you in the next blog post.

What is Alternate Media Storage In Magento 2?

In the previous articles, we described everything about controlling the administrators’ management system, including how to add users, unlock users and creating user roles in Magento 2 admin panel. This article will describe the alternate media storage method in Magento 2.

In Magento 2 default installation, you have two primary option to save media files:

The first method is you can store media files in a database on a database server, or the second method is you can store the media files on a Content Delivery Network (CDN) instead of saving media files on the file system of the web server. The advantage of saving media files in a database on the alternate media storage such as a database server or Content Delivery Network limits the effort required to sync media when multiple instances of the system that are deployed on other servers that need access to the same images, CSS files, and other media files. The advantage of store media files on the database server is the selection of auto-sync and reserve-sync between the web server file system and the database.

Media Storage Configuration
Media Storage Configuration

Each one of these alternate media storages has a specific workflow and also have a specific way to configure. You can do a configuration for both two alternate media storages in Magento 2 admin panel, and we will provide more detail tutorial for these alternate media storages in the next two articles, so you will not confuse in configuring alternate media storage.

Above is an article on two alternate media storages in the default installation of Magento 2 Open Source. We hope that you will know the critical detail of media storage, and prepare a basic knowledge on configuring database and CDN. On the next two articles, we will describe information on using the database for media storage and using a Content Delivery Network. See you in the next blog post.

How To Add Users In Magento 2 Admin Panel

In the default installation of Magento 2, an Admin account is created that gives you full administrative access. First, you have to create another user account with full Administrator access, so you can use one account for your everyday Administrative activities, and reserve the other as a “Super Admin” account in case you lost access to your main account.

For a team of administrators, you can create a separate account for each, and set restrict access based on their business. To do that, you have to create a role with limited scope and access only to the necessary resources and assign the role to an admin account. After assigned to a restricted role, admin users can see and change data only for websites or stores that are associated with the role, but cannot make changes to any global settings or data.

Example Admin Users
Example Admin Users

Step 1: Create a New User

On the admin sidebar click System > All Users > Add New User. Follow these steps:

New User Account Information
New User Account Information

Enter all required information and set “This account is” as Active, enter your password under Current User Identity Verification.

Step 2: Define the Role

On the left of the panel, click User Role. In the Assigned column, tick the Administrators selection and click Save User.

Add New User Role
Add New User Role

Admin Password Requirements

FIELD DESCRIPTION
Password Length of the password must be seven or more characters long, include both letters and numbers. For further information, please read this article: How To Configure Admin Security In Magento 2 Admin Panel.

Above is a tutorial on adding users in Magento 2 admin panel. We hope that you can manage the Administrators function in Magento 2 installation, and run your online store smoothly. In the next article, we will describe one of the most security function of Magento 2 platform: Lock Admin Account. Keep tracking Magestandard by subscribing to our site to read more Magento 2 tutorial blog post. See you in the next article.