標籤:ruby debian nginx apache rails
安裝軟體
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 協助.
[email protected]:/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 modulerequire "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 dbhend
<span style="background-color: rgb(102, 102, 102);"><span style="color:#ffffff;">[email protected]:/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
[email protected]:/home/www# mysql -u root -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 40Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.[email protected](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開發環境.