Varnish on Magento 1

in Caching Tags: Cachemagento1performance

Customers with Magento Go Big and Excellence plans can use Varnish to boost their Magento shop. To manage and configure Varnish for Magento 1.x you’ll need Turpentine. This article explains how you can configure Varnish for your Hypernode.

Although varnish is extremely awesome when it get’s to speeding up websites, varnish is a complex technique that needs some experience to set it up. Don’t implement varnish on production nodes while still under development but use a development node or a hypernode vagrant instead.

Configure Varnish for Magento 1.x

Activate Varnish

Before installing Turpentine we recommend changing the Varnish Cache settings in your Service Panel to active (change to ‘Actief’). Once you’ve changed this setting and enabled Varnish in Magento, Varnish will store all information in it’s own cache. Only when Varnish needs data that hasn’t been cached it will connect with the server.

Install Turpentine

Installing Turpentine works best with Magento Connect Manager:

  • Log on to your backend
  • Navigate to System > Magento Connect > Magento Connect Manager
  • Fill in your admin credentials
  • Paste the following key in the field next to Paste extension key to install: http://connect20.magentocommerce.com/community/Nexcessnet_Turpentine
  • Install
  • Click Proceed
  • Turpentine will now be installed
  • Log off and on again so Turpentine will appear in your admin
  • Flush your Magento cache via the backend (System → Cache Management)

When the Magento Connect Manager is not available, turpentine needs to be installed by manually:

There are a couple of options for this:
* Download and install the tarball package from the Downloads page on GitHub (note that this is not the “Download as tar.gz” option) and install through Magento Connect Downloader or Magento’s mage command.
* Install with modman. You would just need to use: modman clone https://github.com/nexcess/magento-turpentine.git

Note: If you install with modman you should also set System > Configuration > Developer > Template Settings > Allow Symlinks to “Yes”.

Configure Turpentine

After installing Turpentine and flushing the Magento cache, you can start configuring Turpentine:

  • Log on to your Byte Service Panel
  • Select your Hypernode plan
  • Click on the tab Instellingen
  • Select the option Varnish
  • You’ll notice Varnish cache is non-active. This is necessary for testing your shop with Varnish. (See ‘Test your shop with Varnish’ below)
  • Don’t close this page, you’ll need this information later
  • Log on to your Magento backend
  • Navigate to System -> Configuration
  • Select Varnish Options under Turpentine
  • In the Servers section, fill in the following information:
    • Varnish version: leave this on ‘auto’
    • Varnish server list: Paste the content from your Service Panel here
    • Varnish authentication key: Paste the content from your Service Panel here
  • Select Caching Options under Turpentine
  • Check if the following information is correct:
    • Backend host: This should say varnish
    • Backend port: This should say 8080
    • Crawler ip’s: Remove localhost/127.0.0.1 from the crawler ip’s
  • Navigate to System -> Cache Management
  • Enable >Varnish Pages and >Varnish ESI Blocks
  • Click Apply Varnish Config below to complete the configuration

Test your shop with Varnish

We highly recommend you to test Varnish on a staging environment first. This way you’ll make sure your shop is completely optimized and ready to use Varnish.

There are 2 ways to create a Hypernode staging environment for testing Varnish;

We recommend you to use Vagrant. If by chance you can’t use Vagrant, choose cloning your shop to a second node. A basic staging environment doesn’t work well with Varnish.

Debugging headers

If you want debugging headers, please remember to enable those in the admin backend under Varnish settings.

varnish headers

Depending on the version of turpentine you use, sometimes it’s needed to add your ip to the debug_acl in the vcl. This enabled debug headers for your IP address.

Varnish with php7

The current stable release of the Turpentine varnish extension is compatible with php7.

Warm your cache with the turpentine cache-warmer script

Turpentine is shipped with a cache warmer. To use this script copy it to your home directory:

mkdir -p ~/bin; cp ~/public/.modman/magento-turpentine/util/warm-cache.sh ~/bin/

Now you can warm your varnish cache by retrieving the sitemap.xml:

~/bin/warm-cache.sh -u http://example.com/magento/sitemap.xml

Which will crawl all urls defined in the sitemap.xml:

app@gz20le-support-magweb-do:~$ bash ~/bin/warm-cache.sh -u https://example.com/sitemap.xml
Getting URLs from sitemap...
Warming 152 URLs using 2 processes...
HTTP/1.1 200 0.87 secs: 18320 bytes ==> /kamelen.html
HTTP/1.1 200 1.34 secs: 14710 bytes ==> /dromedarissen.html
HTTP/1.1 200 0.75 secs: 17726 bytes ==> /geiten.html
HTTP/1.1 200 0.74 secs: 17974 bytes ==> /tux.html
HTTP/1.1 200 0.79 secs: 14856 bytes ==> /vogelbekdier.html

0