Installing Rails 3.1 pre-release
Create a rvm gemset:
rvm 1.9.2@my_gem_set --create
Install Rails 3.1
gem install rails --pre
If you don’t have a javascript engine like Node installed, you need to manually add one to your Gemfile:
gem 'execjs'
gem 'therubyracer'
Install your gems:
bundle install
Resources:
Teach your MySQL database to talk giberish (Add UTF-8 support to your MySQL database for Rails)
MySQL needs to be configured to support UTF-8 encoding with Rails. Here are the steps –
1. Make sure this line in in your database.yml:
encoding: utf8
2. Edit your MySQL configuration file /etc/mysql/my.cnf, and place the following codes in these sections:
... [client] default-character-set=utf8 ... [mysqld] default-character-set=utf8 character-set-server=utf8 default-collation=utf8_unicode_ci ...
If things are set correctly, you should get the following results:
mysql> SHOW VARIABLES LIKE 'character\_set\_%'; +--------------------------+--------+ | Variable_name | Value | +--------------------------+--------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | +--------------------------+--------+
3. Restart your database
sudo /etc/init.d/mysql restart
Done!
*Note that only databases created AFTER this change will support UTF8 encoding. I’ve seen others modifying the existing databases, but I find it easier to drop everything and recreate the databases since my app was in development anyway.
Resources:
Talking to your EC2
To SSH to your instance, do:
ssh -i /path/to/keyname ubuntu@<external-host-name>
The rails files are located in /mnt/your_app_name-production/current
<< Real-time logging >>
tail -f /path_to_rails_root/log/production.log
You can also combine it with the grep command for filtering. For example, to view all the lines with the word GET only:
tail -f /path_to_rails_root/log/production.log | grep 'GET'
Or if you are using rubber, just do:
cap rubber:tail_logs
To find out where your apache log file is located:
grep ErrorLog /etc/apache2/apache2.conf
for Ubuntu, it’s here:
/var/log/apache2/error.log
Deploying your Rails app to AWS EC2 using Rubber
1. Setup your keypair Download your private key:
(https://console.aws.amazon.com/ec2/home?region=us-east-1#s=KeyPairs)
Change keyname.pem to keyname:
chmod 400 keyname ssh-keygen -y -f keyname > keyname.pub
2. Install Rubber
sudo gem install rubber bundle install rails g vulcanize complete_passenger_mysql
3. Edit config/rubber/rubber.yml
cloud_providers → aws → access_key cloud_providers → aws → secret_access_key cloud_providers → aws → account cloud_providers → aws → keyname image_type: t1.micro image_id: 'ami-3e02f257'
4. Change the ruby version if necessary
The default uses ruby version 1.9.2, which was giving my trouble when parsing YAML files. You can get around this by either:
a) Set “rvm_ruby” to 1.8.7 in your app/config/rubber/rubber-rvm.yml, or
b) Add these two lines to your boot.rb if YAML doesn’t parse correctly:
require 'yaml' YAML::ENGINE.yamler= 'syck'
5. Deploy
cap rubber:create_staging
It’s a good time now to go grab a bite and hope that it’s finished by the time you’re back….
<<To push new changes up>>
cap deploy:check cap deploy:setup cap deploy:cold
or simply
'cap deploy'
<<To run migrations>>
cap deploy:migrate (migration without deploy) cap deploy:migrations (migration with deployment)
<<To terminate the instances>>
cap rubber:destroy_staging
<<Miscellaneous>>
To see all the documented rubber tasks:
cap -T | grep rubber
To describe one in more detail:
cap -e rubber:bootstrap
To really see all rubber tasks (including undocumented ones):
cap -Tv | grep rubber
References:
Set up your Rails 3 app to use MySQL
Create a new rails project using MySQL as the backend:
rails new <app_name> -d mysql
Run the following commands to install MySQl:
sudo apt-get install mysql-server mysql-client sudo apt-get install libmysql-ruby libmysqlclient-dev sudo gem install mysql
Edit your database.yml file if necessary
development: adapter: mysql2 encoding: utf8 reconnect: false database: your_database_development pool: 5 username: root password: host: localhost
References:
Install Ruby RVM
Install the RVM:
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
Edit your ~/.bashrc file by following the instructions given:
You must now complete the install by loading RVM in new shells. 1) Place the folowing line at the end of your shell's loading files (.bashrc or .bash_profile for bash and .zshrc for zsh), after all PATH/variable settings: [[ -s "/home/eric/.rvm/scripts/rvm" ]] && source "/home/eric/.rvm/scripts/rvm" # This loads RVM into a shell session. You only need to add this line the first time you install rvm. 2) Ensure that there is no 'return' from inside the ~/.bashrc file, otherwise rvm may be prevented from working properly. This means that if you see something like: '[ -z "$PS1" ] && return' then you change this line to: if [[ -n "$PS1" ]] ; then # ... original content that was below the '&& return' line ... fi # be sure to close the if at the end of the .bashrc. # This is a good place to source rvm v v v [[ -s "/home/eric/.rvm/scripts/rvm" ]] && source "/home/eric/.rvm/scripts/rvm" # This loads RVM into a shell session. EOF - This marks the end of the .bashrc file Be absolutely *sure* to REMOVE the '&& return'. If you wish to DRY up your config you can 'source ~/.bashrc' at the bottom of your .bash_profile. Placing all non-interactive (non login) items in the .bashrc, including the 'source' line above and any environment settings. 3) CLOSE THIS SHELL and open a new one in order to use rvm.
Note – Use this line if you installed as user:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
To see if it works:
rvm list known
Install the recommended dependencies:
apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev
Install the ruby version you want to use:
rvm install ruby-1.9.2-p180
To use a specific version:
rvm use 1.9.2
To check which version you are using:
ruby -v
Alternatively, you can set it as default:
rvm --default 1.9.2
Switch to default:
rvm use default
You can also create a .rvmrc file so that rvm automatically changes to that particular gemset when you enter the folder:
rvm --rvmrc --create 1.9.2@project_name
Resources: