【Smarty】SmartyのインストールからHelloWorldまで
PHPのテンプレートエンジンSmartyをインストールして、HelloWorldをブラウザ上に表示するまでの方法を記述します。
[環境]
Windows10
PHP 5.6.20
Smarty 3.1.30
手順
1. Smartyのインストール
Smartyを公式サイトからダウンロードします。
http://www.smarty.net/docsv2/ja/
ダウンロードしたファイルを解凍したら、php/includes/に配置します。 (includesが存在しなければ作成します。)
C:/php/includes/Smarty
次にphp.iniのinclude_pathのコメントを外して有効にします。
include_path = ".c:¥php¥includes"
phpinfo関数で有効になったことを確認できます。
<?php phpinfo();
ブラウザからアクセスして、include_pathがphp\includesとなっていればOKです。
2. ディレクトリを構成
実際にSmartyを利用するアプリのディレクトリを構成します。
必須となるのはSmartyのテンプレートを格納するディレクトリと、テンプレートのコンパイル結果を格納するディレクトリです。
ここではそれぞれtpl、tpl_cとします。
プロジェクト名/smarty/tpl プロジェクト名/smarty/tpl_c
次にドキュメントルートとなるディレクトリを作成します。
ここではpublishとします。
プロジェクト名/publish
3. テンプレートを作成する
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Hello World!</title> </head> <body> Hello {$name}! </body> </html>
{$name}にPHPファイルから渡されたデータが出力されます。
4. phpファイルからテンプレートを呼び出す
Smartyクラスを読み込んでテンプレートに渡したい値などを設定します。
<?php // Smartyクラスを読み込む require_once("Smarty/libs/Smarty.class.php"); // Smartyのインスタンスを生成し、 // テンプレートディレクトリと // コンパイルディレクトリを読み込む $smarty = new Smarty(); $smarty->template_dir = "../smarty/templates/"; $smarty->compile_dir = "../smarty/templates_c/"; // assignメソッドを使ってテンプレートに渡す値を設定 $smarty->assign("name", "World"); // テンプレートを表示する $smarty->display("hello.tpl");
5. サーバーを起動する
ビルトインサーバーを起動してブラウザからアクセスします。
$ php -S localhost:9000
【Vagrant】VagrantでCentOSのLAMP環境を構築する
前回に引き続きVagrantです。
Lamp環境を構築します。
[環境]
Windows10
Vagrant 1.9.4
VirtualBox 5.1.22
CentOS 6.4
Apache 2.2.15
MySQL 5.1.73
PHP 5.3.3
手順
1. VagrantでCentOSを立てる
前回記事を参考にしてください。
【Vagrant】VagrantでWindows10にCentOSを立てる - さの、ブログやるってよ
2. Apacheをインストールする
$ sudo yum install httpd
private_networkを有効にする
vagrant upを実行したディレクトリのVagrantfileのprivate_networkのコメントを外します。
config.vm.network "private_netowork", ip: "192.168.33.10"
private_networkを有効にすると、ホストPCとゲストPCの間でだけで有効なプライベートIPが割り振られます。
Vagrantfileを変更したら、ホスト側でreloadコマンドを実行します。
$ vagrant reload
Apacheの実行
private_networkを有効にしたらApacheを起動します。
$ sudo service httpd start
ホスト側のブラウザで192.168.33.10にアクセスして、Apache2 Test Pageが表示されたら成功です。
3. MySQLとPHPをインストールする
$ sudo yum install php $ php -v # バージョンが表示されたらOK
$ sudo yum install mysql-server $ sudo service mysqld start # 正常にスタートされたらOK
以上でLAMP環境が整いました。
4. 共有フォルダ設定
VagrantではホストPCとゲストPCの間で共有ディレクトリを設定することができます。
これにより、作成したファイルをscpする手間を省くことができます。
VagrantfileのSynced_folderのコメントを外します。
config.vm.Synced_folder "../data", "/vagrant_data"
第1引数でホスト側、第2引数でゲスト側のディレクトリを指定します。
ゲスト側のディレクトリは自動で作成されますが、ホスト側は自作しないといけないので注意してください。
Vagrantfileを書き換えたのでreloadコマンドを実行します。
$ vagrant reload
共有フォルダにシンボリックリンクを設定する
共有ディレクトリにシンボリックリンクを設定することで作成したファイルをすぐに公開することができます。
$ rm -rf /var/www/html $ ln -fs /vagrant_data /var/www/html $ sudo service httpd start
ホスト側で共有ディレクトリにPHPファイルを作成してみましょう。
<?php echo "Hello World!";
ブラウザで192.163.33.10にアクセスし、Hello World!が表示されたら成功です。
【Vagrant】VagrantでWindows10にCentOSを立てる
以下の環境で、VirtualBox上にCenOSを起動します。
[環境]
Windows10
Vagrant 1.9.4
VirtualBox 5.1.22
CentOS 6.4
手順
1. VirtualBoxをインストール
以下のサイトからダウンロードします。
「Windows hosts」となっているものを選択しましょう。
https://www.virtualbox.org/
2. Vagrantをインストール
以下のサイトからダウンロードします。
https://www.vagrantup.com/
3. Puttyをインストール
PuttyはWindows対応のSSHクライアントです。
TeraTearm等でも代用できます。
以下のサイトからダウンロードします。
http://ice.hotmint.com/putty/
4. VAGRANT_HOME設定
Windowsのユーザー名を日本語で設定している場合、正常に動作しないことがあります。
環境変数にVAGRANT_HOMEを追加し、日本語を含まないパスを設定します。
5. VagrantでCentOSを起動する
以下の手順でCentOSを起動します。
VagrantにBoxを追加する
VagrantではBoxという単位でOSイメージを扱います。
以下のサイトから対象のOSを選択し、URLをコピーします。
http://www.vagrantbox.es/
$ vagrant box add CentOS_6_4 https://github.com/2creatives/vagrant-centos/releases/download/v6.4.2/centos64-x86_64-20140116.box
ダウンロードが完了したら、listコマンドで確認できます。
$ vagrant box list
Vagrantfileを作成する
Vagrantfileには仮想マシンの設定が記述されます。
任意のディレクトリに移動し、initコマンドを実行してVagrantfileを作成します。
$ vagrant init CentOS_6_4
CentOSを起動する
以下のコマンドでCentOSを起動します。
$ vagrant up
5. CentOSに接続する
Puttyを起動して、以下の通りに接続します。 - Host Name : 127.0.0.1 - Port : 2200
接続先でログインIDとパスワードを聞かれるので入力します。 - login as : vagrant - password : vagrant
停止する場合はホスト側でhaltコマンドを実行します。
$ vagrant halt
【Ruby】Moduleをincludeするとはどういうことか
RubyではModuleを読み込むのに複数の方法があります。
include、prepend、extendなどが挙げられます。
何気なく使っていませんか?
とんでもない落とし穴があるかもしれません。
実際に内部でどういった処理が行われているのか、それぞれの違いを確認してみましょう。
include
おそらくModuleを勉強した時に一番最初に見るのがincludeかと思います。
Moduleをクラスにincludeすると、クラスにModuleで定義したメソッドが追加されます。
これはModuleをもとにして作成された無名クラスを、includeしたクラスの親として継承することで実現しています。
module M1 end class C1 include M1 end C1.ancestors #[C1, M1, Object, Kernel, BasicObject]
C1の親にM1が設定されているのがわかると思います。
そのため、M1で定義されたメソッドはC1で定義されたメソッドでオーバーライドされます。
module M1 def greet puts "hello" end end class C1 include M1 def greet puts "hi" super end end C1.new.greet #hi #hello
superメソッドはオーバーライドされたメソッドを呼び出します。
後から"hello"が表示されたことでM1のgreetメソッドがオーバーライドされていることがわかります。
ただし、Module内で定義された特異メソッドは継承されないので注意が必要です。
module M1 def self.lough puts "hahaha" end end class C1 include M1 end M1.lough #hahaha C1.lough #NoMethodError
特異メソッドはM1ではなく、M1の特異クラスに定義されているため、無名クラスに定義が反映されないためです。
prepend
prependはincludeとよく似ていますが、継承の順番が変わります。
module M2 end class C2 prepend M2 end C2.ancestors #[M2, C2, Object, Kernel, BasicObject]
M2の方が子になっているのがわかると思います。
そのため、includeとは逆で、C2で定義されたメソッドはM2で定義されたメソッドでオーバーライドされます。
module M2 def greet puts "hello" super end end class C2 prepend M2 def greet puts "hi" end end C2.new.greet #hello #hi
prependはモジュールの処理を優先したい場合に使います。
extend
includeとprependはモジュールを継承関係に組み込んでいたのに対し、extendはクラスとインスタンスの関係に組み込みます。
module M3 def greet puts "hello" end end class C3 extend M3 def greet puts "hi" end end C3.greet #hello C3.new.greet #hi C3.ancestors #[C3,Object,Kernel,BasicObject]
継承関係にM3が存在しないことがわかります。
ところで、先ほどのgreetをクラスメソッドにしたらどうなるでしょうか。
module M4 def greet puts "hello" end end class C4 extend M4 def self.greet "hi" end end C4.greet #hi
クラスで定義したメソッドでOverrideされました。
クラスメソッドは特異クラスに定義されますので、それがOverrideされたということはその特異クラスの親クラスとしてモジュールが組み込まれているということがわかります。
特異クラスの継承関係を見てみましょう。
C4.singleton_class.ancestors #[#<Class:C4>, M4, #<Class:Object>, Class, Module, Object, Kernel, BasicObject]
※#<Class:インスタンス名>はそのインスタンスの特異クラスを表します。
C4で定義したクラスメソッドは#<Class:C4>のインスタンスメソッドとして定義されるため、M4で定義されているgreetをOverrideしたという形になっています。
include、prepend、extendを理解することで、意図しないOverrideをしないように気をつけましょう。
【Ruby】非常に強力なRubyのクラス構成
Rubyのクラス構成は非常にシンプルで強力です。
クラス構成を理解することがそのままRubyを理解することにつながります。
Classクラス
RubyにはClassクラスというものが定義されています。
Rubyの組み込みクラスは全てClassクラスのインスタンスになります。
例えばObjectクラスやStringクラスなどがClassクラスのインスタンスです。
"Hello".class #String String.class #Class Object.class #Class
Rubyでは全てのクラスがnewメソッドを持っていますが、もちろん全てのクラスでnewメソッドを定義しているわけではありません。
Classクラスに定義して、それぞれのクラスで使用しています 。
Classクラスのメソッドを見ると、先程挙げたnewメソッドなど、クラスで共通して使われるメソッドが定義されていることがわかります。
Class.methods #[:nesting, :constants, :allocate, :new, :superclass 他省略
以下に図でClassとインスタンスの関係を示します。
特異メソッドとクラスメソッド
ところで、Rubyには特異メソッドというものがありました。
これはインスタンスに特有の振舞いを追加するものです。
class Test end a = Test.new b = Test.new #特異メソッド定義 def a.say_hello puts "Hello" end a.say_hello # Hello b.say_hello # NoMethodError
全てのクラスはClassクラスのインスタンスなので、クラスにも同様にして特異メソッドを定義できます。
class Test end #特異メソッド定義 def Test.say_bye puts "Bye" end Test.say_bye #bye String.say_bye #NoMethodError
クラスの特異メソッドとクラスメソッドは同じものであることに気がつくと思います。 クラスメソッドの定義方法を再度確認してみましょう。
class Test #クラスメソッド定義 def self.say_bye puts "Bye" end end Test.say_bye #bye String.say_bye #NoMethodError
インスタンス名がselfに変わっただけで、特異メソッドの定義方法と同様であることがわかります。
特異メソッドの定義場所
インスタンスがメソッドを呼び出すにはクラスに定義する必要があります。
では特異メソッドはどこに定義されているのでしょうか。
Rubyではインスタンス生成時に特異クラスというそのインスタンス専用のクラスを生成し、継承させています。
想像しづらいと思いますので図解します。
"Hello"という文字列はStringクラスのインスタンスですが、インスタンス生成時に"Hello"インスタンス専用のクラスが生成されます。
このクラスはStringクラスを継承しています。
これを"Hello"インスタンスの特異クラスといい、特異メソッドを定義するとこのクラスにインスタンスメソッドが定義されます。
特異クラスはsingleton_classというメソッドで確認できます。
特異クラスに定義されているメソッドを見てみましょう。
class Test end c = Test.new #特異メソッド定義 def c.say_hoge puts "hoge" end c.singleton_class.instance_methods false #[:say_hoge]
特異メソッドが特異クラスに定義されていることがわかります。
特異クラスはインスタンスのクラスと継承関係にあるので同名のメソッドはオーバーライドされます。
class Test def say_your_name puts "Test" end end d = Test.new def d.say_your_name puts "d" end d.say_your_name #d
Mix-inもそうでしたが、Rubyの処理はほとんどが継承関係、またはクラスとインスタンスの関係で説明がつきます。
このシンプルな構成がRubyの魅力の一つです。
【Ruby】Mix-inは継承なのか
Mix-inは継承なのか
RubyのMix-inの挙動は継承とよく似ています。
superメソッドを使って確認してみましょう。
module Greetable def say_hello p "Hello Greetable" end end class Human include Greetable def say_hello p "Hello Human" super end end Human.new.say_hello #Hello Human #Hello Greetable
Humanクラスのsay_helloメソッドでsuperを使って、オーバーライドされている親クラスのsay_helloメソッドを呼び出しています。
ここで"Hello Greetable"が表示されたので、Moduleを親クラスと認識していることがわかります。
別の角度から見てみましょう。
Moduleにインスタンス変数を宣言してinitializeで値を設定するようにします。
module Greetable @name def initialize @name = "hoge" end end class Human include Greetable def say_hello p "Hello #{@name}" end end Human.new.say_hello #Hello hoge
正常に宣言され、エラーが出ることもなく値も取得できました。
つまり、Moduleのインスタンスが生成されたことになります。
しかしModuleにはnewメソッドが定義されていないため、インスタンスは生成できません。
実際にはModuleを元に生成された無名クラスを継承することでMix-inを実現しています。
ひし形継承問題はあるか
Mix-inが無名クラスの継承だとすると、ひし形継承した場合はどうなるのでしょうか。
module Grandpa @grandpa_name = "" end module Papa include Grandpa def teach_me_papa_grandpa @grandpa_name = "Taro" end end module Mama include Grandpa def teach_me_mama_grandpa @grandpa_name = "Jiro" end end class Me include Papa include Mama def say_grandpa_name p "My grandpa is #{@grandpa_name}" end end me = Me.new me.teach_me_papa_granpa me.teach_me_mama_granpa me.say_grandpa_name # Jiro
MeクラスはPapaクラスとMamaクラスを継承し、PapaクラスとMamaクラスはそれぞれGrandPaクラスを継承しています。
Meクラスのインスタンスが作成される際、父方の祖父と母方の祖父の2つの祖父インスタンスが作成される必要があります。
しかし、インスタンスを2つ作成すると、MeクラスからGrandpaクラスのメンバにアクセスした際にどちらのインスタンスにアクセスすればいいのかわからなくなってしまいます。
逆にインスタンスを1つだけ生成した場合、父も母も1つのインスタンスにアクセスしてしまい、2人の祖父を表現できません。
これがひし形継承問題です。
上記コードでは同じインスタンスにアクセスして値が書き換えられてしまっており、インスタンスを一つしか作っていないことがわかります。
つまり、Mix-inでもひし形継承問題は解決してるとは言えません。
ModuleをClassの代わりに利用するのは危険です。
本来の使い方から逸脱しないようにしましょう。
【Rails】CentOSにRailsを入れよう
CentOS 7(AWSインスタンス)にRails入れるのに大いに時間がかかったのでメモっておきます。
こちら参考にさせていただきました。
rbenv を利用した Ruby 環境の構築 | Developers.IO
まず、gitが入ってる前提とのことなのでyumでインストールします。
$ sudo yum -y install git
次にrbenvを入れます。以下のコマンドを実行します。
$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv $ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile $ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile $ source ~/.bash_profile $ rbenv --version rbenv 1.0.0-19-g29b4da7
※rbenvのクローン先は~/.rbenv推奨です。デフォルトのrootだそうなので。
ここまではサクサクすすみました。
rbenvが入ったので、Rubyをインストールします。
インストールできるRubyのバージョンを確認して、
$ rbenv install --list
2.2.4が見つかったのでインストールします。
$ rbenv install 2.2.4 Downloading ruby-2.2.4.tar.bz2... -> https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.4.tar.bz2 /home/centos/.rbenv/plugins/ruby-build/bin/ruby-build: 209 行: pushd: ruby-2.2.4: そのようなファイルやディレクトリはありません BUILD FAILED (CentOS Linux 7 using ruby-build 20160228-5-g522f3ba) Inspect or clean up the working tree at /tmp/ruby-build.20160315122604.9219 Results logged to /tmp/ruby-build.20160315122604.9219.log Last 10 log lines: /tmp/ruby-build.20160315122604.9219 ~ warning: bzip2 not found; consider installing `bzip2` package tar (child): bzip2: exec 不能: そのようなファイルやディレクトリはありません tar (child): Error is not recoverable: exiting now tar: Child returned status 2 tar: Error is not recoverable: exiting now
ログ見ると、
bzip2 not found; consider installing bzip2
package
とおっしゃってますのでインストールします。
$ sudo yum -y install bzip2
再度、インストールを試します。
$ rbenv install 2.2.4 Downloading ruby-2.2.4.tar.bz2... -> https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.4.tar.bz2 Installing ruby-2.2.4... BUILD FAILED (CentOS Linux 7 using ruby-build 20160228-5-g522f3ba) Inspect or clean up the working tree at /tmp/ruby-build.20160315122847.9303 Results logged to /tmp/ruby-build.20160315122847.9303.log Last 10 log lines: /tmp/ruby-build.20160315122847.9303/ruby-2.2.4 /tmp/ruby-build.20160315122847.9303 ~ checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking target system type... x86_64-pc-linux-gnu checking for gcc... no checking for cc... no checking for cl.exe... no configure: error: in `/tmp/ruby-build.20160315122847.9303/ruby-2.2.4': configure: error: no acceptable C compiler found in $PATH See `config.log' for more details
error: no acceptable C compiler found in $PATH
今度はコンパイラにパス通って無いよって言ってます。
そりゃコンパイラ入れてないですからね。
最初から入れといてよと思いましたが、情弱っぽいのでぐっと我慢してgcc入れます。
$ sudo yum -y install gcc
gccが入ったので今度こそ!
$ rbenv install 2.2.4 Downloading ruby-2.2.4.tar.bz2... -> https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.4.tar.bz2 Installing ruby-2.2.4... BUILD FAILED (CentOS Linux 7 using ruby-build 20160228-5-g522f3ba) Inspect or clean up the working tree at /tmp/ruby-build.20160315123155.9611 Results logged to /tmp/ruby-build.20160315123155.9611.log Last 10 log lines: The Ruby openssl extension was not compiled. The Ruby readline extension was not compiled. The Ruby zlib extension was not compiled. ERROR: Ruby install aborted due to missing extensions Try running `yum install -y openssl-devel readline-devel zlib-devel` to fetch missing dependencies. Configure options used: --prefix=/home/centos/.rbenv/versions/2.2.4 LDFLAGS=-L/home/centos/.rbenv/versions/2.2.4/lib CPPFLAGS=-I/home/centos/.rbenv/versions/2.2.4/include
Try running yum install -y openssl-devel readline-devel zlib-devel
to fetch missing dependencies.
はいはい。
$ sudo yum install -y openssl-devel readline-devel zlib-devel
再々度インストール!
$ rbenv install 2.2.4 Downloading ruby-2.2.4.tar.bz2... -> https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.4.tar.bz2 Installing ruby-2.2.4... Installed ruby-2.2.4 to /home/centos/.rbenv/versions/2.2.4
やっと入りました。
バージョン指定して、ちゃんと入ってるか確認します。
$ rbenv global 2.2.4 $ ruby -v ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-linux]
完璧ですね。
次にbundlerとRails入れましょう。
$ gem install bundle $ gem install rails
ここは流石に簡単に入りますね。
ではアプリをcloneしてきて、bundle installしてみましょう。
※アプリのcloneは省略
$ bundle install Gem::Ext::BuildError: ERROR: Failed to build gem native extension. /home/centos/.rbenv/versions/2.2.4/bin/ruby -r ./siteconf20160315-3608-feu520.rb extconf.rb checking for sqlite3.h... no sqlite3.h is missing. Try 'port install sqlite3 +universal', 'yum install sqlite-devel' or 'apt-get install libsqlite3-dev' and check your shared library search path (the location where your sqlite3 shared library is located). *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. Provided configuration options: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/home/centos/.rbenv/versions/2.2.4/bin/$(RUBY_BASE_NAME) --with-sqlite3-dir --without-sqlite3-dir --with-sqlite3-include --without-sqlite3-include=${sqlite3-dir}/include --with-sqlite3-lib --without-sqlite3-lib=${sqlite3-dir}/lib extconf failed, exit code 1
Try 'port install sqlite3 +universal','yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
とのことなので以下を実行します。
$ sudo yum -y install sqlite-devel
spliteいれたらbundle installが通りました。 いよいよrails sでサーバーを立ち上げます。
$ rails s /home/centos/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:80:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'uglifier'. (Bundler::GemRequireError) from /home/centos/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require' from /home/centos/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `each' from /home/centos/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `block in require' from /home/centos/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `each' from /home/centos/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `require' from /home/centos/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler.rb:99:in `require' from /home/centos/apps/talk_on/config/application.rb:7:in `<top (required)>' from /home/centos/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:78:in `require' from /home/centos/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:78:in `block in server' from /home/centos/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `tap' from /home/centos/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `server' from /home/centos/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!' from /home/centos/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>' from /home/centos/apps/talk_on/bin/rails:9:in `require' from /home/centos/apps/talk_on/bin/rails:9:in `<top (required)>' from /home/centos/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/spring-1.6.4/lib/spring/client/rails.rb:28:in `load' from /home/centos/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/spring-1.6.4/lib/spring/client/rails.rb:28:in `call' from /home/centos/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/spring-1.6.4/lib/spring/client/command.rb:7:in `call' from /home/centos/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/spring-1.6.4/lib/spring/client.rb:28:in `run' from /home/centos/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/spring-1.6.4/bin/spring:49:in `<top (required)>' from /home/centos/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/spring-1.6.4/lib/spring/binstub.rb:11:in `load' from /home/centos/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/spring-1.6.4/lib/spring/binstub.rb:11:in `<top (required)>' from /home/centos/.rbenv/versions/2.2.4/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require' from /home/centos/.rbenv/versions/2.2.4/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require' from /home/centos/apps/talk_on/bin/spring:13:in `<top (required)>' from bin/rails:3:in `load' from bin/rails:3:in `<main>'
エラー多すぎて笑えてきた。
こちら参考にさせていただき、rubyracerいれます。
qiita.com
$ vi Gemfile gem 'therubyracer', platforms: :ruby
gemが増えたのでbundle installし直します。
$ bundle install Gem::Ext::BuildError: ERROR: Failed to build gem native extension. /home/centos/.rbenv/versions/2.2.4/bin/ruby -r ./siteconf20160315-23889-drnx6o.rb extconf.rb checking for main() in -lpthread... yes creating Makefile make "DESTDIR=" clean make "DESTDIR=" compiling accessor.cc make: g++: コマンドが見つかりませんでした make: *** [accessor.o] エラー 127 make failed, exit code 2
g++コマンドがないそうです。
c++のコンパイラのようなので以下を実行。
$ sudo yum -y install gcc-c++
ここまででbundle installが通ったので、今度こそサーバー立ち上げます。
$ rails s INFO WEBrick 1.3.1 INFO ruby 2.2.4 (2015-12-16) [x86_64-linux] INFO WEBrick::HTTPServer#start: pid=24119 port=3000
ついに立ち上がった!
長々とお付き合いありがとうございました。