2012年8月1日水曜日

[Rails][Linux]Apache+Passengerを入れる

このエントリーをはてなブックマークに追加 Clip to Evernote


WEBrickを起動したけど、ブラウザ接続できなかったので、おとなしくPassengerを入れることにした。


参考にさせていただきましたm(__)m
ApacheをWEBサーバとして利用

まずは、passengerをインストール


$ gem install passenger
Fetching: fastthread-1.0.7.gem (100%)
Building native extensions.  This could take a while...
Fetching: daemon_controller-1.0.0.gem (100%)
Fetching: passenger-3.0.15.gem (100%)
Successfully installed fastthread-1.0.7
Successfully installed daemon_controller-1.0.0
Successfully installed passenger-3.0.15
3 gems installed
Installing ri documentation for fastthread-1.0.7...
Installing ri documentation for daemon_controller-1.0.0...
Installing ri documentation for passenger-3.0.15...
Installing RDoc documentation for fastthread-1.0.7...
Installing RDoc documentation for daemon_controller-1.0.0...
Installing RDoc documentation for passenger-3.0.15...


対話式でモジュールをインストール
$ passenger-install-apache2-module
なんかいろいろ入ってないよー。でも心配しないで!
足りないやつをインストールする方法教えるから!
みたいなこと言われます。親切ですね。


私の環境で足りなかったのは以下。


Installation instructions for required software


 * To install Curl development headers with SSL support:
   Please download Curl from http://curl.haxx.se/libcurl and make sure you install it with SSL support.


 * To install Apache 2 development headers:
   Please download it from http://httpd.apache.org/


 * To install Apache Portable Runtime (APR) development headers:
   Please download it from http://httpd.apache.org/
   (APR is an integrated part of Apache.)


 * To install Apache Portable Runtime Utility (APU) development headers:
   Please download it from http://httpd.apache.org/
   (APR Utility is an integrated part of Apache.)


まずは、curlをインストール
$ sudo yum install curl-devel


次、Apache 2 development headers
$ sudo yum install httpd-devel


んで、もう一回モジュールをインストールする。
成功すると、httpd.conf とかにいろいろ書くんだよーと教えてくれるので、メモしましょう。


The Apache 2 module was successfully installed.


Please edit your Apache configuration file, and add these lines:


   LoadModule passenger_module /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.15/ext/apache2/mod_passenger.so
   PassengerRoot /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.15
   PassengerRuby /usr/local/ruby/bin/ruby


After you restart Apache, you are ready to deploy any number of Ruby on Rails
applications on Apache, without any further Ruby on Rails-specific
configuration!


Press ENTER to continue.


--------------------------------------------
Deploying a Ruby on Rails application: an example


Suppose you have a Rails 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
      </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:


  /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.15/doc/Users guide Apache.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のhttpd.confに、


   LoadModule passenger_module /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.15/ext/apache2/mod_passenger.so
   PassengerRoot /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.15
   PassengerRuby /usr/local/ruby/bin/ruby


   <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
      </Directory>
   </VirtualHost>


を書いたら、apacheを再起動


$ service httpd restart


http://ドメイン/ にアクセスし、Welcome aboard の画面が出たら成功!


ようやっとできた~

[Rails][Linux]ちょっぱやでブログサイトを作る

このエントリーをはてなブックマークに追加 Clip to Evernote

なによりも動かさないことにはわからん。
ので、Railsでよく紹介される、ちょっぱやでブログサイトを作ってみる。


がっつり参考にさせていただきました。


簡単!Rails3.2を使って10分でブログアプリを構築する方法
http://dqn.sakusakutto.jp/2012/03/rails32blog.html


まずは、プロジェクト(アプリケーション)を作成
$ rails new project(プロジェクト名)
$ cd project
$ vi GemFile


GemFileを編集して以下追加
$ gem 'execjs'
$ gem 'therubyracer'


サーバ起動
$ rails server
Could not find gem 'therubyracer (>= 0) ruby' in the gems available on this machine.
Run `bundle install` to install missing gems.


ええー


therubyracerがgemに登録されてないんだって。ましーんにないんだってさ。
懲りずに入れましょう。
$ gem install therubyracer
Fetching: libv8-3.3.10.4-x86_64-linux.gem (100%)
Fetching: therubyracer-0.10.1.gem (100%)
Building native extensions.  This could take a while...
Successfully installed libv8-3.3.10.4-x86_64-linux
Successfully installed therubyracer-0.10.1
2 gems installed
Installing ri documentation for libv8-3.3.10.4-x86_64-linux...
Installing ri documentation for therubyracer-0.10.1...
Installing RDoc documentation for libv8-3.3.10.4-x86_64-linux...
Installing RDoc documentation for therubyracer-0.10.1...


無事完了。


サーバ起動に再びトライ
rails server
=> Booting WEBrick
=> Rails 3.2.7 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-07-31 16:42:04] INFO  WEBrick 1.3.1
[2012-07-31 16:42:04] INFO  ruby 1.9.3 (2012-04-20) [x86_64-linux]
[2012-07-31 16:42:04] INFO  WEBrick::HTTPServer#start: pid=8141 port=3000


なんかよさそう。


http://localhost:3000/
にアクセスして、Welcome aboard画面が出ればOK


って出ません!!!Σ(´∀`;)


なんか別の理由っぽい気がするので


続きはまた次回。。

[Rails][Linux]Railsアプリケーションを作成する

このエントリーをはてなブックマークに追加 Clip to Evernote
環境設定が終わったら、次はアプリケーションの作成\(^o^)/


rails new プロジェクト名 で基本的なディレクトリや各種スクリプトが生成される。


$ rails new プロジェクト名
      create
      create  README.rdoc
      create  Rakefile
      create  config.ru
      create  .gitignore
      create  Gemfile
      create  app
      create  app/assets/images/rails.png
      create  app/assets/javascripts/application.js
      --(省略)--


でろでろといろいろ生成してくれます。


と思ってたら、
An error occured while installing sqlite3 (1.3.6), and Bundler cannot continue.
Make sure that `gem install sqlite3 -v '1.3.6'` succeeds before bundling.


なんてエラーが出てた。。
要は、sqlite3がないよーーと言いたいのね。
今回は特にDBにはこだわってないので、sqliteを入れることにしよう。


実行しろと言ってるコマンドを実行


$ gem install sqlite3 -v '1.3.6'


そしてまたエラー。。


Building native extensions.  This could take a while...
ERROR:  Error installing sqlite3:
        ERROR: Failed to build gem native extension.


        /usr/local/ruby/bin/ruby extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal'
or 'yum install sqlite-devel' and check your shared library search path (the
location where your sqlite3 shared library is located).
*** extconf.rb failed ***


なんかyumで入れてから実行しろやってこと??


お望み通り実行
$ sudo yum install sqlite-devel
(省略)
Downloading Packages:
sqlite-devel-3.6.20-1.8.amzn1.x86_64.rpm                 |  79 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : sqlite-devel-3.6.20-1.8.amzn1.x86_64                         1/1


Installed:
  sqlite-devel.x86_64 0:3.6.20-1.8.amzn1


Complete!


はい、入りましたよー


で、もう一回。


$ gem install sqlite3 -v '1.3.6'
Building native extensions.  This could take a while...
Successfully installed sqlite3-1.3.6
1 gem installed
Installing ri documentation for sqlite3-1.3.6...
Installing RDoc documentation for sqlite3-1.3.6...


今度はうまくいったみたい。


というわけで、今度こそプロジェクト作成コマンド実行。


Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.


成功ー!!


どうやらカレントディレクトリの配下にアプリケーションが生成されるので、
/var/www/ の下など、任意の場所に作ると良いみたいです。

[Rails][Linux]Railsをインストールする

このエントリーをはてなブックマークに追加 Clip to Evernote

Linux環境にRailsをインストール

私はいつぞやか立てたAWSのサーバを使用しています。

まずは作業用ディレクトリを作成
$ mkdir ruby_install_workdir
$ cd ruby_install_workdir

Rubyの公式サイトから最新のソースコードをダウンロード
$ wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz

圧縮ファイルを展開する
$ tar zxvf ruby-1.9.3-p194.tar.gz

展開したら移動
$ cd ruby-1.9.3-p194

rubyをコンパイルしてインストール
$ ./configure --prefix=/usr/local/ruby

とここでエラー。。
$ ./configure --prefix=/usr/local/ruby
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/home/---/ruby_install_workdir/ruby-1.9.3-p194':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details

どうやらコンパイラーがないらしい。
http://news.trippyboy.com/serversmanvps/serversmanvps-configure-error-no-acceptable-c-compiler-found-in-path/

sudo yum -y install gcc
でインストール

で、気を取り直してもう一回。
$ ./configure --prefix=/usr/local/ruby
--省略--
checking for pthread.h... yes
checking for if make is GNU make... ./configure: line 17125: make: command not found
no
checking for safe null command for make... configure: error: no candidate for safe null command
まさかのmakeがインストールされていない件orz
慌てずyumでインストール
$ sudo yum install make

で、気を取り直してもう一回。
$ ./configure --prefix=/usr/local/ruby
$ make
$ sudo make install
結構時間が掛かるので、のんびりしましょう。

コマンド実行が出来るように環境変数PATHを設定しておく
$ export PATH=/usr/local/ruby/bin:$PATH

rubyのバージョンを確認
$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]

最後にRailsをインストール
$ sudo gem install rails

libyamlがないYO!と言い出したので、そいつもインストール
http://maeda.farend.ne.jp/blog/2012/03/10/ruby-missing-pysh/
$ sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
$ sudo yum install libyaml-devel

YAMLもないって言い出した。。うう
$ wget http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz
$ ./configure
$ make
# make install

どうやら、AmazonLinuxの素の状態だと、いろいろ足りないらしいので、他にもコケないよういれておく
http://d.hatena.ne.jp/the_yokochi/20111127/1322382198
$ sudo yum groupinstall "Development Tools"
$ sudo yum install openssl-devel readline-devel zlib-devel libyaml-devel

再度rubyをコンパイルする。
終わったらgemが使用出来るか確認
$ gem -v
1.8.23

最後にRailsをインストール
$ gem install rails

Railsのバージョンを確認
$ rails -v

長かった。。。