Introduction
Magento generally is not known for the fastest one on the block but this has now changed. Starting from a couple years ago Magento suggested the use of Varnish on production for caching storage and it will significantly increase the speed of your Magento site.
Fastly in addition to its CDN and firewall capabilities, it also includes Varnish functionality. Fastly does mention that it uses Varnish as its core, so it’s basically an advanced and distributed Varnish server. Fastly accelerates the website speed with its CDN networks and caching storage. If Cloudflare is famous for its (free and) fast CDN, Fastly also integrates pretty well with Magento’s full page caching.
We know that Magento Commerce Cloud includes Fastly on its bundle, but now your self-hosted Magento Open source and Magento Commerce sites can also have Fastly. Read more to see how easy it is to configure Fastly for Magento Open Source / Commerce on-premise.
Requirements
Here are the things that you will need to integrate Fastly into self-hosted Magento:
- A running Magento 2.3 / 2.4 of Open Source / Commerce On-Premise edition with composer installed
- A basic understanding of Magento admin configuration (including cache cleaning)
- A registered account on https://www.fastly.com (we tested both free developer trial and paid accounts)
- A working Magento 2 Access Key https://marketplace.magento.com/customer/accessKeys/
- A Fastly Personal API Token with global scope: https://manage.fastly.com/account/personal/tokens
Extension installation
Installing Fastly’s Magento extension is a straightforward process. Just like any other Magento extensions, you can do the following steps:
- Go to https://marketplace.magento.com/fastly-magento2.html
- Select your magento version and checkout:
- Now login to your server and go to the root directory of your Magento
- Paste the access key in your auth.json file inside your magento install:
- Now execute sudo -u www-data composer require fastly/magento (see that I’m using sudo -u www-data to avoid messing with file permission)
- Clean magento cache with sudo -u www-data bin/magento cache:flush
Finished! Now you should be able to see Fastly module in Magento admin under Stores – Configuration – Advanced – System – Full Page Cache and you will have a new option called Fastly CDN under Caching Application:
Fastly basic configuration
In order to get your site served by Fastly, you will need to add a new Fastly service and a host. To create a new service, follow these steps:
- Login to your Fastly account
- Click on Create Service button right on the top right of your dashboard
- Insert the domain that you want to use then click Add
To create a new host, do the following:
- Click on Origins link on the left sidebar
- Insert the host IP address or the hostname, then click Add. Once you have the host configured, then you are ready to do the Magento extension configuration.
Magento extension settings
Once you’ve configured service and host on Fastly, you can go to Stores – Configuration – Advanced – System – Full Page Cache of your Magento admin and you will have a new option called Fastly CDN under Caching Application.
- Copy the service ID from your newly-created Fastly service to Fastly Service ID field
- Do the same thing for the Fastly API Token (described in the requirement section at the top of this article)
- Verify the details by clicking on Test credentials
- Save Config – Flush Magento cache
- After save, go back to the previous Fastly configuration, then click on Upload VCL to Fastly, tick on Activate VCL after upload, then click Upload
- Once again Save Config and Flush Magento cache
Fastly uses VCL for its service configuration. You can always write it by hand, but this Magento extension will do it for you. The only thing that you need to do is make sure to upload VCL after changing any Fastly Configuration.
At this point, Magento should be ready to work with Fastly but you won’t be able to test it until you update your DNS record as explained below.
DNS Configuration
Fastly acts as a proxy for your server. All web requests going to your domain will go through Fastly before actually reaching your server. This way, Fastly can apply firewalls, manipulate requests, filter traffic, and others. In order to do that, you will need to point the domain to Fastly hostname instead of your server directly.
Fastly has several different hostnames that you can choose depending on your SSL/TLS configuration and/or whether you choose to limit your traffic to a certain network. More details here: https://docs.fastly.com/en/guides/adding-cname-records#choosing-the-right-fastly-hostname-for-your-cname-record
Friendly warning reminder: once you change the DNS, it literally means the traffic will start flowing through the new Fastly service. If you are on production, make sure that everything is good before you switch the DNS.
In short, if you don’t want to use Fastly TLS, then use nonssl.global.fastly.net.
If you need to try Fastly TLS without paying anything, use [name].global.ssl.fastly.net.
And if you already enabled paid account and want to use fully-working fastly TLS, use j.sni.global.fastly.net or k.sni.global.fastly.net.
More details here: https://docs.fastly.com/en/guides/adding-cname-records#tls-enabled-hostnames
Please note that once you change the DNS, it might take some time for the whole internet to propagate your new domain configuration.
If everything goes well, you will be able to start seeing live traffic statistics on your Fastly dashboard. Also, don’t forget that your Magento site is now blazing fast!
Fastly X Magento overview
Overall, we love Fastly. We have been using Cloudflare for our clients and we will also offer Fastly integration for our clients soon. Fastly offers something that Cloudflare doesn’t: seamless Magento integration. Based on our test, Magento running Luma theme can be fully loaded in nearly the blink of an eye. Magento has never been this fast.
Using Fastly is also a timesaver rather than configuring and maintaining your own Varnish server. You probably need to pay at least USD 50 / month for a Fastly paid account while you can build a Varnish server under USD 10 / month, but remember the maintenance cost and all the hassle that you will need to do in the future.
That cost consideration also come in to play when you need to enable something like Image Optimizer. Fastly has it, too and we have confirmed that it is integrated with the Magento extension pretty well.
If you have a need for speed for your high-traffic Magento, go with Fastly. Contact us for assistance and we’re ready to help.