Deploying Rails Application on Amazon Ec2

Hello guys

Posting after a long time. But any ways below are the steps if you want to deploy a rails app on ec2 directly without using any 3rd party service providers

All the details mentioned below after for ubuntu so path might vary for other Linux flavours.

step 1 = Set java home. Ofcourse you need to have java installed and I assume that you already have it installed.

JAVA_HOME=/usr/lib/jvm/java-6-openjdk/
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH

Step 2 = login to amazon aws go to the account tab and download security credentials.  You will see 2 things

1) private key 2) certificate

Download them and store it on some path like /home/dhaval/cert or whatevery

Than export the keys and set it up with the following commands

export EC2_PRIVATE_KEY=/home/dhaval/cert/pk-2spdXHCQ4HDMJNCULJB5NA4JNLE7SWOR.pem
export EC2_CERT=/home/dhaval/cert/cert-2spdJXHCQ4HDMJNCULJB5NA4JNLE7SWOR.pem

Step 3 = Download api tools available on aws site

http://aws.amazon.com/developertools/351?_encoding=UTF8&jiveRedirect=1

export it and set the path

export EC2_HOME=/home/dhaval/cert/ec2-api-tools-1.3-62308
export PATH=$EC2_HOME/bin:$PATH

Step 4 = set up ssh keys using the following commands

ec2-add-keypair gsg-keypair

Now save this generated kaypair in ~/.shh folder with name id_rsa-gsg-keypair

Step 5 = Start an instance using the command below

ec2-run-instances (ami instance name) -k gsg-keypair

Step 6 = Check status of the instance

check status with

ec2-describe-instances (instant name)

eg.

ec2-describe-instances i-10a64379

Step 7 = Authorization of network ports using commands as below

ec2-authorize default -p 22
ec2-authorize default -p 80

Step 8 = Connect to your instance using the command below

ssh -i id_rsa-gsg-keypair root@machine_name

Thats all once these steps are done you can see the instance running on the aws console.

Than install ruby gems + rails + other required gems and packages and you are set to go.

In order to upload your files you can use Capistrano or also you can ssh through ftp using the key specified.

Hope this helps. If you are stuck at any step do feel free to ask question and I shall get back to you.

Njoi

Be Sociable, Share!

10 comments

  • Dhaval Patel

    amazon ec2 account is free ? I mean any commercial App is allow to deploy on it ?

  • Hi Dhaval

    amazon ec2 account is not free (i.e using its service of ec2 or s3 and others).
    pricing details can be found on http://aws.amazon.com/ec2/pricing/ and ofcourse commercial apps can be deployed on cloud there r so many of them.

    Let me know if you want any other info.

    Thanks

  • Pulkit

    Hi Dhaval,

    Thanks for nice post. I am facing one issue while doing above setup.

    when I try to run Step 7 it is giving me errors as below:
    Client.InvalidPermission.Duplicate: The permission ‘0.0.0.0/0-1-22-22’ has already been authorized on the specified group\ for ec2-authorize default -p 22

    and

    “Client.InvalidPermission.Duplicate: The permission ‘0.0.0.0/0-1-80-80’ has already been authorized on the specified group\ for ec2-authorize default -p 80

    Can you please help me on this?

    Thanks,
    Pulkit

  • Pulkit

    Hi Dhaval,

    Thanks for nice post. I am facing one issue while doing above setup.

    when I try to run Step 7 it is giving me errors as below:
    “Client.InvalidPermission.Duplicate: The permission ‘0.0.0.0/0-1-22-22’ has already been authorized on the specified group” for ec2-authorize default -p 22

    and

    “Client.InvalidPermission.Duplicate: The permission ‘0.0.0.0/0-1-80-80’ has already been authorized on the specified group” for ec2-authorize default -p 80

    Can you please help me on this?

    Thanks,
    Pulkit

  • Hi Pulkit

    Thanks for the post. This suggests that both the ports are already open so no need to worry at all. Continue with the other steps.

    Hope this helps

    Thanks

  • Pulkit

    Hi Dhaval,

    Thanks for quick reply. It works fine now.

    Thanks & Regards,
    Pulkit J. Pancholi

  • Pulkit

    Hello Dhaval,

    After doing all above steps, I tried to deploy my rails application by Capistrano. When I run command “cap deploy:setup” it gives below error:

    connection failed for: ec2-xxx-xx-xxx-xx.compute-1.amazonaws.com (Net::SSH::AuthenticationFailed: root)

    Thanks & Regards,
    Pulkit J. Pancholi

  • Hi pulkit have you configured ssh keys + checked on amazon GUI if the instance is running? please confirm that and get back to me.

    Thanks

  • Pulkit

    Hi Dhaval,

    I got this error because I have changed permission of some folder on server.

    I have to restart instance to take effect.

    Thanks & Regards,
    Pulkit J. Pancholi

  • Hi Pulkit

    So the problem is now solved correct?

    Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *