Tuesday, October 29, 2013

Deploy rails application in apache2 server using passenger

Summary:
-------
In ubuntu create virtual server and deploy rails application using passenger and apache server

Step 1:
-------
Make sure apache is installed and it work on ubuntu properly. Check it in browser.

http://localhost

It should display  "It Works!"


Step 2:
-------
Install passenger gem on ubuntu

$ gem install passenger


Step 3:
-------
Install passenger apache module.

$ sudo passenger-install-apache2-module


Step 4:
-------
We need to install require module for apache passenger

Step 5:
-------
After installation we need to add the passenger ruby modules at apache config file.

$ sudo subl /etc/apache2/apache2.conf

At last you need to add this lines

LoadModule passenger_module /home/kannan/.rvm/gems/ruby-1.9.3-p374/gems/passenger-4.0.21/buildout/apache2/mod_passenger.so
PassengerRoot /home/kannan/.rvm/gems/ruby-1.9.3-p374/gems/passenger-4.0.21
PassengerDefaultRuby /home/kannan/.rvm/wrappers/ruby-1.9.3-p374/ruby

Step 6:
-------
Create default sites enabled file and pase this code

$ sudo touch /etc/apache2/sites-enabled/railsproject.local

Suppose you have a Rails application in /somewhere. Add a virtual host to your
Apache configuration file and set its DocumentRoot to /somewhere/public:

eg. somewhere-> /var/www/railsproject


  #railsproject.local

   NameVirtualHost *:80
   <VirtualHost *:80>
      ServerName www.railsproject.local
      # !!! Be sure to point DocumentRoot to 'public'!
      DocumentRoot /somewhere/public   
      <Directory /somewhere/public>
         # This relaxes Apache security settings.
         AllowOverride all
         # MultiViews must be turned off.
         Options -MultiViews
      </Directory>
   </VirtualHost>

Step 7:
-------
Open hosts file and add the local ip of your application

$ subl /etc/hosts

Add last you need to add

127.0.0.1    railsproject.local


Step 8:
-------
Restart your apache2 server

$ sudo service apache2 restart


Step 9:
-------
check your virtula hosted project domain

www.railsproject.local


Rocks!!!!

An error occurred while installing nokogiri

Summary:
--------
During bundle install nokogiri shows some errors. we need to install associated packages for nokogiri gem

Step 1:
-------
Install associated packages

$ sudo apt-get install libxslt-dev libxml2-dev

Step 2:
-------
Now start the bundle install

Gem install pg error

Summary:
--------
Install pg without any installation errors

Step 1:
-------
Before install 'pg' Gem we need to install the following dependency package

$ sudo apt-get     install libpq-dev

Step 2:
-------
Install 'pg' gem

$ gem install pg

Generate RSA private/public key in ubuntu

Summary:
--------
Generate RSA private and public key  on ubuntu from ssh.

Step 1:
-------
open terminal enter the following command

$  ssh-keygen -t rsa


Step 2:
-------
It will ask some passphrase we can add if require more secure key


Step 3:
-------
You can view your system public key

$ cat ~/.ssh/id_rsa.pub

Install gem without ri-documentaions

Summary:
-------
During Gem installation skip the ri and Rdoc installation process; Create a .gemrc file from home directory and paste the following code and save.

Step 1:
-------
Open terminal create .gemrc

$ touch .gemrc

Step 2:
-------
Add the following line in that file , then save and close the file. Start install gem without any RDocs

gem: --no-ri --no-rdoc


Install postgreSQL on ubuntu

Summary:
--------
Install postgreSQL database on ubuntu system

Step 1:
-------
Update your system.

$ sudo apt-get update

Step 2:
-------
Install postgresql and associated packages

$ sudo apt-get install postgresql postgresql-contrib


Step 3:
-------
We need to stop Postgres server.

$ sudo service postgresql stop

Step 4:
-------
Navigate postgres user. Change PostgreSQL root user password.

$ sudo su postgres
$ psql


postgres=#  ALTER USER postgres WITH PASSWORD 'Passw0rd';
postgres=# \q


Step 5:
-------
We need to set the access permission  as trust to root user. The default access is md5. Open pg_hba.conf file

$ sudo subl /etc/postgresql/9.1/main/pg_hba.conf

Make sure the following commands

# Database administrative login by Unix domain socket
local   all             postgres                                trust

Step 6:
------
We must restart the postgresql

$ sudo service postgresql restart

"RVM is not a function"?

Summary:
-------
Make sure RVM should be a function.

Step 1:
-------
After installation of rvm. We need to add the add the following source to .baserc file.

$ gedit  ~/.bashrc

Step 2:
-------
Add the following line at the end of file

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

save and close the file

Step 3:
-------
check rvm is a funtion

$ type rvm | head -n 1

Could not reliably determine the server's fully qualified domain name?

Summary:
----------------
apache 2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

Step 1:
-----------
We need to configure localhost as a server name in apache2 httpd file

$ sudo subl /etc/apache2/httpd.conf

Step 2:
-----------
Add the following command and save the file

$ ServerName localhost


Step 3:
-----------
Restart the apache2 server

$ sudo service apache2 restart

Monday, October 28, 2013

Use Gmail SMTP on Ubuntu



Summary:
--------
We can use Gmail account as a free SMTP server on your Ubuntu system. The configuration as following steps

Step 1:
-------
Install postfix and associated packages

$ sudo apt-get install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules


Step 2:
-------
Open your postfix config file:

vim /etc/postfix/main.cf

add the following command

relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes

Step 3:
-------
Configure gmail username and password

open sasl_passwd file or create

$ vim /etc/postfix/sasl_passwd

Add the  username and password

[smtp.gmail.com]:587    USERNAME@gmail.com:PASSWORD


Step 4:
-------
Apply permission for the created file

sudo chmod 400 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd


Step 5:
-------
Create certificate file for authenticate

$ cat /etc/ssl/certs/Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem

Step 6:
-------
Reload the postfix server

$ sudo /etc/init.d/postfix reload

Step 7:
-------
Check mail weather its sending or not

$ echo "Test mail from postfix" | mail -s "Test Postfix" you@example.com

Add SSL on Apache for Ubuntu


Summary:
------------
Add and configure SSL certificate on  Apache for Ubuntu system using the following system.

Step 1:
-------
First enable SSL for your ubuntu

$ sudo a2enmod ssl

Step 2:
-------
Restart your apache2 server

$ sudo service apache2 restart

Step 3:
-------
Create a SSl folder at apache2

$ sudo mkdir /etc/apache2/ssl

Step 4:
-------
Generate private/public keys for security purpose. Enter the below command and add related key information.

$ sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt

Step 5:
-------
Now configure default SSl file

$ nano /etc/apache2/sites-available/default-ssl

#Add the server name

ServerName appname.com:443

#Add the ssl file location

SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key

Step 6:
-------
Enable the virtual host default

$ sudo a2ensite default

Step 7:
-------
Restart the apache2

$ sudo service apache2 restart

Sunday, October 27, 2013

How to be Become a Better Leader

Summary:
-------------
Being likeable will help you in your job, business, relationships, and life. I interviewed dozens of successful business leaders for my last book, to determine what made them so likeable and their companies so successful. All of the concepts are simple, and yet, perhaps in the name of revenues or the bottom line, we often lose sight of the simple things - things that not only make us human, but can actually help us become more successful. Below are the eleven most important principles to integrate to become a better leader:

1. Listening
"When people talk, listen completely. Most people never listen." - Ernest Hemingway
Listening is the foundation of any good relationship. Great leaders listen to what their customers and prospects want and need, and they listen to the challenges those customers face. They listen to colleagues and are open to new ideas. They listen to shareholders, investors, and competitors. Here's why the best CEO's listen more.

2. Storytelling
"Storytelling is the most powerful way to put ideas into the world today." -Robert McAfee Brown
After listening, leaders need to tell great stories in order to sell their products, but more important, in order to sell their ideas. Storytelling is what captivates people and drives them to take action. Whether you're telling a story to one prospect over lunch, a boardroom full of people, or thousands of people through an online video - storytelling wins customers.

3. Authenticity
"I had no idea that being your authentic self could make me as rich as I've become. If I had, I'd have done it a lot earlier." -Oprah Winfrey
Great leaders are who they say they are, and they have integrity beyond compare. Vulnerability and humility are hallmarks of the authentic leader and create a positive, attractive energy. Customers, employees, and media all want to help an authentic person to succeed. There used to be a divide between one’s public self and private self, but the social internet has blurred that line. Tomorrow's leaders are transparent about who they are online, merging their personal and professional lives together.

 4. Transparency
"As a small businessperson, you have no greater leverage than the truth." -John Whittier
There is nowhere to hide anymore, and businesspeople who attempt to keep secrets will eventually be exposed. Openness and honesty lead to happier staff and customers and colleagues. More important, transparency makes it a lot easier to sleep at night - unworried about what you said to whom, a happier leader is a more productive one.

5. Team Playing
"Individuals play the game, but teams beat the odds." -SEAL Team Saying
No matter how small your organization, you interact with others every day. Letting others shine, encouraging innovative ideas, practicing humility, and following other rules for working in teams will help you become a more likeable leader. You’ll need a culture of success within your organization, one that includes out-of-the-box thinking.

6. Responsiveness
"Life is 10% what happens to you and 90% how you react to it." -Charles Swindoll
The best leaders are responsive to their customers, staff, investors, and prospects. Every stakeholder today is a potential viral sparkplug, for better or for worse, and the winning leader is one who recognizes this and insists upon a culture of responsiveness. Whether the communication is email, voice mail, a note or a a tweet, responding shows you care and gives your customers and colleagues a say, allowing them to make a positive impact on the organization.

7. Adaptability
"When you're finished changing, you're finished." -Ben Franklin
There has never been a faster-changing marketplace than the one we live in today. Leaders must be flexible in managing changing opportunities and challenges and nimble enough to pivot at the right moment. Stubbornness is no longer desirable to most organizations. Instead, humility and the willingness to adapt mark a great leader.

8. Passion
"The only way to do great work is to love the work you do." -Steve Jobs
Those who love what they do don’t have to work a day in their lives. People who are able to bring passion to their business have a remarkable advantage, as that passion is contagious to customers and colleagues alike. Finding and increasing your passion will absolutely affect your bottom line.

9. Surprise and Delight
"A true leader always keeps an element of surprise up his sleeve, which others cannot grasp but which keeps his public excited and breathless." -Charles de Gaulle
Most people like surprises in their day-to-day lives. Likeable leaders underpromise and overdeliver, assuring that customers and staff are surprised in a positive way. There are a plethora of ways to surprise without spending extra money - a smile, We all like to be delighted — surprise and delight create incredible word-of-mouth marketing opportunities.

10. Simplicity
"Less isn't more; just enough is more." -Milton Glaser
The world is more complex than ever before, and yet what customers often respond to best is simplicity — in design, form, and function. Taking complex projects, challenges, and ideas and distilling them to their simplest components allows customers, staff, and other stakeholders to better understand and buy into your vision. We humans all crave simplicity, and so today's leader must be focused and deliver simplicity.

11. Gratefulness
"I would maintain that thanks are the highest form of thought, and that gratitude is happiness doubled by wonder." -Gilbert Chesterton
Likeable leaders are ever grateful for the people who contribute to their opportunities and success. Being appreciative and saying thank you to mentors, customers, colleagues, and other stakeholders keeps leaders humble, appreciated, and well received. It also makes you feel great! Donor's Choose studied the value of a hand-written thank-you note, and actually found donors were 38% more likely to give a 2nd time if they got a hand-written note!

The Golden Rule: Above all else, treat others as you’d like to be treated

By showing others the same courtesy you expect from them, you will gain more respect from coworkers, customers, and business partners. Holding others in high regard demonstrates your company’s likeability and motivates others to work with you. This seems so simple, as do so many of these principles — and yet many people, too concerned with making money or getting by, fail to truly adopt these key concepts.

Replace last commit message

Summary:
---------

If you want to remove last commit message or replays existing one by following step

Step 1:
-------

Navigate your app git initialized directory and add this command

$ git commit --amend -m "New commit message"

Installing Sublime Text 2 in Ubuntu

Summary:
----------
 Install sublime Text 2 editor on Ubuntu repository

Step 1:
-------
Open terminal and add the ubuntu repository link to our kerlnal

$ sudo add-apt-repository ppa:webupd8team/sublime-text-2


Step 2:
-------
Update Ubuntu repository

$ sudo apt-get update


Step 3:
-------
Now install Sublime Text2 by command

$ sudo apt-get install sublime-text

Friday, October 25, 2013

Install Apache2 on Ubuntu



Summary:
--------
Install new  Apache 2, as well as other dependent packages and its associated configurations.


Step 1:
------
Update your packages

$ sudo apt-get update

Step 2:
------
Install apache2 and associated packages

$ sudo apt-get install apache2

Uninstall Apache2 on Ubuntu



Summary:
--------
Need to remove Apache2, as well as other dependent packages and its associated configurations.


Step 1:
------
Stop apache serveice if already exists.

$ sudo service apache2 stop

Step 2:
------
Remove apache2 and associated packages

$ sudo apt-get purge apache2 apache2-utils apache2.2-bin apache2-common
$ sudo apt-get autoremove


Step 3:
------
Check apache2 installation folders

$ whereis apache2

-> apache2: /etc/apache2


Step 4:
------
Remove apache2 folder from /etc

$ sudo rm -rf /etc/apache2

Thursday, October 24, 2013

Ubuntu rvm installation for ruby an rails


Summary:
--------

Install rvm to uUbuntu system and install ruby as well as rails.



Step 1:
------
Before installation we need to update the Ubuntu system

$ sudo apt-get update


Step 2:
------
After updated the system we need to install curl for fetching the rvm stable source from the rvm side using curl

$ sudo apt-get install curl

Step 3:
-------
Install stable rvm, it will take few minute for installation.  

$ \curl -L https://get.rvm.io | bash -s stable

Step 4:
-------
After rvm install we need to add the execution of rvm to source

$ source ~/.rvm/scripts/rvm

Step 5:
-------
Check rvm is installed correctly

$ rvm requirements

Step 7:
-------
Install Latest ruby in that rvm and make as default

$ rvm install ruby
$ rvm use ruby --default

Step 8:
-------
Install default required ruby gem for current ruby version

$ rvm rubygems current

Step 9:
-------
Now install rails it will install latest version of rails

$ gem install rails


Step 10:
-------
All installation completed create your rails project and start your application.

$ rails new sample
$ rails s






Create server in Ubuntu

Summary:
--------
Create your own ubuntu server

installation steps:
------------------

Step1:
-----
Open terminal, check your root password is valid.

sudo su

check the password is correct/wrong

Step2:
------
In terminal type command and get your local  ip address:

ifconfig eth0 | grep inet | awk '{ print $2 }'

Step3:
------
Now login using ssh from root

$ ssh root@123.122.34.32
$ Enter your root(server) password
$ It may ask public key credentials, type 'yes'


Step4:
------
Create a user account for the login accout

adduser rails

Step5:
------
Give all root permission for the user

$ visudo

add the following command lines after the root previllages

# User privilege specification
rails    ALL=(ALL:ALL) ALL

Type 'ctrl+x'

Save the file.

Step6:
-----
Now you can login as rails to the created server

$ ssh rails@123.122.34.32
$ enter password: ****

You can do with your server whatever requirements

Angular Rails patch to $.ajax pass the CSRF protection


Summary:
--------
If we using $.ajax to pass the value need to verify the CSRF production. It will work both rails 3 & rails 4.


Step 1:
-------

You need to add the below code to pass the CSRF production during $.ajax.

JS:
---

app.config(["$httpProvider", function(provider) {
  provider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content');
}]);

Coffee:
------

app.config ["$httpProvider", (provider) ->
  provider.defaults.headers.common["X-CSRF-Token"] = $("meta[name=csrf-token]").attr("content")
]