#navi(../../)
* Apacheで一般ユーザーの$HOME/public_htmlを公開する設定方法 [#ee2a3b33]
Apacheの設定により、以下のようにユーザーごとのホームページを公開することができます。
http://サーバー名/~ユーザー名
これにより、サーバーに存在するユーザー毎にホームページを作成することができます。~
以下、~ユーザー名によるホームページ公開の設定方法を記します。
#contents
#htmlinsertpcsp(web-top.html,web-sp.html)
* 使用した環境 [#g4141b9b]
本資料で使用した環境は以下の通りです。
- OS
$ lsb_release -d
Description: CentOS release 6.3 (Final)
- Apache
$ httpd -v
Server version: Apache/2.2.15 (Unix)
Server built: Feb 13 2012 22:31:42
本環境以外の方(Windowsなど)でも、httpd.confは一緒なので、本資料に記述してあるディレクトリなどを読み替えて使用してください。~
また、httpd.confではなく、apache.confになっている環境もあると思いますのでご注意ください。
* 関連資料 [#v3e80a17]
Windows, CentOS, UbuntuのLAMP, LAPPなどのインストール使用を公開しています。
参考にしてください。
-[[WindowsでXAMPPを用いてLAMP環境を構築>LAMP/WindowsでXAMPPを用いてLAMP環境を構築]]
以下の4つの資料は[[LINUX.JUST4FUN.BIZ>http://linux.just4fun.biz]]で公開している資料です。
-[[UbuntuでLAMP環境を構築する>http://linux.just4fun.biz/Ubuntu/LAMP%E7%92%B0%E5%A2%83%E3%81%AE%E6%A7%8B%E7%AF%89.html]]
-[[CentOSでLAMP環境を構築する>http://linux.just4fun.biz/CentOS/CentOS%E3%81%A7LAMP%E7%92%B0%E5%A2%83%E3%82%92%E6%A7%8B%E7%AF%89.html]]
-[[UbuntuでLAPP環境を構築する>http://linux.just4fun.biz/Ubuntu/LAPP%E7%92%B0%E5%A2%83%E3%81%AE%E6%A7%8B%E7%AF%89.html]]
-[[CentOSでLAPP環境を構築する>http://linux.just4fun.biz/CentOS/CentOS%E3%81%A7LAPP%E7%92%B0%E5%A2%83%E3%82%92%E6%A7%8B%E7%AF%89.html]]
* SELinuxを無効にする [#ic7e6aef]
SELinuxを無効にしないとPermission deniedになります。~
SELinuxの無効化は以下のリンクを参考にして設定してください。
-[[CentOSでSELinux動作モード確認・動作モードの設定方法>http://linux.just4fun.biz/CentOS/SELinux%E5%8B%95%E4%BD%9C%E3%83%A2%E3%83%BC%E3%83%89%E7%A2%BA%E8%AA%8D%E3%83%BB%E5%8B%95%E4%BD%9C%E3%83%A2%E3%83%BC%E3%83%89%E3%81%AE%E8%A8%AD%E5%AE%9A.html]]
ちなみにrootユーザーになり、以下のコマンドでEnforceと出力されたらSELinuxが有効になっています。
[root@centos6 ~]# getenforce
Enforcing
一時的にSELinuxを無効化にする方法は、以下のコマンドで可能です。
setenforce 0
* httpd.confを修正しユーザー毎にホームページを公開する [#a59cf472]
httpd.confファイルを開き、以下のキーワードを探します。~
本資料では、CentOS6を使用しています。~
以下のディレクトリにhttpd.confがありました。~
作業はrootユーザーにて行いました。
[sakura@centos6 ~]$ su -
パスワード:
[root@centos6 ~]# vi /etc/httpd/conf/httpd.conf
-変更前
187 LoadModule userdir_module modules/mod_userdir.so
<省略>
360 <IfModule mod_userdir.c>
361 #
362 # UserDir is disabled by default since it can confirm the presence
363 # of a username on the system (depending on home directory
364 # permissions).
365 #
366 UserDir disabled
367
368 #
369 # To enable requests to /~user/ to serve the user's public_html
370 # directory, remove the "UserDir disabled" line above, and uncomment
371 # the following line instead:
372 #
373 #UserDir public_html
374
375 </IfModule>
<省略>
381 #<Directory /home/*/public_html>
382 # AllowOverride FileInfo AuthConfig Limit
383 # Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
384 # <Limit GET POST OPTIONS>
385 # Order allow,deny
386 # Allow from all
387 # </Limit>
388 # <LimitExcept GET POST OPTIONS>
389 # Order deny,allow
390 # Deny from all
391 # </LimitExcept>
392 #</Directory>
- 変更後~
以下の変更を行いました。
+ userdir_moduleのロード(最初からコメントされていなかったのでそのまま。コメントされている場合は有効にしてください。)
+ UserDir disabled → #UserDir disabled
+ #UserDir public_html → UserDir public_html
+ <Directory /home/*/public_html> ... </Directory> のコメントを外す。(#の消去。)
187 LoadModule userdir_module modules/mod_userdir.so
<省略>
360 <IfModule mod_userdir.c>
361 #
362 # UserDir is disabled by default since it can confirm the presence
363 # of a username on the system (depending on home directory
364 # permissions).
365 #
366 #UserDir disabled
367
368 #
369 # To enable requests to /~user/ to serve the user's public_html
370 # directory, remove the "UserDir disabled" line above, and uncomment
371 # the following line instead:
372 #
373 UserDir public_html
374
375 </IfModule>
<省略>
381 <Directory /home/*/public_html>
382 AllowOverride FileInfo AuthConfig Limit
383 Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
384 <Limit GET POST OPTIONS>
385 Order allow,deny
386 Allow from all
387 </Limit>
388 <LimitExcept GET POST OPTIONS>
389 Order deny,allow
390 Deny from all
391 </LimitExcept>
392 </Directory>
変更が終了したらhttpd.confを保存しapache(httpd)を再起動します。~
CentOSではrootユーザーにて以下のコマンドで再起動しました。
service httpd restart
上記コマンドを実行したときの出力です。
[root@centos6 ~]# service httpd restart
httpd を停止中: [ OK ]
httpd を起動中: [ OK ]
[root@centos6 ~]#
#br
* ユーザーのホームディレクトリにpublic_htmlを作成する [#ae0bc25f]
以下、ユーザー名 sakura で設定を行います。
+ sakura ユーザーでログインします。
+ public_htmlディレクトリを作成します。
mkdir ~/public_html
+ httpd(apache)プロセスがアクセスできるようにパーミッションを設定します。~
CentOSの設定を見たところ、以下のようになっていました。
[sakura@centos6 ~]$ cd ..
[sakura@centos6 home]$ ls -l
合計 8
drwx------. 30 sakura sakura 4096 2月 11 21:00 2013 sakura
drwx------. 4 tsubaki tsubaki 4096 2月 11 21:03 2013 tsubaki
ユーザー以外、アクセスができないので、以下のようにパーミッションを変更しました。
chmod o+r /home/sakura
以下、chmodによるアクセス権限変更および確認を記します。
[sakura@centos6 home]$ pwd
/home
[sakura@centos6 home]$ ls -ld sakura/
drwx------. 30 sakura sakura 4096 2月 11 21:00 2013 sakura/
[sakura@centos6 home]$ chmod o+x sakura/
[sakura@centos6 home]$ ls -ld sakura/
drwx-----x. 29 sakura sakura 4096 2月 11 21:21 2013 sakura/
その他にパーミッション(権限)に--xになりました。
上記操作で作成したpublic_htmlのパーミッションを確認すると以下のようにその他のr(リード)になっていたので特に設定は行いませんでした。
[sakura@centos6 home]$ cd
[sakura@centos6 ~]$ ls -ld public_html/
drwxrwxr-x. 2 sakura sakura 4096 2月 11 21:02 2013 public_html/
* public_htmlにindex.htmlを作成しブラウザからアクセスしてみる [#dbb0031e]
作成したpublic_htmlディレクトリにindex.htmlを作成してみます。
[sakura@centos6 ~]$ cd public_html/
[sakura@centos6 public_html]$ echo '<b>Hello world!</b>' > index.html
作成したindex.htmlのパーミッションを確認すると、その他にr(リード)権限があるので特に変更しませんでした。
[sakura@centos6 public_html]$ ls -l index.html
-rw-rw-r--. 1 sakura sakura 20 2月 11 21:14 2013 index.html
* ブラウザを起動してアクセスしてみる [#e09f8b50]
今回使用したユーザー名はsakuraです。~
したがって、以下のようにすれば/home/sakura/public_html/のindex.htmlにアクセスが可能です。
http://ホスト名/~sakura/
実際にアクセスしたときのスクリーンショットです。
#ref(01.gif)
以上、Apacheで一般ユーザーの$HOME/public_htmlを公開する設定方法でした。
#htmlinsertpcsp(web-btm.html,web-sp.html)