Magento 2.1.18 is the final 2.1.x release. After June 2019, Magento 2.1.x will no longer receive security patches, quality fixes, or documentation updates.
To maintain your site's performance, security, and PCI compliance, upgrade to the latest version of Magento.

Configure the Magento application

Now that you’ve finished installing the Magento application, you need to configure it. This topic provides some recommended configuration settings for Magento; the list is not complete so watch this space.

Set up cron

cron—the UNIX task scheduler—is critical to Magento’s day-to-day operations. It schedules things like reindexing, newsletters, e-mails, sitemaps, and so on.

Immediately after finishing your Magento installation, set up a crontab for the Magento file system owner.

Prerequisites

Magento uses cron for two sets of tasks, and for each, cron can run with a different configuration:

  • PHP command-line configuration: The general cron job that reindexes indexers, generates e-mails, generates the sitemap, and so on.

    You can find the command-line configuration using the command php --ini.

  • Web server PHP plug-in configuration: Two other cron jobs are used by the Component Manager and System Upgrade utilities.

    You can find the web server plug-in configuration using phpinfo.php.

  • To avoid issues during installation and upgrade, we strongly recommend you apply the same PHP settings to both the PHP command-line configuration and to the PHP web server plug-in’s configuration. For more information, see Required PHP settings.
  • In a multi-node system, crontab can run on only one node. This applies to you only if you set up more than one webnode for reasons related to performance or scalability.

Find the PHP binary and php.ini path

To display the path to your PHP binary, enter

1
which php

A sample result follows:

1
/usr/bin/php

Create the cron job

To create a cron job for the Magento file system owner, enter the following command as a user with root privileges:

1
crontab -u <Magento file system owner username> -e

For example,

1
crontab -u magento_user -e

A text editor displays. (You might need to choose a text editor first.)

1
2
3
* * * * * <path to php binary> <magento install dir>/bin/magento cron:run | grep -v "Ran jobs by schedule" >> <magento install dir>/var/log/magento.cron.log
* * * * * <path to php binary> <magento install dir>/update/cron.php >> <magento install dir>/var/log/update.cron.log
* * * * * <path to php binary> <magento install dir>/bin/magento setup:cron:run >> <magento install dir>/var/log/setup.cron.log

where

  • <path to php binary> is the absolute file system path to your PHP binary
  • <magento install dir> is the directory in which you installed the Magento software; for example, /var/www
  • | grep -v "Ran jobs by schedule" filters this message from the log, making any errors easier to spot

The first command (magento cron:run) reindexes indexers, sends automated e-mails, generates the sitemap, and so on. Usually it’s associated with the PHP command line .ini file. The other two commands are used by the Component Manager and System Upgrade.

If you’re a contributing developer (that is, you cloned the Magento 2 GitHub repository), only the first line applies to you. See the examples that follow for details.

Example 1: Everyone except contributing developers

For example, if the PHP binary is located in /usr/bin, you installed Magento in /var/www/magento2, enter

Example:

1
2
3
* * * * * /usr/bin/php /var/www/magento2/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/magento2/var/log/magento.cron.log
* * * * * /usr/bin/php /var/www/magento2/update/cron.php >> /var/www/magento2/var/log/update.cron.log
* * * * * /usr/bin/php /var/www/magento2/bin/magento setup:cron:run >> /var/www/magento2/var/log/setup.cron.log

Example 2: Contributing developers only (that is, you cloned the Magento 2 GitHub repository):

1
* * * * * /usr/bin/php /var/www/magento2/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/magento2/var/log/magento.cron.log

The preceding works for contributing developers because if you cloned the GitHub repository you don’t have an update directory and errors result if you run magento setup:cron:run. These cron jobs work in the Web Setup Wizard, which contributing developers cannot use for installing or updating the Magento application or components.

Save your changes to the crontab and exit the editor.

For more information about cron, including how to remove a crontab and run cron from the command line, see Configure and run cron.

Security settings and recommendations

After installation, we recommend the following:

If you installed by cloning the Magento repository, make sure that when you deploy Magento, you only include files and folders that are required for the production environment. Files and folders that are not required can potentially expose security risks.

Enable Apache server rewrites

If you use the Apache web server, you must enable server rewrites for pages to display properly. Otherwise, you’ll see pages without styles and other issues.

Section on Apache server rewrites

Caching in a multi-webnode environment

If you have multiple webnodes, you cannot use Magento’s default file caching because there is no synchronization between webnodes. In other words, activity on one webnode is written to that webnode’s file system only. Subsequent activity, if performed on another webnode, can result in unnecessary files being written or can result in errors.

Instead, use Redis for both the default cache and the page cache.

Server settings

This section briefly discusses settings we recommend you consider for the server on which Magento runs. Some of these settings are not directly related to Magento; these are provided as suggestions only.

Log rotation

The UNIX logrotate utility enables you to administer systems that generate large numbers of log files. It allows automatic rotation, compression, removal, and mailing of log files. Each log file can be handled daily, weekly, monthly, or when the log file exceeds a specified size.

For more information, see one of the following:

Set up iptables rules to enable various Magento services to communicate.

Whether you have one server or many, you must open ports in the firewall to enable Magento services to communicate. For example, if you use the Solr search engine with Magento Commerce, you must enable it to communicate with the web server. If you have multiple web nodes, you must enable them to communicate with each other.

More information:

Security Enhanced Linux (SELinux) rules

We don’t recommend whether or not you use SELinux at all; however, if you use it, you must configure Magento services to communicate with each other similar to configuring iptables.

More information:

Set up an e-mail server

Magento requires an e-mail server. We don’t recommend a particular server but you can try any of the following:

Settings for Magento Commerce only

You can configure the following only if you use Magento Commerce:

Updated