C4f1151075b447779af31e99d6cf70e2c6eb47ac
By:
newbie

how to Install Varnish on Ubuntu 14.04.1 LEMP

December 22, 2014 5k views

Hello,
i m running one wordpress site on 512 droplet. i want install varnish for my droplet and i believe i must do some extra things also so that varnish can cache my wordpress site efficiently. just like its described in the following tutorial
https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-nginx-php-and-varnish-on-ubuntu-12-04

now my questions are the following

Q1. How can i install varnish for my nginx server which is on ubuntu 14.04.1? i tried to follow the above tutorial which is for 12.04 but that didnt work. says not supported when i try to install varnish. maybe that procedure not supported anymore for 14.04.1 or maybe because that is for varnish v3.

Q2. Currently Opcache code is enabled and its set to following parameter
opcache.memoryconsumption=128
opcache.max
acceleratedfiles=4000
opcache.revalidate
freq=60

should i change them to default or keep them as it is? or i simply dont need Opcache anymore?

Q3. i need to add one sub-domain that will bypass varnish cache and hit directly to my nginx server which is on default port 80.

3 comments
  • At what point in the tutorial are you seeing the message that it is not supported?

  • @ryanpq
    when i follow that tutorial i get error at
    sudo apt-get install varnish libvarnish-dev

    from varnish support i followed new instruction to install varnish 4.0 which is for ubuntu 14.04 and then i was able to install varnish. then i followed again next parts of varnish configuration from the above tutorial and then i get this msg when i tried to start varnish.

    root@:~# sudo service varnish restart
     * Stopping HTTP accelerator varnishd                                    [fail]
     * Starting HTTP accelerator varnishd                                    [fail]
    Message from VCC-compiler:
    VCL sub's named 'vcl*' are reserved names.
    ('input' Line 18 Pos 5)
    sub vcl_fetch {
    ----#########--
    
    Valid vcl_* methods are:
            none
            vcl_recv
            vcl_pipe
            vcl_pass
            vcl_hash
            vcl_purge
            vcl_miss
            vcl_hit
            vcl_deliver
            vcl_synth
            vcl_backend_fetch
            vcl_backend_response
            vcl_backend_error
            vcl_init
            vcl_fini
    Running VCC-compiler failed, exited with 2
    
    VCL compilation failed
    
    
  • @newbie

    From Varnish documentation :

    1. " vclfetch is now vclbackend_response".
    2. "req.* not available in vclbackendresponse ! req.* used to be available in vclfetch, but after the split of functionality, you only have 'bereq.*' in vclbackend_response."

    So with varnish 4.0 the beginning of the default.vcl file should look like this:

    backend default {
        .host = "127.0.0.1";
        .port = "8080";
    }
    
    # Drop any cookies sent to Wordpress.
    sub vcl_recv {
            if (!(req.url ~ "wp-(login|admin)")) {
                    unset req.http.cookie;
            }
    }
    
    # Drop any cookies Wordpress tries to send back to the client.
    sub vcl_backend_response {
            if (!(bereq.url ~ "wp-(login|admin)")) {
                    unset beresp.http.set-cookie;
            }
    }
    

    After that Varnish started !

1 Answer

When I Google Install Varnish 4 on Ubuntu, the first result is on Varnish's website: https://www.varnish-cache.org/installation/ubuntu. It provides the commands to copy into terminal, and at the footer it mentions if you are installing on 14.04 rather than 12 to just change one word in the commands. Just make sure you sudo su into root first. Installed without any issues here on 14.04 running LEMP. If you use WordPress you will want to add the lines aristovia mentioned to your /etc/varnish/default.vcl file so that the WordPress admin works properly regardless of the version of Varnish. Hope this helps!

Have another answer? Share your knowledge.