首页 > 代码库 > debian 安装ruby +nginx+apache开发环境.

debian 安装ruby +nginx+apache开发环境.

安装软件

1.很简单, 前提你安装了apache, mysql, nginx 如果没有 加上.

#apt-get installapache2 nginx

2.开启apache的重写.

#a2enmod rewrite

#apt-get install mysql-server

3.下面会安装ruby, apache的ruby模块, mysql的ruby支持, vim的rails支持.

#apt-get install ruby rails rubygems rake  libapache2-mod-ruby libdbi-ruby libdbd-mysql-ruby vim-rails  ri libruby  libfcgi-ruby1.9.1 libxml-ruby libxml2-dev


查看安装的ruby版本 

gem 常用命令

  • gem list 列出已经安装的包
  • gem install xxx 安装包
  • gem uninstall xxx 卸载安装包
  • gem query xxx 搜索包
  • gem cleanup 清除cache
  • gem help 帮助.

root@debian:/home/ruby# gem list


*** LOCAL GEMS ***


rubyzip (1.1.3)

测试ruby和mysql的链接

编写一个简单的脚本来测试链接, 如果显示mysql版本就ok了.

#gvim test.rb

# test.rb - test MySQL script using Ruby DBI module
require "dbi"
begin
    # connect to the MySQL server
    dbh = DBI.connect("dbi:Mysql:mysql:localhost", "root", "")

    # get server version string and display it
    row = dbh.select_one("SELECT VERSION()")
    puts "Server version: " + row[0]
rescue DBI::DatabaseError => e
    puts "An error occurred"
    puts "Error code: #{e.err}"
    puts "Error message: #{e.errstr}"
ensure
    # disconnect from server
    dbh.disconnect if dbh
end
<span style="background-color: rgb(102, 102, 102);"><span style="color:#ffffff;">root@debian:/home/ruby# ruby ./test.rb 
Server version: 5.5.37-0+wheezy1-log</span></span>


测试 rails

#cd /home/www 先进入apache, nginx的www目录, 我这里都设置的一个.
#rails new_project 来建立一个rails的project.
#cd new_project
#rm -rf public/index.html  这里删除掉默认页面,以免一直跳转到这里.
#vim config/database.yml  修改development开发模式的database: ruby_test 
#mysql -uroot -p   进入mysql后建一个ruby_test的DB  
root@debian:/home/www# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 40
Server version: 5.5.37-0+wheezy1-log (Debian)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

root@(none) 12:02:44>create database ruby_test;
Query OK, 1 row affected (0.00 sec)
#script/generate controller Blog        建立一个 Blog 的 controller
#script/server                          启动 server, 就可以由 http://localhost:3000/ 访问了
现在来实现Hello world
#vim app/controllers/blog_controller.rb
加入
def index
    render :text => "Hello world"
end


debian 安装ruby +nginx+apache开发环境.