カテゴリー別アーカイブ: Sinatra

VirtualBox centos6.8で、Apache+Passenger+Sinatraでの環境構築

VirtualBox centos6.8で、Apache+Passenger+Sinatraでの環境構築
してみる

sudoを使えるようにする
使用できるか確認する

・結果表示
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for centos: ##←パスワードを入力
centos は sudoers ファイル内にありません。この事象は記録・報告されます。
[centos@localhost ~]$ 

使用できない

Passwordを入力

ALL=を検索する

root ALL=(ALL) ALL
の下に

ユーザー名 ALL=(ALL) ALLを追加する

vi のコマンドなので
iで、挿入モードとして
ユーザー名 ALL=(ALL) ALL
を入力し
[Esc]+:+wq+改行で上書き終了
suから抜ける

suから抜ける
もう一度ためして見る

・表示結果
[sudo] password for centos: 
bin   dev  home  lib64	     media  mnt  opt   root  selinux  sys  usr
boot  etc  lib	 lost+found  misc   net  proc  sbin  srv      tmp  var
[centos@localhost ~]$ 

できた。

必要なアプリをインストール

15分ぐらいかかります・・・・

・結果表示
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.
  :
  :
Press Enter to continue, or Ctrl-C to abort.
 
1を、選択
・結果表示
Use <space> to select.
If the menu doesn't display correctly, press '!'
  
 ‣ ⬢  Ruby
   ⬢  Python
   ⬡  Node.js
   ⬡  Meteor
 
entrで、進んで行く

エラーがでます

・結果表示
[root@localhost sina]# /etc/rc.d/init.d/httpd restart
httpd を停止中:                                            [  OK  ]
httpd を起動中: httpd: Syntax error on line 1010 of /etc/httpd/conf/httpd.conf: Cannot load /home/centos/sina/vendor/bundle/ruby/2.2.0/gems/passenger-5.0.29/buildout/apache2/mod_passenger.so into server: /home/centos/sina/vendor/bundle/ruby/2.2.0/gems/passenger-5.0.29/buildout/apache2/mod_passenger.so: cannot open shared object file: Permission denied

cannot open shared object file: Permission denied
Permission関係なので、SELinuxの設定を変えてみます

[root@localhost sina]# /etc/rc.d/init.d/httpd restart
httpd を停止中:                                            [  OK  ]
httpd を起動中: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
                                                           [  OK  ]

apacheの起動はできた

http://localhost/にアクセスしてみます

エラーがでる

[root@localhost sina]# curl 'http://localhost/'
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /
on this server.</p>
<hr>
<address>Apache/2.2.15 (CentOS) Server at localhost Port 80</address>
</body></html>
[root@localhost sina]# 

apacheのエラーログを調べてみる
まず、error_logのありかを調べる

・結果表示
/var/log/httpd/error_log

エラーを表示してみる

・表示結果
  :
    :
[Sat Jun 25 05:17:15 2016] [error] [client ::1] (13)Permission denied: access to / denied

(13)Permission denied: access to / denied
で、Googleに聞いてみる
ユーザホームディレクトリのパーミッションが原因のようだ

http://dqn.sakusakutto.jp/2010/05/apache_13permission_denied_acc.html
http://toybox-v2.blogspot.jp/2011/10/13permission-denied-access-to-denied.html
(13)Permission denied: access to hoge denied の対処

Permissionを変えてみる

まず、現状を調べる

・表示結果
合計 12
drwxr-xr-x.  3 root   root   4096  6月 22 05:18 2016 .
dr-xr-xr-x. 25 root   root   4096  6月 25 04:16 2016 ..
drwx------. 33 centos centos 4096  6月 25 05:00 2016 centos

実行権限を付与する

・表示結果
合計 12
drwxr-xr-x.  3 root   root   4096  6月 22 05:18 2016 .
dr-xr-xr-x. 25 root   root   4096  6月 25 04:16 2016 ..
drwxr-xr-x. 33 centos centos 4096  6月 25 05:00 2016 centos
[root@localhost sina]# 

実行権限が付与された

drwx------. 33 centos centos 4096  6月 25 05:00 2016 centos
  ↓↓
drwxr-xr-x. 33 centos centos 4096  6月 25 05:00 2016 centos

もう一度行ってみる

[root@localhost sina]# curl 'http://localhost/'
Hello World[root@localhost sina]#

うまく表示された

Firfoxからhttp://localhost/を呼んでも、うまくいった

再起動して確認してましす

必要はファイルなどは、保存後、アプリを終了しておいて、下さい。

リブートします

SELinuxを確認

[centos@localhost ~]$ getenforce
Enforcing
[centos@localhost ~]$ 

Enforcing → SELinux機能、アクセス制御が有効

無効に設定する

/etc/selinux/config
ファイルの
SELINUX=enforcing

SELINUX=disabled
に変更します

apacheの状態を調べる

httpd は停止しています
[centos@localhost ~]$ 

httpd          	0:off	1:off	2:off	3:off	4:off	5:off	6:off

httpd          	0:off	1:off	2:on	3:on	4:on	5:on	6:off

レベル2から5がon(自動起動)になる

再度、リブートしてみます

SELinuxを確認

[centos@localhost ~]$ getenforce
Disabled
[centos@localhost ~]$ 

無効なのでOK

apacheの状態を調べる

[sudo] password for centos: 
httpd (pid  2021) を実行中...
[centos@localhost ~]$ 

実行中なのでOK

localhostにアクセスしてみる

[centos@localhost ~]$ curl 'http://localhost/'
Hello World[centos@localhost ~]$ 

接続できた

Firfox
http://localhost/
にアクセスする

Hello World

無事表示されました

passenger+sinatraで、Documenの置き場所をhomeに変える

前々回

apache+passenger+sinatraにて、
環境を構築しましたが、

コンテンツの置き場所が
/root/
で、権限がo+x
のままだと、プログラムの作成、編集が、面倒です。

また、
/root/の権限がそのままというのも、
少々不安な感じがします。

このため、コンテンツの置き場所を

/home/(user)/sina

に変更するしてみましょう

ユーザ権限にて

cd
pwd
・結果表示
/home/(user)
cd
mkdir sina
cd sina
echo "#coding: utf-8"    >app.rb
echo "require 'sinatra'" >>app.rb
echo "get '/' do"        >>app.rb
echo "'Hello World'"     >>app.rb
echo "end"               >>app.rb
echo "require File.expand_path(File.dirname(__FILE__)) + '/app'"  >config.ru
echo "run Sinatra::Application"                                   >>config.ru
mkdir public
mkdir tmp
touch tmp/always_restart.txt

/etc/httpd/conf/httpd.confを変更

su
権限にて
ファイル
/etc/httpd/conf/httpd.conf

DocumentRoot /root/sina/public
の部分を
DocumentRoot /home/(user)/sina/public
に変更

vi /etc/httpd/conf/httpd.conf
/etc/rc.d/init.d/httpd restart
curl 'http://localhost/'

しかし、エラーになる
エラーの内容を確認
apacheのエラーログの場所を探す

find / -name error_log
・結果表示
/var/log/httpd/error_log

エラーの内容を確認する

cat /var/log/httpd/error_log
・内容表示
:
Could not find rake-11.2.2 in any of the sources (Bundler::GemNotFound)
:

/home/(user)/ap/public
にも、Bundlerなどが必要・・・・・
.Bundler(隠しファイル)
なども、必要なので
一括複写する

cp -R /root/sina /home/(user)/sina

はじめから、こうすればよかった。。。

apacheの再起動

/etc/rc.d/init.d/httpd restart

確認

curl 'http://localhost/'

うまくいった。

suで、複写したので、
home側での権限などが心配なので、
ユーザ権限にもどって、作りなおしてみる

$cd
$cp -R /home/(user)/sina /home/(user)/sinatra

/etc/httpd/conf/httpd.conf

DocumentRoot /home/(user)/sina/public

DocumentRoot /home/(user)/sinatra/public
に変更し、apache再起動
/etc/rc.d/init.d/httpd restart
表示確認
curl ‘http://localhost/’

うまくいった。