1. 以非root用户更新系统
sudo apt-get updatesudo apt-get upgrade
2. 设置主机名,如果是系统是图形安装的,则这步骤可以忽略
sudo hostname your-hostname
Add 127.0.0.1 your-hostname:
sudo vim /etc/hosts
Write your-hostname in:
sudo vim /etc/hostname
Verify that hostname is set:
hostname
3. 以非root安装 git &curl
新的ubuntu系统,需要安装这些包;
sudo apt-get install curl git
4. 安装RVM
$ bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
add below to your .bashrc.
|
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" |
Once you edit your bashrc file execute the following to load rvm without logging out and back in
把~/.bashrc中的return都删除,[ -z "$PS1" ] && return 改成 [ -z "$PS1" ]
运行:
|
source ~/.rvm/scripts/rvm |
Just to be safe check wether rvm is a function, which is what it should be.
5. Install ruby 1.9.2sudo aptitude "bash functions">install "bash plain">build-essential bison openssl libreadline5 libreadline5-dev curl git-core zlib1g zlib1g-dev libssl-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libmysqlclient-dev
rvm "bash functions"> install "bash plain">1.9.2
rvm use 1.9.2 --default
6. 安装 rails3
gem install rails
7. 安装 passenger and nginx
gem install passenger
rvmsudo passenger-install-nginx-module
这个步骤需要一些required softwares,可以按照提示完成
8 测试nginx
8.1 检查nginx的安装结果:
sudo vi /opt/nginx/conf/nginx.conf
确保以下为ruby 1.9.2(以 "bash plain">rvm use 1.9.2 --default保持一致) 和 passenger 3
http {
passenger_root /home/leslin123/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.3;
passenger_ruby /home/leslin123/.rvm/wrappers/ruby-1.9.2-p180/ruby;
8.2 启动
sudo /opt/nginx/sbin/nginx
打开
nginx的欢迎界面:http://localhost/
如果看到:Welcome to nginx! , 那么恭喜你!
9. Install latest version MySQL
sudo apt-get install mysql-server mysql-client
这个步骤花费的时间比较多,since需要下载的软件多于20M
根据提示为root设置相应的密码,3344***
10. 创建rails application
在当前用户目录中,如/home/les***/rorails 创建
rails new helloubuntu
进入应用目录,运行 bundle install
这时sqllite3会被安装
11. 运行 rails server
启动的log为:
[email protected]:~/rorails/helloubuntu$ rails server
=> Booting WEBrick
=> Rails 3.0.4 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-02-26 11:28:38] INFO WEBrick 1.3.1
[2011-02-26 11:28:38] INFO ruby 1.9.2 (2011-02-18) [x86_64-linux]
[2011-02-26 11:28:38] INFO WEBrick::HTTPServer#start: pid=14429 port=3000
打开目录http://localhost:3000/, 可以看到rails欢迎界面,但这个只是说明rails 配置成功。
显然,所希望的web服务器和数据库都没有配置好!
12. 配置MySQL
rails new helloMySQL -d mysql
cd ./helloMySQL
问题:
rails server
Could not find gem 'mysql2 (>= 0, runtime)' in any of the gem sources listed in your Gemfile.
解决方法:
bundle update
Installing mysql2 (0.2.6) with native extensions
进入应用程序目录,将root的密码添加到database.yml 中,否则启动后会出现类型下面的,数据库连接错误;
Access denied for user 'root'@'localhost' (using password: NO)
rake db:create
rails server
打开欢迎界面http://0.0.0.0:3000/; 点击: About your application’s environment
查看相关信息,包括: Database adaptermysql2
好了,现在就剩下最后一项了。
13. 配置nignx服务器
认真者可以在安装Nignx看到如下提示:
---------------------------------------**************************************************--------------------------------------
--------------------------------------------
Nginx with Passenger support was successfully installed.
The Nginx configuration file (/opt/nginx/conf/nginx.conf)
must contain the correct configuration options in order for Phusion Passenger to function correctly.
This installer has already modified the configuration file for you! The
following configuration snippet was inserted:
http {
...
passenger_root /home/leslin123/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.3;
passenger_ruby /home/leslin123/.rvm/wrappers/ruby-1.9.2-p180/ruby;
...
}
After you start Nginx, you are ready to deploy any number of Ruby on Rails applications on Nginx
Press ENTER to continue.
--------------------------------------------
Deploying a Ruby on Rails application: an example
Suppose you have a Ruby on Rails application in /somewhere. Add a server block
to your Nginx configuration file, set its root to /somewhere/public, and set
'passenger_enabled on', like this:
server {
listen 80;
server_name www.yourhost.com;
root /somewhere/public; # <--- be sure to point to 'public'!
passenger_enabled on;
}
And that's it! You may also want to check the Users Guide for security and optimization tips and other useful information:
/home/leslin123/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.3/doc/Users guide Nginx.html
---------------------------------------**************************************************--------------------------------------
配置:/opt/nginx/conf/nginx.conf
http {
passenger_root /home/leslin123/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.3;
passenger_ruby /home/leslin123/.rvm/wrappers/ruby-1.9.2-p180/ruby;
include mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name localhost;
root /home/leslin123/rorails/helloMySQL/public; #设置app目录
passenger_enabled on;
rails_env development; #设置为开发环境,默认是生产环境
#charset koi8-r;
#access_log logs/host.access.log main;
#location / {
# root /home/leslin123/rorails/helloMySQL/public;
# index index.html index.htm;
#}
配置Nginx为启动项:
curl -L http://bit.ly/nginx-ubuntu-init-file > /etc/init.d/nginx
[email protected]:~$ sudo chmod +x /etc/init.d/nginx
[email protected]:~$ sudo /usr/sbin/update-rc.d -f nginx defaults
System start/stop links for /etc/init.d/nginx already exist.
[email protected]:~$ sudo /etc/init.d/nginx start
* Starting Nginx Server.
进入项目,建立脚手架:
~/rorails/helloMySQL$ rails generate scaffold Post name:string title:string content:text
rake db:create
rake db:migrate
http://localhost/
http://localhost/posts