This guide aims to assist in operating a healthy and optimized Magento website. By the end of this article, we should clearly understand common Magento issues and how to resolve them.
This support article will cover best practices to start and maintain a healthy Magento 2.x website.
Magento is the 3rd most used e-commerce platform on the web, after Woocommerce and Shopify, according to the latest available statistics from builtwith.com.
Since Magento is a resource-intensive CMS, it's always recommended to have plenty of resources available on the hosting plan before deciding to use Magento or when migrating an existing Magento site to our network.
Related Articles
Magento 2.4 Requirements Matrix
Recommended Practices
CAUTION: This article does not apply to Magento 1.x.
It's always recommended to utilize server-side caching when running Magento sites. Both PHP and MySQL caching are recommended. PHP should be cached using OPCache, and MySQL should be cached using Redis.
OPcache
OPcache is recommended by Magento according to their official documentation. On our new servers with EasyApache 4, OPcache can be easily enabled along with PHP-FPM. Note that the PHP handler doesn't matter when PHP-FPM is used. Simply install OPcache for PHP using EA4 and enable PHP-FPM using the MultiPHP Manager from the WHM interface.
- Enable OPcache
- Update the OPcache INI
- SSH into the server as root
- Edit the INI at
/opt/cpanel/ea-php##/root/etc/php.d/10-opcache.ini
REPLACE: ea-php## with the correct PHP version. - Updatethe following settings
opcache.memory_consumption=512 opcache.max_accelerated_files=60000 opcache.consistency_checks=0 opcache.validate_timestamps=0 opcache.enable_cli=1
- Restart Apache and PHP-FPM
/scripts/restartsrv_httpd
CAUTION: When running PHP OPcache with PHP-FPM, after a Magento extension is installed or a PHP file is edited, the changes may not apply immediately due to the caching. In this scenario, we would need to restart Apache and PHP-FPM for them to take effect immediately.
/scripts/restartsrv_apache_php_fpm
Redis with Magento
Ensure that the Redis server is installed and running before updating the Magento configuration file to use Redis.
- Install Redis
- Log into into Root WHM
- Navigate to EasyApache 4, located under the Software section
- Select Customize
- Select PHP Extensions
- Toggle to install any php##-php-redis extensions needed
REPLACE: php## with the correct PHP version. - Click Review
- Click Provision
Enable Redis Configuration
- SSH into the server as the cPanel user that owns the domain
- Navigate to the document root
cd $(docroot.py domain.com)
REPLACE: domain.com with the domain of the site - Copy the current env.php file
cp app/etc/env.php ~/env.$(date -I).php
- Enable Redis page or default caching
- Enable Redis default caching
php bin/magento setup:config:set --cache-backend=redis --cache-backend-redis-server=127.0.0.1 --cache-backend-redis-db=0
- Enable Redis page caching
php bin/magento setup:config:set --page-cache=redis --page-cache-redis-server=127.0.0.1 --page-cache-redis-db=1
- Enable Redis default caching
- Restart Apache and PHP-FPM
/scripts/restartsrv_httpd
TIP: The redis cache can be cleared at any time by running
/scripts/restartsrv_apache_php_fpmredis-cli flushall
.
Comments
0 comments
Article is closed for comments.