Home » Categories » Multiple Categories |
How To Configure Varnish for Drupal with Apache on Debian and Ubuntu |
Article Number: 246 | Rating: Unrated | Last Updated: Thu, Jan 2, 2014 at 3:44 AM
|
Drupal is an open-source content management framework and platform written in PHP. Used for building rich, back-end based solutions for websites of any size and web applications alike, it is massively popular with extremely high statistics of adoption rates. Its distribution under the GNU General Public License means that anyone is free to use the software, contribute to the project in various ways and share it with others. The main distribution of Drupal is called Drupal Core and as of October 2013, it is expandable with over 20 thousand modules and almost 2 thousand themes. Taking advantage of platforms like Drupal to quickly prototype and develop applications is great. However, just as quickly, issues such as tackling growth of your product start to arise. This will require you to scale rapidly to continue to serve your customers fast, in order to keep their interest in your product and to maintain their happiness. In this article in a series tohelp developers with scaling, we will be talking about configuring Varnish with Drupal to greatly reduce the amount of time it takes users to load your Drupal based website and increase the simultaneous serving capacity by passing requests through the Varnish Cache software first. ScalingWhen talking about scaling in terms of software, what people usually mean is [a system's] ability to handle and accommodate a larger-than-its-built-for amount of work (which is to be processed) and data *which is to be kept and used in real-time or later). Regarding networks, the definition and identification of the issue gets simpler, despite a thorough solution usually being more costly to implement as it can require further incorporation of hardware to the system. The two most common approaches of scaling a webpage (or a web application) are: Vertical and/or Horizontal scaling. Vertical Scaling (Scaling Up!)Simply put, Vertical Scaling means increasing the resources of that one, single computer which is our server or of any of the computers forming our system as a whole vertically, by adding more resources to them or increasing their capacity. Adding more memory, replacing the CPU with a faster one, getting higher capacity and faster drives with excellent read-write speeds can all be considered as Vertical Scaling. Sometimes, this is also called Scaling Up. Horizontal Scaling (Scaling Out!)When we decide to take advantage of excellent low pricing of today's private servers and decide to incorporate more of them in our system, it is called Horizontal Scaling, or Scaling Out. This could happen in a variety of ways, such as running each software of our application stack on its own machine or cloning the web servers to create several others of the same and distributing incoming requests from clients across them by making use of a reverse proxy, such as NGINX. For more information on reverse proxies visit http://en.wikipedia.org/wiki/Reverse_Proxy. VarnishSitting in front of your website, Varnish Cache deals with serving static or quasi-static content directly, without passing the request back to the web server (i.e. Apache) to process over and over again. Since a lot of content (despite the amount of time they will be accessed) needs to be computed and generated only once, storing and then serving them from the fast access memory greatly reduces the load bore by the web server and increases the amount of requests that can be simultaneously handled by our system as a whole. How CanVarnish Help?Using Varnish in (almost) any web site means a faster web site by multitudes of force (depending on the architecture, of course!). It also means a more reliable product (for reasons you will see during configuration) thanks to the extended functionality of Varnish Cache. All this translates to happier customers who enjoy using your product more and a system that you can better count on to deliver. To Note: Unless we use a separate application server instance for Varnish (which we should, for manygood reasons!) this is technically not scaling (neither up, nor out), but having a good system architecture and basically being smart. However, due to the increase of load that can be handled by a single server, this could be referred to as scaling in some ways, as we are going to have much better overall performance from our system. This is really the result expected from scaling, and we end up with a system architecture that is ready to truly scale if necessary; however, it must be noted that better performance alone does not mean scaling. 1. Preparing Your Web Server for VarnishIn this article, our goal is to set up Varnish to serve pages quickly, directly from the memory. This is called caching and for this to work, Varnish needs to be able to handle the incoming requests first. Given that your web server (ex. Apache) is set for doing the exact same thing (handling incoming requests), we need to make some modifications for Varnish to take its place. The way to achieve this is to modify the port it listens to (i.e. port 80). Modifying ApacheBy default, Apache runs on (listens to) port 80 and we need to modify that. Modifying Apache's settings on ports.conf: The port setting we need to modify is defined in a file called Let's modify that using a text editor. We will be working withnano here, which is known for its user friendliness compared to some others. Run the following command to open the editor to edit the contents of ports.conf file:
Inside this file (by default) you should see something similar to:
So go ahead and modify the first two lines where the port number is specified, from its original to, say, 8000 (and remember this number):
Now in order to save and close, press If you also have _Virtual Host(vhost) Configurations_ In case you are hosting multiple websites (or have domain specific options set), you are likely to haveVirtual Hostconfigurations which we need to update as well. Run the following command to open the editor to edit the settings for your site:
!! Do not forget to replace my-domain-dot-com with the appropriate name. !! If you do not have custom named Virtual Host configurations, you can find the default settings on Depending on your current settings, you will see a document, beginning with (or containing) something like the following:
Which we now need to replace withsame port from ports.conf:
Close and save the file by pressing In order to bring changes to effect, we need to restart Apache:
As of now, Apache will accept incoming requests on the new set port of 8000. 2. Installing Varnish CacheFor Debian and Ubuntu:Setting up Varnish on Debian and Ubuntu is quite simple, as it is distributed with default system package manager:apt. However, the recommended way, in order to ensure that we are getting the latest version, is as follows (ref. https://www.varnish-cache.org/installation/debian): We need to add download URL for Varnish to aptitude package manager's sources list. In order to verify the source, we first need to add the security key provided by http://repo.varnish-cache.org. Let's begin with adding the security key [Debian and Ubuntu]:
Now add the package URL to apt-get repository sources list. Debian:
Ubuntu:
Finally, let's update the package manager and download/install Varnish Cache [Debian and Ubuntu]
3. Modifying Varnish's SettingsAfter having Apache's port modified and Varnish installed, we are ready to continue with modifying the settings of Varnish in order for it to behave the way we need it to. Putting Varnish into Production ModAs one of the reasons of enabling administrators to test Varnish upon installation, the default settings arenotset to run on front-facing port of 80, and we need to change that. The configuration file on Debian and Ubuntu reside at Open the editor to edit the file:
Upon running this command, you will be faced with a rather long but self-explanatory document. If you scroll down, you will see a block of text defining the Varnish daemon options starting with the text DAEMON_OPTS, similar to:
Let's modify it to change the port from 6081 to 80:
VCL Language and FileVarnish uses a Modifying the Default VCL File under |
Attachments
There are no attachments for this article.
|
How To Create Nagios Plugins With PHP On Ubuntu 12.10
Viewed 2354 times since Sat, Jan 4, 2014
How To Install Opigno on Debian 7 with Git and Drush
Viewed 3816 times since Sat, Jan 4, 2014
How To Create and Manage Databases in MySQL and MariaDB on a Cloud Server
Viewed 2815 times since Thu, Dec 26, 2013
How To Use HAProxy to Set Up MySQL Load Balancing
Viewed 8195 times since Thu, Dec 26, 2013
How To Create An Off-Site Backup Of Your Site With Rsync On Centos 6
Viewed 5778 times since Sat, Jan 4, 2014
How to Install Piwik on an Ubuntu 12.04 Cloud Server
Viewed 3209 times since Sat, Jan 4, 2014
How To Install and Secure phpMyAdmin on Debian 7
Viewed 3681 times since Fri, Dec 27, 2013
How To Import and Export Databases and Reset a Root Password in MySQL
Viewed 2893 times since Thu, Dec 26, 2013
How To Perform Basic Queries in MySQL and MariaDB on a Cloud Server
Viewed 2257 times since Thu, Jan 2, 2014
How To Install (LEMP) nginx, MySQL, PHP stack on Arch Linux
Viewed 13592 times since Sun, Dec 29, 2013
|