How to get LiveReload working with Vagrant and auto compile scss files from shared folder

Last few days are amazing. Learning so many things, especially setup of Vagrant in our company. I had few issues with the performance of Drupal running on Vagrant on windows host which I fixed yesterday. That was one milestone achieved but I didn't realized that there would be more obstacles.

We started using Omega 4 for all of our projects now and it is great. Especially compass support of SASS that enables us to design great websites in short time. The only problem is that it is not smooth to setup. If you read the Omega 4 documentation you will come to know that they have clear instructions on how to setup this stuff. I will not cover that in this blog. It is already well documented and there are plenty of articles on the internet.

I did all the setup for Omega 4 but the problem was that Live Reloading was not working and the .scss files were not compiling automatically whenever there are some changes done in them.

My current setup is Vagrant running on Windows 8.1, and guest OS is CentOS 6.5

Steps to get Live Reload working

First make sure that live reload is enabled in Drupal Omega 4 settings. Go to your Omega subtheme settings, under Development tab check the "Enable Development extension" and then under it check "Enable LiveReload". Here you would notice that LiveReload server uses port 35729. We will use it just now in the next step.

Changes in the Guardfile

You will find the Guardfile under the root of your subtheme directory. Edit it and do the following changes. We need to mention the ip address as 0.0.0.0 (I am not sure about the purpose) and the port number here.

guard :livereload , :host=> '0.0.0.0', :port=> '35729' do
   watch(%r{^((?!\.normalize\.).)*\.(css|js)$})
end

Now enable the Port Forwarding in Vagrantfile

Add the following line to forward 35729 port from guest to host.

config.vm.network "forwarded_port", guest: 35729, host: 35729

These are the changes I did and it took me 5 hours to figure out after lot of researching and hopefully this will work for you as well. Provided you are using the same environment as I am. At this moment just reload your Vagrant and try whether LiveReloading works or not.

Changes in .scss file are not detected from Windows Share, but there is a work around

I am still stuck here. If I make changes directly in CentOS VirtualBox then Guard picks up the changes immediately and .scss files are compiled when I make the changes through windows then it won't. I tried few methods but didn't succeed yet but there is a workaround which works fine.

Trick is to force the polling

bundle exec guard -p -l 10

The only problem with this force polling is that it is not super fast. You have to wait for few seconds for Guard compile the .scss files, but I am still ok with it. At least it is not blocking issues.

So far loving working with Vagrant. Lovely.

How to speed up Drupal running in Vagrant on Windows Host

I recently install and setup Vagrant on my Windows laptop. The only reason I used Windows on my laptop is because of the trainings I conduct. Most companies use Windows based systems and it is difficult to train them if you are showing demos on Linux and they have to repeat the same on Windows. For that reason only I used Windows. When I am not providing training, I am usually developing stuff. Mostly on Drupal and most recently on JIRA Plugins (Yes I am learning Java).

I heard about Vagrant in the past but never really had enough space to try it out. Recently I decided to not take usuall Drupal projects and will only work with smart clients who are willing to pay for the service and quality. That decision is costing me money, as I don't do lot of work now but I am happy with the peace on mind. This gives me with some extra time which I now devote in learning new things and improving processes in my company. When you are on your own, you need to spend your time wisely. Free time means opportunity to learn new stuff.

I was happy to understand the whole workflow of Vagrant and quite like it actually. Everything went fine. Installed CentOS 6.5 using Vagrant and setup LAMP on it. I even installed a blank Drupal site just to test it out. It worked fine too. I even created a package and moved this customized CentOS box to another machine and it worked perfectly too. I loved this idea to have exact same development environment. I will now ask everyone in the team to use this box.

So far it was great, until I actually cloned one of our complex Drupal project which we have to deliver in few days. That site was running horribly slow. I came to know that the performance can be increased if we enable NFS for file sharing but unfortunately NFS is not supported on windows.

So I searched a lot on google for possible improvements. I mean Vagrant can be installed on Windows but just because of this NFS issue it is impossible to use it for LAMP. Finally I found we tricks, which I applied and it really improved the performance. Not great but atleast usable.

Install the following Vagrant plugin in your host, Windows in my case.
Someone has written this plugin to enable NFS on Windows. I found this after searching a lot on google.

vagrant plugin install vagrant-winnfsd

Now enable the root of your project folder with /vagrant folder where I keep my website files. This could be any directory on your setup. don't forget to enable NFS by using type: "nfs"

Do the following change in your Vagrantfile.

config.vm.synced_folder ".", "/vagrant", type: "nfs"

I realised that increasing the memory also has positive effects on the performance.

Also increase the memory of your virtual machine. I have 8 GB of RAM so I can afford to allocate 3GB to my virtual machine.

config.vm.provider "virtualbox" do |vb|
    vb.customize ["modifyvm", :id, "--memory", "3000"]
end

Lastly some tweaks in the Apache configuration file for some extra improvements.

Finally do the following change in your httpd.conf file

<IfModule prefork.c>
StartServers       2
MinSpareServers    6
MaxSpareServers   4
ServerLimit      4
MaxClients       4
MaxRequestsPerChild  3000
</IfModule>

These are some of the things that I tried, I cannot guarantee that it will help you too, but there is not harm in trying. It might work for you.

Have fun!

How to install VirtualBox on Fedora 20

For the past few days I am trying to setup Vagrant for uniform development environment in our company, personall I work on Windows 8.1, iMac, Fedora for development and our servers are running CentOS. It is pain I know.

Last weekend I installed and understood Vagrant on windows 8.1, it was great. I will not get into the details on setup here. You can check the documentation on their website.

Today I cloned my Vagrant box, which I want to duplicate on my fedora machine. So for that I need to install VirtualBox first on Fedora 20. It is not as simple as yum install VirtualBox, it requires some effort. Here are the steps.

Step 1: Add the VirtualBox .repo

su -
cd /etc/yum.repos.d/
wget http://download.virtualbox.org/virtualbox/rpm/fedora/virtualbox.repo

Step 2: Update your system

sudo yum update

Step 3: Install the required packages

yum install binutils gcc make patch libgomp glibc-headers glibc-devel kernel-headers kernel-devel dkms

Step 4: Install VirtualBox

sudo yum install VirtualBox-4.3

Step 5: Build modules

/etc/init.d/vboxdrv setup

Step 6: Add the user in vboxusers group

sudo usermod -a -G vboxusers YOUR_USERNAME

Installation complete. Now I will install Vagrant on Fedora 20. Have fun.

How to use Emacs & Org-mode on multiple computers with same settings

I am a big fan of Emacs. I am not saying it is the best editor but I feel it is light weight, yet powerful and it can be customized easily. Of course vi is equally good. It is just a matter of personal taste. I also now rely heavily on Org-mode for storing all my tasks, random thoughts and to-do in org files which is I feel by far the best to-do tool. Calling it a to-do tool is actually understatement. It can do lot more. If you need to remember something with dates, estimates, tracking then org-mode can handle it pretty well. It is fast and super powerful.

The only thing missing is the syncing. If you are like me then working on multiple computers without your tasks in hand could be difficult. Org files are just text files and it is upto you to make it portable and sync with other computers.

Here is what I did to make my org-files portable.

1. I have a folder called c:\emacs that contains the following
.emacs -> init file
emacs.d/ -> folder containing all the modes, .el files
org-mode/ -> folder containing org-files

2. By default if you run emacs it will load the init file from the current user's Home directory, but we want emacs to load init file from c:\emacs\ directory. For this I have written a batch file in windows to change the HOME variable and then load emacs.

set HOME=c:\emacs
C:\softwares\windows\emacs-24.3-bin-i386\emacs-24.3\bin\runemacs.exe %*

3. Now I run this batch file to launch emacs which considers c:\emacs as the home directory.

Neat!

Now I have this folder c:\emacs which I commit and push to Git repository regularly.

But how to sync?

Ideally the commits to happen automatically after every 1 hour or so and changes should be pushed to server regularly too. So I am going to setup the following stuff and also share with everyone.

1. Auto commit files to git.
2. Issue a push on post-commit or may be few times a day using scheduler or cron.
3. Auto pull files on new computer when it is booted up for the first time.

(After implementing I will make these links)

Technically this is not sync in real sense but it is more like making your files portable and available to you as and when you need it.

2014 Half Year Update

More than half of 2014 has passed away and today it is 1st August. Today is my mother's birthday and also starting August it is festival time. Rakhi is next week, then Independence Day, next month is my birthday, then Dusshera, Diwali an so on. Really looking forward to next few months.

I am happy. There is a reason. My company Sparxsys is doing really well, especially the way I planned. We are by far the best JIRA Training provider in India right now. I don't think any other institute or organization who is into JIRA training can match our quality and experience. That is one. Second we are also one of the leading Drupal training provider in NCR. On an average I receive atleast 10-15 Drupal training requirements every week and around 5 JIRA training leads. Lastly we have some really amazing Drupal development projects lined up.

At our company we are now selective with work, we don't accept boring work just for the sake of money. We prefer working with smart clients who are willing to pay for the quality. Though our rates are still affordable and we charge less than our counter parts.

I am sure Sparxsys is on its way to become the number 1 Drupal and JIRA Consultancy firm in India.

We are planning to focus more on trainings and building products now. Recently we did some changes in the company that was difficult for me but it was necessary. I recently read Lean startup book that talks about continuously monitoring your progress and pivoting as and when necessary. The decisions I took in last few months were little difficult but now I feel that it really helped me to get more focus on things that matter the most and bring maximum value.

BTW I am also receiving some job offers :) really tempting offers but you know it is not easy to give up your dream. I recently started writing a daily journal where I summarize daily stuff in few paragraphs. It is good to write regularly, it really clears up the confusion in the mind and I think everyone should write journals.

It is 8:30 PM and I can hardly focus and write well, so winding up now.

Good Bye.

Pages

Subscribe to Ravi Sagar RSS