Configure Varnish for PrestaShop

Before running the commands shown on this page, you should load the Bitnami stack environment by executing the installdir/use_APPNAME script (Linux and Mac OS X) or by clicking the shortcut in the Start Menu under “Start -> Bitnami APPNAME Stack -> Application console” (Windows). Learn more.

NOTE: The steps below assume that PrestaShop is configured to run at the root of the domain.

Follow the steps below to configure PrestaShop with Varnish:

  • Connect to the server via SSH.

  • Start the Varnish service on port 81 by executing the following commands:

    $ sudo mv installdir/varnish/scripts/ installdir/varnish/scripts/
    $ sudo installdir/ start varnish
  • Back up the original Varnish configuration file:

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

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

Varnish and PrestaShop are now configured.

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

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

  • Restart the Varnish service:

    $ sudo installdir/ 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 on port 81, by browsing to http://localhost:81.

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

     $ cd installdir
     $ sudo sed -i 's/^\s*Listen .*$/Listen 81/g' apache2/conf/httpd.conf
     $ sudo sed -i 's/\:80/\:81/g' apache2/conf/bitnami/bitnami.conf
     $ sudo sed -i 's/at port.*"/at port 81"/g' apache2/scripts/
     $ sudo sed -i 's/\:80/\:81/g' apps/*/conf/httpd-vhosts.conf
     $ 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/
  • Restart the services:

    $ sudo installdir/ restart
  • Remove the firewall rule added for port 81.

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

IMPORTANT: If using bnconfig, set the server port to 80 or 8080 before running it, then change it back to 81 or 8081 after, as shown below:

$ sudo sed -i 's/=81/=80/g' properties.ini
$ sudo apps/APPNAME/bnconfig --option parameter
$ sudo sed -i 's/=80/=81/g' properties.ini
$ sudo installdir/ restart
Last modification December 31, 2018