This tutorial is only suitable for Ubuntu Server for deploying projects online. It is recommended to use the same Ubuntu version to avoid problems caused by different versions.
This tutorial is suitable for beginners to deploy Rails applications for the first time;
This article test passes the environment
Ubuntu 12.04 Server,
The server installation was tested on Linode VPS (Ubuntu 12.04 LTS (GNU/Linux 3.4.2-x86_64-linode25 x86_64).
Configure Ubuntu Server System
If you are a domestic server, it is recommended to modify NetEase's source
Enter sudo vi /etc/apt/ to replace the contents with:
deb http://mirrors./ubuntu/ precise main restricted universe multiversedeb
http://mirrors./ubuntu/ precise-security main restricted universe multiversedeb
http://mirrors./ubuntu/ precise-updates main restricted universe multiversedeb
http://mirrors./ubuntu/ precise-proposed main restricted universe multiversedeb
http://mirrors./ubuntu/ precise-backports main restricted universe multiversedeb-src
http://mirrors./ubuntu/ precise main restricted universe multiversedeb-src
http://mirrors./ubuntu/ precise-security main restricted universe multiversedeb-src
http://mirrors./ubuntu/ precise-updates main restricted universe multiversedeb-src
http://mirrors./ubuntu/ precise-proposed main restricted universe multiversedeb-src
http://mirrors./ubuntu/ precise-backports main restricted universe multiverse
Then update:
$ sudo apt-get update
Install the necessary three-party library
$ sudo apt-get install -y wget vim build-essential openssl libreadline6 libreadline6-dev libmysqlclient-dev curl git-core zlib1g 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
$ /curl -L | bash -s stable $ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"' >>~/.bashrc $ source ~/.bashrc $ rvm -v
Install Ruby
If you are a domestic server, it is recommended to replace the RVM installation source with Taobao's mirror server, so that the installation can be faster!
$ sed -i -e 's/ftp/.ruby-lang/.org//pub//ruby/ruby/.taobao/.org//mirrors//ruby/g' ~/.rvm/config/db
Install Ruby with RVM:
$ rvm pkg install readline openssl $ rvm install 2.0.0 $ rvm use 2.0.0 --default $ ruby -vruby 2.0.0p247
It is recommended to replace RubyGems to Taobao image for domestic servers:
$ gem sources --remove / $ gem sources -a / $ gem sources -l *** CURRENT SOURCES ***
Install Rails
$ gem install rails $ rails -vRails 4.0.0
Install MySQL or other database
Of course, if your project is using another database, please solve it yourself
$ sudo apt-get install mysql-server
Follow the prompts to install it. The things involved here are outside this tutorial. Please solve them by yourself in Google-related tutorials.
Deploy your website
Next, you can submit the source code of your project to the server through Git or other means, and it is recommended to put it under the user's ~/www.
To facilitate the tutorial, we assume that the user is jason (with sudo permissions), and if the project name is gitlab, please modify it with your own situation.
$ cd ~/ $ pwd /home/jason/ $ mkdir www $ cd www $ git clone git@: $ cd gitlab $ bundle install
Modify your database configuration, create a database, merge migration... These are the foundations of Rails development, I won't go into details here. The key is that in the end you can make your project run with rails s!
$ rails s -e production
Install Passenger for deploying Rails applications
$ gem install passenger $ passenger -vPhusion Passenger version 4.0.10
Since Passenger needs to recompile Nginx, if you have installed Nginx before, you need to uninstall it!
nginx -v, if there is one, uninstall $ sudo apt-get remove nginx-common nginx-full nginx
Install Nginx with Passenger
$ sudo passenger-install-nginx-module
Next, a prompt appears, selectYes: download, compile and install Nginx for me. (recommended), keep selecting which item to default for the following prompts, and press Enter.
Finally seen
Nginx with Passenger support was successfully installed.
It means that you have a good character and Nginx installation is successful! Otherwise please seePassenger official installation documentationSolve it yourself...
Install Nginx init script
Next you need to install Nginx startup scripts and configure automatic startup
$ cd ~/ $ git clone git:///jnstq/ $ sudo mv rails-nginx-passenger-ubuntu/nginx/nginx /etc//nginx $ sudo chmod +x /etc//nginx
Configure Nginx to boot
$ sudo nginx defaults
Configure Nginx and website
Open Nginx
$ sudo vim /opt/nginx/conf/
PS: If you are not Nginx installed by Passenger, this configuration file may also be under /usr/local/nginx/ or /etc/nginx
Please refer to the following example to modify:
user jason; # Modify it to your system account name, otherwise the project directory /home/jason/www does not have permission hereworker_processes 8; # Modify to the same number of CPU cores as yourpid /var/run/; http { include ; default_type application/octet-stream; client_max_body_size 50m; sendfile on; access_log /var/log/nginx/; error_log /var/log/nginx/; gzip on; gzip_disable "msie6"; ## -------------------------- server { # This is used to prevent other domain names from being bound to your website listen 80 default; return 403; } server { listen 80; server_name ; # Please replace it with your website's domain name rails_env production; root /home/jason/www/gitlab/public; passenger_enabled on; location ~ ^(/assets) { access_log off; # Set the browser cache time below assets to the maximum value (since the file name of Rails Assets Pipline is the MD5 digest file name generated according to file modification, so you can open it here with confidence) expires max; } } ## --------------------------------- }
Restart Nginx
$ sudo /etc//nginx start
Deployment is complete! You can try to access your domain name.
Additional to other netizens: Recommended view
I just tried it, it was very easy.
Just treat it as an entry-level tutorial. .
Note: This article only introduces how to install the Rails environment on Ubuntu 12.04 Server, and does not guarantee that your Rails project will run normally on 12.04.
This article tests the environment
•The system installed is: Ubuntu 12.04 Server LTS amd64
• Installed on: Parallels Desktop virtual machine on OSX
Ubuntu installation
Very common installations:
1. Select English Installation
Select other -> Asia -> China
3. Continue to install and default all the way. .
4. Enter your name, username and password
the changes to disks and configure LVM? <Yes>
the changes to disks? <Yes>
Selection stage: Select OpenSSH server (press the space bar) (you will use ssh in the future...)
8. Regarding GRUB issues, if you have multiple systems, please refer to other information
9. Installation is completed and restart automatically.
Update the system
1. Log in to the system
2. Replace the update source: $ sudo vim /etc/apt/ I am in the Education Network, so I changed the source of the Education Network
3. Update the software list: $ sudo aptitude update
4. Update software: $ sudo aptitude upgrade
5. Reboot: $ sudo reboot
Install Ruby, Rails and related
Simple method:
I wrote a script that can be used directly:
Server version Ubuntu 12.04
$ curl -L /gist/2521307/ | bash
Desktop version Ubuntu 12.04
$ curl -L /gist/2521307/ | bash
If rails -v fails after running the script, reopen terminal/shell.
Complex method:
1. Install RVM: $ curl -L | bash -s stable
2. Add rvm to PATH: $ source ~/.rvm/scripts/rvm
3. Check the packages that need to be installed: $ rvm requirements
4. Install the required packages prompted in the previous step: $ sudo aptitude install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion
5. Install Ruby 1.9.3: $ rvm install 1.9.3
6. Replace gem's source: $ gem source -r /;gem source -a
7. Install Bundler and Rails: $ gem install bundler rails
Test whether the installation is successful
1.$ rails new path/to/your/new/application
2.$ cd path/to/your/new/application
3.$ vim Gemfile , change the source of the first line to , add the last line: gem 'therubyracer'
4.$ rails server
5. Open :3000/ with a browser. If you can access it, the installation will be successful.