Centos, Varnish, NGINX, Drupal

As an experiment this week I decided to change the web server of a site to NGINX, the existing web server was Apache. I would like to share the steps required to setup NGINX with Varnish to make your Drupal site run at a blazing speed.
Centos 6
Quadcore processor.
Install NGINX
yum install nginx
Configure NGINX
Open /etc/nginx/nginx.conf
Add the following lines at the bottom of “http” block:

It will look something like:

Add host yoursitename.com
Create two directories sites-available and sites-enabled

Create a file named “yoursitename.com.conf” under sites-available and paste the following contents:

Please note that the port number is “81” as varnish will run at port 80 and will behave like content server.

Create a symlink and remove the default configuration:

Please note that default.conf’s location can be different based on different platforms.

Change owner of the web directory

Install Varnish

Configure Varnish

Open /etc/sysconfig/varnish, replace the following values:

Keep all other values as it is.

Open /etc/varnish/default.vcl and update “backend default” block to the following:

Install PHP FPM

I am also using php fpm for faster php processing. Here is the command for that, simple simple

Restart servers:

Configure Varnish with Drupal

Install Drupal’s varnish module
Add the following lines to your settings.php:

Go to varnish configuration: admin /config /development /varnish

Set Varnish control terminal:
Set Varnish Control key from/etc/varnish/secret
Please make sure the “Varnish running” is ticked.
Awesome, you are done. Enjoy the faster response times of your site.
Please comment if you have any feedback

Load masonry after all the images are loaded

The team decided to make the homepage of Biyixia.com like Pinterest or toptenreviews.com. Challenging, but thanks to the Masonry. Masonry was working absolutely fine on localhost but on the server it looks a bit messed up.

The reason was that on slow connections Masonry was being loaded before all images gets loaded in the browser so looked a bit messed up. So I loaded masonry in the following code:

And it worked like a charm. Here is the new biyixia.com homepage:

Screen Shot 2014-12-24 at 1.07.27 pm

Please feel free to share better solutions.

Drupal: Managing translations in a multisite environment.

Currently, I have been working on a complex Drupal project with around 400 subdomains and half a million nodes. All the subdomains have same codebase. The product is in Chinese language and my real issue was to translate the strings from English to Chinese but the problem was that if a string is translated in one subdomain, it has to be translated to other 399 subdomains as well, so I decided to use the translation table of one (parent) domain on all other subdomains. So I just added the following lines to the settings.php of all 400 domains:

$databases['default']['default']['prefix'] = array(
'default' => 'mysite_',
'locales_target' => 'parent_db.mysite_',
'locales_source' => 'parent_db.mysite_',

“parent_db” is the database of the parent subdomain. Now if you change the translation of any subdomain, it will use the table of “parent_db” and will be changed in all 400 subdomains.