Introduction
Adobe Commerce is Adobe’s flagship eCommerce platform that uses the LAMP(Linux Apache MariaDB/MySQL PHP) stack for its code base. The platform is designed to scale to hundreds of millions of SKUs while still remaining performant. In this tutorial I will be explaining how to optimize your Adobe Commerce website for a snappy user interface and high traffic loads.
Tools
In order to optimize your website you will need to have one or more of the following to see results.
- Varnish (Full page caching)
- Redis (session caching e.g. user carts and unsaved admin changes)
- Magento CLI (Used to configure the above)
Redis
Almost hosting providers will provide you with a Redis server to use with your hosting plan. If not you may be able to reach out to their support for this to be included in your plan. At PrivateerHosting Redis is always available to shared and dedicated web hosting plans. You will be able to upgrade your plan for larger cache sizes should you need it.
Before you configure your Redis server make sure you have the following: socket/ip, port, database id, and (optional) compression library.
Enable cache backend
SOCK="/run/redis/redis.sock"; # Replace this with IP if server is remote
COMP_LIB=snappy;
DB1=0; # Make sure these databases are not used by anything else
DB2=1;
DB3=2;
php bin/magento setup:config:set --cache-backend=redis --cache-backend-redis-server="${SOCK}" --cache-backend-redis-port="${PORT:-0}" --cache-backend-redis-db="${DB1}" --cache-backend-redis-compression-lib=${COMP_LIB}
Full page caching (skip if using Varnish)
php bin/magento setup:config:set --page-cache=redis --page-cache-redis-server="${SOCK}" --page-cache-redis-port="${PORT:-0}" --page-cache-redis-db="${DB2}" --page-cache-redis-compress-data=1 --page-cache-redis-compression-lib=${COMP_LIB}
Enable session caching
php bin/magento setup:config:set --session-save=redis --session-save-redis-host="${SOCK}" --session-save-redis-port="${PORT:-0}" --session-save-redis-db="${DB3}" --session-save-redis-log-level=4 --session-save-redis-max-concurrency=20 --session-save-redis-compression-lib=${COMP_LIB}
# Flush cache to begin using Redis
php bin/magento cache:flush
At this point Redis is configured and you should be seeing significant improvements to the responsiveness of your website.
Varnish
Varnish cache is an engine that runs as a proxy in front of your website to serve content from memory. Adobe Commerce has built in support to manage Varnish caching so that changes are shown quickly. To setup Varnish caching you will need your hosting provider to place Varnish in between the user and your web server. In a future article I will explain further how you can configure this for yourself. Begin by getting your Varnish server’s IP or FQDN (fully qualified domain name) and the port that it is running on. In this case we will be assuming Varnish is running on the same server as your website on port 8080.
HOST=localhost;
PORT=8080;
php bin/magento config:set system/full_page_cache/varnish/backend_host $HOST;
php bin/magento config:set system/full_page_cache/varnish/backend_port $PORT;
php bin/magento config:set system/full_page_cache/caching_application 2;
php bin/magento setup:config:set --http-cache-hosts=$HOST:$PORT;
php bin/magento cache:flush;
Now that it is configured you can check if Varnish is working by running the following command. You should see HIT if the page is properly cached.
curl -Il https://yoursite.com | grep -i cache
X-Cache: HIT
Conclusion
Now you have maximized the caching options available to your eCommerce website. In the future you may want to include OpenSearch to speed up product searching. In a later article we will explore this in more detail.