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

Drupal – Run AJAX command after success of another JS command.

With ajax_command_invoke, I was getting error: Uncaught TypeError: Cannot read property ‘apply’ of undefined — ajax.js


After banging my head for like 4 hours with ajax_command_invoke, I am finally able to do it. Here is an example code.

Here is the full code.

Customizing a vagrant box

Recently, I got to know an excellent ready virtual machines solution known as Vagrant. The solution I was looking for was that I can create a custom virtual machine and install my development environment on that e.g. LAMP or MEAN so that new developers can easily download that machine and can start work on that straight away.

If we follow default vagrant instructions, we will end up having and Ubuntu virtual machine. My target was to have a Centos 7 machine with Apache, PHP and MySQL.

So I installed a basic Centos 7 virtual machine, the instructions are available on http://docs.vagrantup.com/v2/getting-started/boxes.html. Instead of “hashicorp/precise32”, I choose serveit/centos-7. After adding the box, I installed the required tools, now my machine is ready so it’s time to export my VM as a vagrant box, it is so simple:

We can package a box using command:

That’s it, the above command will will create a VM for virtual box. Now you can delete the existing box using:

Delete the Vagrantfile and can use this new box with the following command:

You can add your distribution to vagrant repo if you want.

Sails JS – Production mode Error: [$injector:unpr]

I just encountered another error and in production mode that angular JS controllers were not being loaded properly and I was getting the error like:

Error: [$injector:unpr] ...

To fix this, just change the declaration of your AngularJS controllers from


And it works like a charm.

Please comment if this solution solved your problem.

Sails JS security [DRAFT]

This is a checklist I am creating for myself to secure different areas of a SailsJS application I am developing these days.

For API security: https://github.com/lucj/sails-oauth2-api

For user authentication and thirdparty login: PassportJS


This was really important as sails by default allows CRUD operations with both GET and POST so to avoid CSRF I added the following path to the routs.js

I will keep adding more stuff so please feel free to comment if you think I missing something.