nativeInstallerprestashop

Configure Varnish (TM) 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 MacOS) or by clicking the shortcut in the Start Menu under “Start -> Bitnami APPNAME Stack -> Application console” (Windows). On OS X VMs, the installation directory is /opt/bitnami and OS X VM users can click the “Open Terminal” button to run commands. Learn more about the Bitnami stack environment and about OS X VMs.

NOTE: We are in the process of modifying the file structure and configuration for many Bitnami stacks. On account of these changes, the file paths stated in this guide may change depending on whether your Bitnami stack uses native Linux system packages (Approach A), or if it is a self-contained installation (Approach B). To identify your Bitnami installation type and what approach to follow, run the command below:

 $ test ! -f "installdir/common/bin/openssl" && echo "Approach A: Using system packages." || echo "Approach B: Self-contained installation."

The output of the command indicates which approach (A or B) is used by the installation, and will allow you to identify the paths, configuration and commands to use in this guide. Refer to the FAQ for more information on these changes.


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 ™ is enabled. Varnish ™ is disabled by default, but you can enable it by following the instructions in our Varnish ™ guide.

Download the different files used in the example:

Follow the steps below to configure PrestaShop with Varnish ™:

  • Connect to the server via SSH.

  • 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.vcl 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/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 ™ 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/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 depending on your installation type:

    • Approach A (Bitnami installations using system packages):

      $ sudo sed -i 's/\:80/\:81/g' apache/conf/vhosts/prestashop-vhost.conf
      
    • Approach B (Self-contained Bitnami installations):

      $ sudo sed -i 's/\:80/\:81/g' apps/*/conf/httpd-vhosts.conf
      
  • Restart the services:

    $ sudo installdir/ctlscript.sh 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.

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

Last modification September 28, 2020