前回、Apacheをインストールした。今回は、RailsをApacheで動かすためのモジュールPhusion Passenger をインストールする。
Passenger をインストール
gem install passenger
※ No such file or directory が表示されたら sudo つけないとうまくインストールできた。
vagrant@ubuntu-14:~$ sudo gem install passenger Fetching: rake-10.4.2.gem (100%) Fetching: daemon_controller-1.2.0.gem (100%) Fetching: rack-1.6.0.gem (100%) Fetching: passenger-4.0.56.gem (100%) Building native extensions. This could take a while... Successfully installed rake-10.4.2 Successfully installed daemon_controller-1.2.0 Successfully installed rack-1.6.0 Successfully installed passenger-4.0.56 4 gems installed Installing ri documentation for rake-10.4.2... Installing ri documentation for daemon_controller-1.2.0... Installing ri documentation for rack-1.6.0... Installing ri documentation for passenger-4.0.56... Installing RDoc documentation for rake-10.4.2... Installing RDoc documentation for daemon_controller-1.2.0... Installing RDoc documentation for rack-1.6.0... Installing RDoc documentation for passenger-4.0.56... vagrant@ubuntu-14:~$
apache2-module の関連必須ソフトウェアをチェック
passenger-install-apache2-module
passenger-install-apache2-module コマンドを実行すると会話式でインストールが進む。
プロセスは大きく分けて3つに分かれている。
- The Apache 2 module will be installed for you.
- You'll learn how to configure Apache.
- You'll learn how to deploy a Ruby on Rails application.
どの言語に興味(関連?)あるかと聞いてくるので今回はデフォのRuby と Python にチェックを入れた。
必要なソフトウェアがインストールされているかチェックがはじまる。
必要なソフトウェアが足りない場合、インストール方法を指示してくれる。
Rubyの関連付けバージョンの修正
上記のapache2-module の関連必須ソフトウェアをチェックで気になったのが関連づけられたRubyのバージョン。ruby 2.1.2 のはずなのに 1.9.1になっている。1.9.1といったらVagrant Box (※Vagrant Box 取得 参照)で初期インストールされていたバージョン・・・
現在のrubyのグローバルバージョンを確認する。
vagrant@ubuntu-14:~$ ruby -v ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux] vagrant@ubuntu-14:~$
グローバルバージョンは2.1.2 になっているので問題ないようだ。
2.1.2は rbenv (※Rubyのバージョンを簡単に切り替えられる rbenv のインストール 参照) を使ってインストールした。
rbenv が管理しているバージョンを確認する。
vagrant@ubuntu-14:~$ rbenv versions system * 2.1.2 (set by /home/vagrant/.rbenv/version) vagrant@ubuntu-14:~$
当然の結果だが、rbenvでインストールしたのが2.1.2だけなので1.9.1がない。Rubyの管理が混合してるので動作がおかしいのか・・・?とりあえずRubyはrbenvで管理したいので1.9.1を削除する。
apt-get remove ruby1.9.1
vagrant@ubuntu-14:~$ sudo apt-get remove ruby1.9.1 Reading package lists... Done Building dependency tree Reading state information... Done 略 Removing ruby (1:1.9.3.4) ... Processing triggers for man-db (2.6.7.1-1) ... Processing triggers for libc-bin (2.19-0ubuntu6) ... vagrant@ubuntu-14:~$
Ruby の設定を変更したので、一旦 passenger入れ直し。
rbenv rehash ➡ gem install passenger ➡ rbenv rehash
vagrant@ubuntu-14:~$ rbenv rehash vagrant@ubuntu-14:~$ vagrant@ubuntu-14:~$ gem install passenger 略 2 gems installed vagrant@ubuntu-14:~$ vagrant@ubuntu-14:~$ rbenv rehash
再度、passenger-install-apache2-module コマンドを叩く。
今度は、2.1.2と関連づけられた。この状態でapache2-module の関連必須ソフトウェアで足りないものをインストールしていく。
To install Curl development headers with SSL support
apt-get install libcurl4-openssl-dev
vagrant@ubuntu-14:/vagrant$ sudo apt-get install apache2-threaded-dev Reading package lists... Done Building dependency tree Reading state information... Done 略
To install Apache 2 development headers
apt-get install apache2-threaded-dev
vagrant@ubuntu-14:/vagrant$ sudo apt-get install apache2-threaded-dev Reading package lists... Done Building dependency tree Reading state information... Done Note, selecting 'apache2-dev' instead of 'apache2-threaded-dev' apache2-dev is already the newest version. The following packages were automatically installed and are no longer required: augeas-lenses libaugeas0 libyaml-0-2 unzip virt-what zip Use 'apt-get autoremove' to remove them. 0 upgraded, 0 newly installed, 0 to remove and 5 not upgraded. vagrant@ubuntu-14:/vagrant$
To install Apache Portable Runtime (APR) development headers
apt-get install libapr1-dev
vagrant@ubuntu-14:/vagrant$ sudo apt-get install libapr1-dev Reading package lists... Done Building dependency tree Reading state information... Done libapr1-dev is already the newest version. libapr1-dev set to manually installed. The following packages were automatically installed and are no longer required: augeas-lenses libaugeas0 libyaml-0-2 unzip virt-what zip Use 'apt-get autoremove' to remove them. 0 upgraded, 0 newly installed, 0 to remove and 5 not upgraded. vagrant@ubuntu-14:/vagrant$
To install Apache Portable Runtime Utility (APU) development headers
apt-get install libaprutil1-dev
vagrant@ubuntu-14:/vagrant$ sudo apt-get install libaprutil1-dev Reading package lists... Done Building dependency tree Reading state information... Done libaprutil1-dev is already the newest version. libaprutil1-dev set to manually installed. The following packages were automatically installed and are no longer required: augeas-lenses libaugeas0 libyaml-0-2 unzip virt-what zip Use 'apt-get autoremove' to remove them. 0 upgraded, 0 newly installed, 0 to remove and 5 not upgraded. vagrant@ubuntu-14:/vagrant$
apache2-module をインストール
passenger-install-apache2-module
上記コマンドを何度か繰り返し、必要なソフトウェアをすべてインストールされると「All good!」と表示される。そしてapache2-moduleのインストールが開始される。
Apacheの設定とRailsアプリのデプロイ設定例が表示されるのでメモる。
Apacheのconfigファイル変更
Apacheの設定ファイル「apache2.conf」に次の指示されたコードを追記する。
※自分の環境では /etc/apache2/apache2.conf
<IfModule mod_passenger.c>
PassengerRoot /home/vagrant/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/passenger-4.0.56
PassengerDefaultRuby /home/vagrant/.rbenv/versions/2.1.2/bin/ruby
</IfModule>
default.conf作成
default.conf作成し次の指示されたコードを追記する。
※Ubuntu の環境による設定。自分の環境ではapache2.conf に,「Include sites-enabled/」という記述があるのでsites-enabled以下のファイルが読まれる。apache2.conf → 000-default → default の順で読まれる。
<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>
Apacheを再起動する
/etc/init.d/apache2 restart
vagrant@precise32:/etc/apache2/sites-enabled$ sudo /etc/init.d/apache2 restart * Restarting web server apache2 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName ... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName [ OK ] vagrant@precise32:/etc/apache2/sites-enabled$
警告がでているが、動作するということなので保留。
これで開発環境のベースができた。次回は動作検証をする。
[VagrantによるRails環境 関連記事]