2015年8月13日 星期四

Cloud9-RoR-mysql連結

https://docs.c9.io/docs/running-a-rails-app  本篇跟這份文件有關
開啟專案下的config/database.yml檔,將內容改成
development:
  adapter: mysql2
  encoding: utf8
  database: c9
  host: <%=ENV['IP']%>
  username: <%=ENV['C9_USER']%>
  password:
production:
  adapter: mysql2
  encoding: utf8
  database: c9
  host: <%=ENV['IP']%>
  username: <%=ENV['C9_USER']%>
  password:
test:
  adapter: mysql2
  encoding: utf8
  database: c9
  host: <%=ENV['IP']%>
  username: <%=ENV['C9_USER']%>
  password:

再打開專案下的Gemfile(就是這一步,我一直再想what is gemfile???),增加兩行
# Use mysql as the database for Active Record
gem 'mysql2'

接著在指令處下
gem install mysql2

安裝完成
Fetching: mysql2-0.3.19.gem (100%)
Building native extensions.  This could take a while...
Successfully installed mysql2-0.3.19
1 gem installed

Run程式啦
rails s -b $IP -p $PORT

畫面可以正常出現就代表完成啦!

在連線請先確定是不是裝好mysql,才不會鬼打牆。

Cloud9-RoR-rails與apache衝途

之前先裝phpmyadmin後run程式時會跑出這一大堆哩哩扣扣,然後失敗…
=> Booting WEBrick
=> Rails 4.2.1 application starting in development on http://0.0.0.0:8080
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2015-08-13 09:02:25] INFO  WEBrick 1.3.1
[2015-08-13 09:02:25] INFO  ruby 2.2.1 (2015-02-26) [x86_64-linux]
Exiting
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/socket.rb:206:in `bind': Address already in use - bind(2) for 0.0.0.0:8080 (Errno::EADDRINUSE)
        from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/socket.rb:206:in `listen'
        from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/socket.rb:461:in `block in tcp_server_sockets'
        from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/socket.rb:232:in `each'
        from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/socket.rb:232:in `foreach'
        from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/socket.rb:459:in `tcp_server_sockets'
        from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/utils.rb:70:in `create_listeners'
        from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:133:in `listen'
        from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:114:in `initialize'
        from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:45:in `initialize'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/rack-1.6.1/lib/rack/handler/webrick.rb:32:in `new'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/rack-1.6.1/lib/rack/handler/webrick.rb:32:in `run'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/rack-1.6.1/lib/rack/server.rb:286:in `start'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.1/lib/rails/commands/server.rb:80:in `start'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:80:in `block in server'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:75:in `tap'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:75:in `server'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.1/lib/rails/commands.rb:17:in `<top (required)>'
        from /home/ubuntu/workspace/bin/rails:8:in `require'
        from /home/ubuntu/workspace/bin/rails:8:in `<top (required)>'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/spring-1.3.6/lib/spring/client/rails.rb:28:in `load'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/spring-1.3.6/lib/spring/client/rails.rb:28:in `call'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/spring-1.3.6/lib/spring/client/command.rb:7:in `call'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/spring-1.3.6/lib/spring/client.rb:26:in `run'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/spring-1.3.6/bin/spring:48:in `<top (required)>'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/spring-1.3.6/lib/spring/binstub.rb:11:in `load'
        from /usr/local/rvm/gems/ruby-2.2.1/gems/spring-1.3.6/lib/spring/binstub.rb:11:in `<top (required)>'
        from /home/ubuntu/workspace/bin/spring:13:in `require'
        from /home/ubuntu/workspace/bin/spring:13:in `<top (required)>'
        from bin/rails:3:in `load'
        from bin/rails:3:in `<main>'

google了好久,終於在一個網站上發現解決之道(話說這個網站真的很好用,每次遇到問題幾乎都是在這個網站上找到解答滴)

http://stackoverflow.com/questions/26663967/rails-tutorial-chapter-1-rails-server-isnt-working-on-cloud9  原始網頁

下指令
lsof -i:8080

出現
COMMAND   PID   USER   FD   TYPE    DEVICE SIZE/OFF NODE NAME
apache2 15456 ubuntu    4u  IPv6 743515391      0t0  TCP *:http-alt (LISTEN)
apache2 15462 ubuntu    4u  IPv6 743515391      0t0  TCP *:http-alt (LISTEN)
apache2 15463 ubuntu    4u  IPv6 743515391      0t0  TCP *:http-alt (LISTEN)
apache2 15464 ubuntu    4u  IPv6 743515391      0t0  TCP *:http-alt (LISTEN)
apache2 15465 ubuntu    4u  IPv6 743515391      0t0  TCP *:http-alt (LISTEN)
apache2 15466 ubuntu    4u  IPv6 743515391      0t0  TCP *:http-alt (LISTEN)
apache2 17350 ubuntu    4u  IPv6 743515391      0t0  TCP *:http-alt (LISTEN)

原來是apach佔了8080port啊啊啊啊啊啊...所以停止它!
sudo /etc/init.d/apache2 stop

終於跑出頁面來了,可喜可賀~可喜可賀!
這問題搞了我一天,眼睛太用力的盯著螢幕,不酥湖,休息準備下班企…

2015年8月11日 星期二

Cloud9-RoR-phpmyadmin安裝

mysql的好朋友phpmyadmin。

https://docs.c9.io/docs/setting-up-phpmyadmin 官網文件

影片字很小又講很快。

指令:

$ phpmyadmin-ctl install

再次確認mysql為啟動中

$ mysql-ctl start

安裝完phpmyadmin後有一行很重要

PHPMyAdmin Installation complete. You can log in at: https://專案-帳號-1.c9.io/phpmyadmin with the following username (and blank password):

https://專案-帳號-1.c9.io/phpmyadmin

這個就是phpmyadmin的連結,直接點選連結就行哩,BTW,一開始是沒有預設密碼的。



Cloud9-RoR-mysql安裝篇

在Cloud9的視窗下方,有個「bash-帳號-專案-不知名編號」的視窗,輸入下方連結的指令

https://docs.c9.io/docs/setup-a-database 官網提供的文件


安裝mysql

$ mysql-ctl install

不過本來就有安裝了,所以會先stop然後在starting,然後秀出

MySQL 5.5 database added.  Please make note of these credentials:

Root User: username
Database Name: c9

mysql的使用ip是127.0.0.1,port則是3306。

控制mysql

$ mysql-ctl cli
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 24
Server version: 5.5.37-0ubuntu0.14.04.1 (Ubuntu)

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.

mysql>  show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| c9                 |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.15 sec)

接著就是安裝phpmyadmin了,下一篇唄。(先不做,apache會與rails衝途)






Cloud9-RoR-創建與刪除專案

Create專案
https://docs.c9.io/docs/create-a-workspace

Delete專案
https://docs.c9.io/v1.0/docs/deleting-a-workspace