Installing the _ruby feature on the Ubuntu 12.04 Server deployment Ruby on Rails application

Source: Internet
Author: User
Tags curl md5 digest openssl browser cache openssh server ruby on rails automake


This tutorial is only suitable for Ubuntu Server to deploy the project to the line, it is recommended to use the same Ubuntu version, so as not to encounter some different versions of the problem.






This tutorial is suitable for beginners to deploy Rails applications for the first time;



This article tests through the environment






Ubuntu 12.04 Server,



Server installation tested on Linode VPS (Ubuntu 12.04 LTS (gnu/linux 3.4.2-x86_64-linode25 x86_64).






Configuring the Ubuntu Server system



If you are a domestic server, recommended to modify the source of NetEase



Enter sudo vi/etc/apt/sources.list to replace the contents inside:



Deb Http://mirrors.163.com/ubuntu/precise main restricted universe Multiversedeb
Http://mirrors.163.com/ubuntu/precise-security Main restricted Universe Multiversedeb
Http://mirrors.163.com/ubuntu/precise-updates Main restricted Universe Multiversedeb
http://mirrors.163.com/ubuntu/precise-proposed Main restricted Universe Multiversedeb
Http://mirrors.163.com/ubuntu/precise-backports Main restricted Universe MULTIVERSEDEB-SRC
Http://mirrors.163.com/ubuntu/precise Main restricted Universe MULTIVERSEDEB-SRC
Http://mirrors.163.com/ubuntu/precise-security Main restricted Universe MULTIVERSEDEB-SRC
Http://mirrors.163.com/ubuntu/precise-updates Main restricted Universe MULTIVERSEDEB-SRC
http://mirrors.163.com/ubuntu/precise-proposed Main restricted Universe MULTIVERSEDEB-SRC
Http://mirrors.163.com/ubuntu/precise-backports Main restricted Universe multiverse



And then update:


sudo apt-get update


Install the necessary tripartite libraries


sudo apt-get install-y wget vim build-essential OpenSSL libreadline6 Libreadline6-dev Libmysqlclient-dev Curl Git-core ZL ib1g zlib1g-dev libssl-dev libyaml-dev libxml2-dev libxslt-dev libcurl4-openssl-dev autoconf automake libtool ImageMagick Libmagickwand-dev Libpcre3-dev Nodejs Libpq-dev


Install Ruby, Rails, and related



Install RVM


/Cecho' [[s] $HOME/.RVM/SCRIPTS/RVM]] &&. "$HOME/.rvm/scripts/rvm" 'sourcervm-v


Install Ruby



If you are a domestic server, it is recommended to replace the RVM installation source with the Taobao mirror server, so that the installation can be faster!


' s/ftp/.ruby-lang/.org//pub//ruby/ruby/.taobao/.org//mirrors//ruby/g ' ~/.rvm/config/db


Install Ruby with RVM:


RVM Install 2.0.0 Ruby-vruby 2.0.0p247


Domestic server recommended to replace the RubyGems to Taobao Mirror:


Gem sources--remove https://rubygems.org/ gem sources-a http://ruby.taobao.org/    * * * http://ruby.taobao.org


Installing Rails


Rails-vrails 4.0.0


Installing MySQL or other databases



Of course, if your project is using the other database, please resolve it yourself


sudo apt-get install Mysql-server


Follow the prompts to install, here is something in the outside of this tutorial, please Google related tutorials to solve.



Deployment of your site



Next you can submit your project's source code to the server by Git or other means, and suggest that it be placed under the user's ~/www.



In order to facilitate the tutorial, we assume that the user is Jason (with sudo permissions), the project name Gitlab after encountering similar places please more own circumstances modify


CDpwd /home/jason/mkdir 
wwwwww git  Clone git@you.host:gitlab.git  gitlabBundle Install


Modify your database configuration, create a database, merge migration ... These are the basics of rails development, so here's the thing, and the point is that you can finally get your project running with rails s!


Rails S-E Production


Install passenger for deploying Rails applications


Passenger-vphusion passenger version 4.0.10


Since passenger need to recompile Nginx, if you have previously installed Nginx need to uninstall it off!
Nginx-v, some words uninstall $ sudo apt-get remove Nginx-common nginx-full nginx



Install Nginx with passenger


sudo passenger-install-nginx-module


Next, you will be prompted to select Yes:download, compile and install Nginx for me. (recommended) , select the default for the following prompts, and hit enter.



Last seen


Nginx with passenger support is successfully installed.


It means you have a good personality. Nginx Installation Success! Otherwise please see passenger official installation document to resolve itself ...



Install Nginx init script



Next you need to install the Nginx boot script and configure the boot to start automatically


cdsudochmod +x/etc/init.d/nginx


Configure Nginx to boot from


sudo update-rc.d nginx defaults


Configuring Nginx and Web Sites



Open Nginx's nginx.conf.


$ sudo vim/opt/nginx/conf/nginx.conf

PS: If you are not passenger installed Nginx, this profile may also be under/usr/local/nginx/or/etc/nginx


Please refer to the example below to modify:


user jason; # modify to your system account name, otherwise the project directory / home / jason / www does not have permissions here worker_processes 8;

# Change to the same number of CPU cores
 pid /var/run/nginx.pid;
http {include mime.types;
default_type application / octet-stream;
client_max_body_size 50m;
sendfile on;
access_log /var/log/nginx/access.log;
 error_log /var/log/nginx/error.log; gzip on;
 gzip_disable "msie6";

 ## ------------ Key Modifications -------- server {
# This is used to prevent other domain names from binding to your website listen 80 default; return 403;
}
server {
 listen 80;
server_name you.host.name; # Please replace with the domain name of your website
rails_env production;
root / home / jason / www / gitlab / public;
passenger_enabled on;
 location ~ ^ (/ assets) {
access_log off; # Set the browser cache time under assets to the maximum value (because the file name of Rails Assets Pipline is the MD5 digest file name generated according to the file modification, so you can safely open it here)
  expires max;
}} ## ---------------------------------} 


Restart Nginx


Sudo/etc/init.d/nginx start


Deployment Complete! You can try to access your domain name.



Other User's supplement: Recommended view



Just tried it, it was easy.



Just be a tutorial for the entry level.



Note: This article only describes how to install the rails environment on the Ubuntu 12.04 Server and does not guarantee that your rails project will work properly on 12.04.



This article tests the environment



• Installed system is: Ubuntu 12.04 Server LTS AMD64
• Installed on: OS X parallels Desktop virtual machine
Ubuntu Installation
Very common installation:



1. Select Chinese Version Installation
2.Location Select other-> Asia->
3. Continue to install, all the way by default.
4. Enter your name, username and password
5.Write the changes to disks and configure LVM? <Yes>
6.Write the changes to disks? <Yes>
7.Software selection Stage: Select OpenSSH server (press SPACEBAR) (you will use SSH in the future ...) )
8. For GRUB issues, if you are a multiple system, please refer to other information
9. Installation complete, automatic restart.



Update system



1. Landing System
2. Replace update Source: $ sudo vim/etc/apt/sources.list I'm in the education net, so change the source of the education net
3. Update Software list: $ sudo aptitude update
4. Update Software: $ sudo aptitude upgrade
5. Restart: $ sudo reboot



Install Ruby, Rails, and related
Simple method:



I wrote a script that you can use directly:



Server version Ubuntu 12.04



$ curl-l https://raw.github.com/gist/2521307/install-rails-12-04-server.sh | Bash
Desktop version Ubuntu 12.04



$ curl-l https://raw.github.com/gist/2521307/install-rails-12-04-desktop.sh | Bash
After running the script, if Rails-v fails, open a Terminal/shell again.



Complex approach:



1. Installation RVM: $ curl-l Get.rvm.io | Bash-s Stable
2. Add RVM to PATH: $ source ~/.RVM/SCRIPTS/RVM
3. View the packages that need to be installed: $ RVM Requirements
4. Package required to install the previous step: $ sudo aptitude install build-essential OpenSSL libreadline6 Libreadline6-dev Curl Git-core zlib1g zlib1g-d EV libssl-dev Libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool b ISON Subversion
5. Install Ruby 1.9.3: $ RVM Install 1.9.3
6. Replace the gem Source: $ gem source-r http://rubygems.org/;gem source-a http://ruby.taobao.org
7. Installing Bundler and Rails: $ gem Install bundler Rails



Test whether the installation was successful



1.$ Rails New path/to/your/new/application
2.$ cd path/to/your/new/application
3.$ vim Gemfile, the first line of source To http://ruby.taobao.org, add the end line: Gem ' therubyracer '
4.$ Rails server
5. Open the http://ip.of.your.host:3000/in a browser, if you can To access, the installation is successful.


Related Article

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.