After working on it for many hours again, I managed to make it work. But I had to comment the SuexecUserGroup line in /etc/apache2/vhost.d/shekhar.conf file.
I also uncommented the <FilesMatch > element in mod_fcgid.conf file.
Now, if I have a file.php, it works. works with https too. But If i rename it to a .cgi file, it just downloads the file. What should I do so that it knows the cgi extension?