Ubuntu 14.04 で、ruby on rails passenger をインストールして apache 連携する

passenger インストール cd ~/ rbenv exec gem install passenger rbenv rehash passenger-install-apache2-module実行 rbenv exec passenger-install-apache2-module passenger-install-apache2-module 詳細 This installer will guide you through the entire installation process. It shouldn't take more than 3 minutes in total. Here's what you can expect from the installation process: 1. The Apache 2 module will be installed for you. 2. You'll learn how to configure Apache. 3. You'll learn how to deploy a Ruby on Rails application. Don't worry if anything goes wrong. This installer will advise you on how to solve any problems. Press Enter to continue, or Ctrl-C to abort. Enter 入力 -------------------------------------------- Which languages are you interested in? Use <space> to select. If the menu doesn't display correctly, press '!' ? ? Ruby ? Python ? Node.js ? Meteor ! 入力 上下でカーソルを移動できる > (*) Ruby (*) Python (*) Node.js ( ) Meteor Ruby を選択し、Enter 入力 -------------------------------------------- Checking for required software... * Checking for C compiler... Found: yes Location: /usr/bin/cc * Checking for C++ compiler... Found: yes Location: /usr/bin/c++ * Checking for Curl development headers with SSL support... Found: no Error: Cannot find the `curl-config` command. * Checking for OpenSSL development headers... Found: yes Location: /usr/include/openssl/ssl.h * Checking for Zlib development headers... Found: yes Location: /usr/include/zlib.h * Checking for Apache 2... Found: yes Location of httpd: /usr/sbin/apache2 Apache version: 2.4.7 * Checking for Apache 2 development headers... Found: no * Checking for Rake (associated with /home/[loginusername]/.rbenv/versions/2.1.2/bin/ruby)... Found: yes Location: /home/[loginusername]/.rbenv/versions/2.1.2/bin/ruby /home/[loginusername]/.rbenv/versions/2.1.2/bin/rake * Checking for OpenSSL support for Ruby... Found: yes * Checking for RubyGems... Found: yes * Checking for Ruby development headers... Found: yes Location: /home/[loginusername]/.rbenv/versions/2.1.2/include/ruby-2.1.0/ruby.h * Checking for rack... Found: yes * Checking for Apache Portable Runtime (APR) development headers... Found: no * Checking for Apache Portable Runtime Utility (APU) development headers... Found: no Some required software is not installed. But don't worry, this installer will tell you how to install them. Press Enter to continue, or Ctrl-C to abort. Enter 入力 -------------------------------------------- Installation instructions for required software * To install Curl development headers with SSL support: Please run apt-get install libcurl4-openssl-dev or libcurl4-gnutls-dev, whichever you prefer. * To install Apache 2 development headers: Please install it with apt-get install apache2-threaded-dev * To install Apache Portable Runtime (APR) development headers: Please install it with apt-get install libapr1-dev * To install Apache Portable Runtime Utility (APU) development headers: Please install it with apt-get install libaprutil1-dev If the aforementioned instructions didn't solve your problem, then please take a look at the Users Guide: /home/[loginusername]/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/passenger-4.0.53/doc/Users guide Apache.html https://www.phusionpassenger.com/documentation/Users%20guide%20Apache.html ガイドに従い、必要なパッケージをインストールする sudo apt-get install libcurl4-openssl-dev apache2-threaded-dev libapr1-dev libaprutil1-dev 再度インストールコマンド実行 rbenv exec passenger-install-apache2-module 再度エラーが出る場合は、パッケージインストール、passenger-install-apache2-module を エラーがなくなるまで、繰り返す エラーがなくなると、自動でコンパイルが始まる 最後に以下が表示される -------------------------------------------- Almost there! Please edit your Apache configuration file, and add these lines: LoadModule passenger_module /home/[loginusername]/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/passenger-4.0.53/buildout/apache2/mod_passenger.so <IfModule mod_passenger.c> PassengerRoot /home/[loginusername]/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/passenger-4.0.53 PassengerDefaultRuby /home/[loginusername]/.rbenv/versions/2.1.2/bin/ruby </IfModule> After you restart Apache, you are ready to deploy any number of web applications on Apache, with a minimum amount of configuration! Press ENTER to continue. 上記をコピーし、控えておく 再度表示したい場合は、rbenv exec passenger-install-apache2-module --snippetを実行すると 上記と同じものが表示される Enter 入力 -------------------------------------------- Deploying a web application: an example Suppose you have a web application in /somewhere. Add a virtual host to your Apache configuration file and set its DocumentRoot to /somewhere/public: <VirtualHost *:80> ServerName www.yourhost.com # !!! Be sure to point DocumentRoot to 'public'! DocumentRoot /somewhere/public <Directory /somewhere/public> # This relaxes Apache security settings. AllowOverride all # MultiViews must be turned off. Options -MultiViews # Uncomment this if you're on Apache >= 2.4: #Require all granted </Directory> </VirtualHost> And that's it! You may also want to check the Users Guide for security and optimization tips, troubleshooting and other useful information: /home/[loginusername]/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/passenger-4.0.53/doc/Users guide Apache.html https://www.phusionpassenger.com/documentation/Users%20guide%20Apache.html Enjoy Phusion Passenger, a product of Phusion (www.phusion.nl) :-) https://www.phusionpassenger.com Phusion Passenger is a trademark of Hongli Lai & Ninh Bui. 最後にapache バーチャルホスト設定のサンプルも表示されるので、控えておく ...

2014-11-14 ·  2014-11-14 · 4 分 · 755 文字

Ubuntu 14.04 libwebsockets クライアントを試す

libwebsockets build sudo aptitude install cmake cd ~/works git clone git://git.libwebsockets.org/libwebsockets cd libwebsockets/ mkdir build cd build cmake .. make -j8 # sudo make install サンプルとして作成したサーバに libwebsocket-test-echo サンプルからアクセスする server rails 上に em-websocket を実装したcontrollerを用意する ※ rails に関しては、省略 Ubuntu 14.04 libwebsockets クライアントを試す libwebsockets build sudo aptitude install cmake cd ~/works git clone git://git.libwebsockets.org/libwebsockets cd libwebsockets/ mkdir build cd build cmake .. make -j8 # sudo make install サンプルとして作成したサーバに libwebsocket-test-echo サンプルからアクセスする server rails 上に em-websocket を実装したcontrollerを用意する ※ rails に関しては、省略 gem settings cd ~/works/test_rails vim GemFile ----------------- 以下を追加 gem 'em-websocket' gem install bundle update mod controller 任意のcontrollerに以下を追加 require "em-websocket" ~ 省略 ~ connections = EM::Channel.new EM::WebSocket.start(host: "[server address]", port: 3001) do |ws_conn| ws_conn.onopen do puts "connected" # EventMachine#subscribeを用い、コネクションオブジェクトと処理を登録 connections.subscribe{|message| ws_conn.send(message) } end ws_conn.onmessage do |message| # onopen内で登録した処理を呼び出し puts "received:" + message connections.push(message) end end ...

2014-10-03 ·  2014-10-03 · 2 分 · 224 文字

Ubuntu 14.04 rails scoffoldでEntity作成、からDB migrateまで

以下のような形式で generate できる bundle exec rails generate scaffold [entity_name] [column_name]:[data_type][column_name]:[data_type] # 間違えたら! bundle exec rails destroy scaffold "name" data type integer, string, timestamp などなどが使える Generateした各ファイルをそれぞれ条件を追加するように、下記のように修正 db/migrate/YYYYMMDDhhmmss_create_[entity_name].rb 以下のように、NotNullや桁指定、デフォルト指定ができる class CreateEvents < ActiveRecord::Migration def change create_table :[entity_name] do |t| t.string :column_name, :null => false, :limit => 1, :default => 0 t.timestamps end end end 作成した rb ファイルで、DB再作成 # 通常DB作成 # bundle exec rake db:migrate # DB再作成(db/schema.rb より再実行) # bundle exec rake db:reset # DB再作成(db/migrate/**.rb より再実行) # →今回は追加する形であるので、以下を実行する # →DROP→CREATEされる bundle exec rake db:migrate:reset サーバ立ち上げ bundle exec rails server

2014-10-03 ·  2014-10-03 · 1 分 · 86 文字

Ubuntu 14.04 ruby2.1.2 で ActiveRecord4.1.6 を使用し、postgresql4.1.6 へアクセス

まずはdatabase 確認 sudo su postgres -c psql install activerecord,pg mkdir -p ~/works/99_sample/02_activerecord cd ~/works/99_sample/02_activerecord gem install activerecord gem install pg gem list DBユーザtest_nameを作成しておく sudo su postgres -c psql create role test_name superuser login; \password test_name Enter new password: test_name Enter it again: test_name create database test_name; config/database.yml mkdir -p config && vim config/database.yml db: production: adapter: postgresql host: localhost username: test_name password: test_name database: test_name development: adapter: postgresql host: localhost username: test_name password: test_name database: test_name db/migrate配下に、3ファイルを配置(rails環境からコピー) mkdir -p db/migrate ...

2014-10-03 ·  2014-10-03 · 1 分 · 130 文字

Ubuntu 14.04 で websocket, zeroMQ

rails 、postgresql、zeroMQ、websocketを使って通信するサンプル環境を作成中 create rails project cd 任意のディレクトリ rails new test_rails_postgres -d postgresql cd test_rails_postgres bundle install --path vendor/bundle bundle exec rake db:create db:migrate テスト起動確認 cd test_rails_postgres rails server http://[サーバアドレス]:3000へアクセス git 管理開始 cd test_rails_postgres git init vim .gitignore 以下を追加 doc/ *.swp *~ .project .DS_Store .idea .secret git add . git commit -m "initial commit." テスト設定 bundle exec rails generate scaffold book title:string author:string outline:text bundle exec rake db:migrate bundle exec rails server db確認 -- database list \l -- user list select * from pg_user; -- table list \d routes の確認 http://localhost:3000/rails/info/routes rails へwebsocket実装 websocket-rails install cd test_rails_postgres vim Gemfile # 以下を追加 gem 'websocket-rails' bundle install rails g websocket_rails:install # コントローラ作成 vim app/controllers/websocket_chat_controller.rb # WebsocketRails::BaseControllerを継承 class WebsocketChatController < WebsocketRails::BaseController def message_recieve # クライアントからのメッセージを取得 recieve_message = message() # websocket_chatイベントで接続しているクライアントにブロードキャスト broadcast_message(:websocket_chat, recieve_message) end end vim config/events.rb WebsocketRails::EventMap.describe do # websocket_chatイベントのマッピング subscribe :websocket_chat, to: WebsocketChatController, with_method: :message_recieve end # クライアント rails g controller chat index vim app/views/chat/index.html.erb 以下追加 <!-- チャット表示部分 --> <ul id="chat_area"> </ul> <!-- コメントフォーム --> <input id="comment" type="text"> <input id="send" type="button" value="send"> <script> var ws_rails = new WebSocketRails("[url]:3000/websocket"); // メッセージ受信時の処理 ws_rails.bind("websocket_chat", function(message){ var message_li = document.createElement("li"); message_li.textContent = message; document.getElementById("chat_area").appendChild(message_li); }) // メッセージ送信時の処理 document.getElementById("send").onclick = function(){ var comment = document.getElementById("comment").value; ws_rails.trigger("websocket_chat", comment); } </script> vim config/environments/development.rb # 以下を追加 config.middleware.delete Rack::Lock test websocket client作成 gem install gem install websocket-client-simple client program(動かない) vim websocket_client.rb require 'rubygems' require 'websocket-client-simple' ws = WebSocket::Client::Simple.connect '[url]:3000/websocket' ws.on :message do |msg| puts msg.data end ws.on :open do ws.send 'hello!!!' end ws.on :close do |e| p e exit 1 end loop do ws.send STDIN.gets.strip end execjs install(不要) gem install execjs zeromq install cd 任意のディレクトリ git clone https://github.com/zeromq/zeromq4-x.git cd zeromq4-x # git checkout origin/v4.0.1 sudo aptitude install libtool autoconf uuid-dev ./autogen.sh #./configure --prefix=/usr/local/zmq ./configure make sudo make install ZeroMQ導入 vim Gemfile -------------------- # Use zeroMq gem 'rbzmq' #gem 'ffi-rzmq' #gem 'zqm' ffi-rzmqのバージョンが合っている2.0.1が要る? rails コントローラにZMQスレッドを立ち上げる vim websocket_chat_controller.rb --------------------------------------------------- require 'rbzmq' # WebsocketRails::BaseControllerを継承 class WebsocketChatController < WebsocketRails::BaseController context = ZMQ::Context.new publisher = context.socket ZMQ::PUB publisher.bind "tcp://*:5563" begin t = Thread.new do Thread.pass # メインスレッドが確実にjoinするように puts "[rails] Tread loop start." loop do publisher.send_string 'A', ZMQ::SNDMORE publisher.send_string "We don't want to see this." publisher.send_string 'B', ZMQ::SNDMORE publisher.send_string "We would like to see this." sleep 1 end publisher.close raise "unhandled exception" end t.join rescue p $! # => "unhandled exception" end puts "[rails] WebsocketChatController is started!!!!!" def message_recieve # クライアントからのメッセージを取得 recieve_message = message() puts "[rails] server message receive and broadcast => #{recieve_message}" # websocket_chatイベントで接続しているクライアントにブロードキャスト broadcast_message(:websocket_chat, recieve_message) end end rails server立ち上げ bundle exec rails server em-websocket in rails vim websocket_chat_controller.rb require “em-websocket” # 省略 puts “rails emwebsocket server start” # 配列ではなくEventMachineオブジェクトを生成 connections = EM::Channel.new EM::WebSocket.start(host: “172.19.1.94”, port: 3001) do |ws_conn| ws_conn.onopen do puts “connected” # EventMachine#subscribeを用い、コネクションオブジェクトと処理を登録 connections.subscribe{|message| ws_conn.send(message) } end ws_conn.onmessage do |message| # onopen内で登録した処理を呼び出し puts “received:” + message connections.push(message) end end

2014-10-03 ·  2014-10-03 · 3 分 · 454 文字