Basic Ruby on Rails Deploy to EC2 Amazon Web Services

 

1. Open AWS Console Page, Choose EC2.


AWS Console Page

 

2. Go to Key Pairs Menu and Generate New Key Pair, It Will Downloaded on Your PC.


Key Pair

 

3. Go To Security Group Menu, Create New Security Group and Setting Port Range on Inbound Tab With 80.


Security Group

 

4. Go To Instance Menu and Then Choice Ubuntu For Server, You Can Skip Another Step. When You Click Launch, You Will Choice To Use Which Key Pair.

 

With pen file, you can access your virtual server with this command :

 

 

      $ ssh -i file.pem [email protected]

 

After logged in, you can install and configure apache passenger.

 

 

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

 

Configure RVM

 

 

      source ~/.rvm/scripts/rvm rvm use ruby --default rvm install ruby rvm use ruby --default rvm ruby gems current

 

Install rails and other stuff.

 

 

      gem install rails sudo apt-get install git-core sudo apt-get install apache2 sudo apt-get install mysql-server gem install passenger

 

You will install apache2 module :

 

 

      passenger-install-apache2-module

 

There is will show some error, but don’t worry, the installer will tell you for fix the error, like this :

 

 

      sudo apt-get install libcurl4-openssl-dev apache2-threaded-dev libapr1-dev libaprutil1-dev=

 

There is will show error for swap memory configuration, you can fix this with this command :

 

 

      sudo dd if=/dev/zero of=/swap bs=1M count=1024 sudo mkswap /swap sudo swapon /swap

 

There is will take a long time, maybe about a hour, don’t worry if you see error. After finish for install apache passenger module, you can clone your project into server and add new configuration file on /etc/apache2/sites-available . Let we create new config file with name practice.conf. Fill the file with this code :

 

 

      <VirtualHost *:80> ServerName dnsname.com # !!! Be sure to point DocumentRoot to 'public'! DocumentRoot /home/ubuntu/yourapp/public <Directory /home/ubuntu/yourapp/public> Options All AllowOverride All Require all granted </Directory> </VirtualHost>

 

Disable default configuration :

 

 

      sudo a2dissite 000-default.conf

 

Enable new configuration.

 

 

      sudo a2ensite practice.conf

 

Restart apache.

 

 

      sudo service apache2 restart

 

Your virtual server has already to live now. you can setup your rails app like migrate and precompile your rails app.

 

 

Written by : Team Kasela - Developers at 41studio