azureprestashop

Configure Varnish (TM) for PrestaShop

NOTE: The steps below assume that PrestaShop is already running at the root URL of the server, such as at http://prestashop.example.com/, and that Varnish (TM) is enabled. Varnish (TM) is disabled by default, but you can enable it by following the instructions in our Varnish (TM) guide.

Download the different files used in the example:

Follow the steps below to configure PrestaShop with Varnish (TM):

  • Connect to the server via SSH.

  • Back up the original Varnish (TM) configuration file:

      $ sudo cp /opt/bitnami/varnish/etc/varnish/default.vcl /opt/bitnami/varnish/etc/varnish/default.vcl.backup
    
  • Add the PrestaShop-specific Varnish (TM) configuration by downloading the corresponding file and copying it to the correct location:

      $ sudo cp prestashop.vcl /opt/bitnami/varnish/etc/varnish/default.vcl
      $ sudo sed -i 's/port\s*=\s*"[^"]*"/port = "80"/g' /opt/bitnami/varnish/etc/varnish/default.vcl
    

Varnish (TM) and PrestaShop are now configured.

IMPORTANT: Varnish (TM) is connected to Apache locally so other applications like phpMyAdmin could become public. Find out how to block these applications.

Next, proceed to test and activate the Varnish (TM) service as described below:

  • Restart the Varnish (TM) service:

      $ sudo /opt/bitnami/ctlscript.sh restart varnish
    
  • Open port 81 in the server firewall. Refer to the FAQ for instructions.

  • Check if the website is being served properly by Varnish (TM) on port 81, by browsing to http://SERVER-IP:81.

  • If Varnish (TM) is working correctly, switch the Apache and Varnish (TM) ports and activate Varnish (TM) on port 80:

       $ cd /opt/bitnami
       $ sudo sed -i 's/^\s*Listen .*$/Listen 81/g' apache/conf/httpd.conf
       $ sudo sed -i 's/\:80/\:81/g' apache/conf/bitnami/bitnami.conf
       $ sudo sed -i 's/at port.*"/at port 81"/g' apache/scripts/ctl.sh
       $ sudo sed -i 's/=80/=81/g' properties.ini
       $ sudo sed -i 's/port\s*=\s*"[^"]*"/port = "81"/g' varnish/etc/varnish/default.vcl
       $ sudo sed -i 's/VARNISH_PORT=.*$/VARNISH_PORT=80/g' varnish/scripts/ctl.sh
    
  • Update the HTTP port used by PrestaShop, by running these commands:

      $ sudo sed -i 's/\:80/\:81/g' apache/conf/vhosts/prestashop-vhost.conf
    
  • Restart the services:

      $ sudo /opt/bitnami/ctlscript.sh restart
    
  • Remove the firewall rule added for port 81.

IMPORTANT: Varnish (TM) does not cache content if the Apache PageSpeed module is enabled. Find out how to disable this module.

Varnish is a registered trademark of Varnish Software AB and its affiliates.

Last modification February 9, 2023