Install and configure the rails3 + nginx runtime environment on an Amazon EC2 instance

Source: Internet
Author: User
Tags install openssl

Environment: Ubuntu lts 12.04 (free usage tier)

0. preparation:

0.1. Update the system
$ Sudo apt-Get update
$ Sudo apt-Get upgrade
0.2 install the compiling environment
$ Sudo apt-Get install build-essential Git-core
$ Sudo apt-Get install curl
1. Install rvm and ruby1.9.3
1.1 install rvm
Run the following command:
$ Bash-s stable <(curl-s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
Modify the. bashrc file. Note that Ubuntu in/home/Ubuntu is the user name and must be replaced with your own.
$ Echo '[[-s "/home/Ubuntu /. rvm/scripts/rvm "] & source"/home/Ubuntu /. rvm/scripts/rvm "'> ~ /. Bashrc
(Or echo "Source \ $ home/. rvm/scripts/rvm" >> ~ /. Bashrc)
Make the modification take effect immediately. Execute:
$ Source. bashrc

1.2 install ruby1.9.3
Install zlib1g
$ Sudo apt-Get install zlib1g zlib1g-dev
Install OpenSSL
$ Rvm PKG install OpenSSL

Installation: (this step is time-consuming and may take 10 minutes)
$ Rvm install 1.9.3 -- With-OpenSSL-Dir = $ home/. rvm/usr
Set the default value:
$ Rvm use -- default 1.9.3
$ Rvm gemset use global
$ Gem list

$ Rvm ruby-1.9.3-p194 @ rails326 -- create -- default
$ Rvm gemset list

1.3 install rails3
$ Gem install rails

Install SQLite
$ Sudo apt-Get install sqlite3 libsqlite3-dev

2. Test the rails Environment
2.1 create a test application: firstapp, path :~ /Webapps/firstapp (~ Point to the root directory of the current user, the same below)
$ Cd
$ Mkdir webapps
$ CD webapps
$ Rails new firstapp
$ CD firstapp
2.2 edit gemfile
$ Nano gemfile
Use nano to edit gemfile and add downstream information to gemfile,
Gem 'therubyracer'
Save and exit. Run
$ Bundle install
2.3 run the rails Service
$ Rails s
2.4 open a browser: (port 3000 must be added to the security policy of the EC2 instance)

Http://ec2-x-x-x-x.ap-southeast-1.compute.amazonaws.com: 3000

If it is enabled successfully, rails installation is complete. (X-X is the IP address of your EC2 instance)

3. Install nginx + passenger
3.1 install passenger
$ Gem install passenger
3.2 install ngigx
Install the dependency package first:
$ Sudo apt-Get install libcurl4-openssl-dev
Run the following command to install nginx. Two options are displayed: select 1 to install nginx1.2.1.
$ Rvmsudo passenger-install-nginx-Module
The default installation path is/opt/nginx.

3.3 download nginx Startup Script
$ Git clone https://github.com/hulihanapplications/nginx-init-debian.git
$ CD nginx-init-Debian
$ Sudo CP etc/init/nginx. CONF/etc/init
$ Sudo start nginx

3.4 configure firstapp in nginx
Add a link under/opt/nginx/html. Note that you need to link it to the public directory of the rails project.
$ Pwd
/Opt/nginx/html
$ Sudo ln-S ~ /Webapps/firstapp/public/firstapp
Then edit the nginx. conf file.
$ Sudo nano/opt/nginx/CONF/nginx. conf
Add the following two lines to the server segment:
Passenger_enabled on;
Passenger_base_uri/firstapp;
Modify SERVER_NAME: localhost to SERVER_NAME: www.yourdomain.com.
Save and exit. (Yourdomain.com is your own domain name .)
Restart nginx:
$ Sudo restart nginx
Or use
$ Sudo stop nginx
$ Sudo start nginx
3.5 test configuration results:
Open your browser and access: http://www.yourdomain.com/firstapp

[Appendix 1] prevent installation of RI and rdoc

Create ~ /. Gemrc file:

$ Cat. gemrc (Note: This is a command to view the content of the. gemrc file)
---
: Backtrace: false
: Benchmark: false
: Bulk_threshold: 1000
: Sources:
Https://rubygems.org
: Update_sources: True
: Verbose: True
Install: -- no-rdoc -- no-ri
Update: -- no-rdoc -- no-ri

[Appendix 2] If a zlib error occurs during installation, try the following method: failed. The above method is used successfully.
$ Rvm remove 1.9.3
$ Rvm PKG install zlib
(Or rvm package install zlib)

$ Rvm install 1.9.3 -- With-zlib-Dir = $ rvm_path/usr

Refer:

1) http://www.andrehonsberg.com/article/install-rvm-ubuntu-1204-linux-for-ruby-193
2) http://www.modrails.com/documentation/Users%20guide%20Nginx.html#deploying_a_rack_app

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.