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

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

無事表示されました