====== apache2でDocumentRootを変更 ======
===== はじめに =====
* デフォルトの DocumentRoot は "/var/www/html" になっており、root での利用となる。別のユーザーでホームページを運用できるよう、専用のユーザー webuser を作成し、/home/webuser/ に環境を構築する。
===== ユーザー webuser の登録 =====
==== ユーザー webuserを登録 ====
root$>useradd webuser
passwd webusr
Retype new UNIX password:<パスワードを入力>
passwd:<パスワードを入力>
all authentication tokens updated successfully.
==== ユーザー webuser のホームディレクトリを確認 ====
root$>su - webuser
webuser$>pwd
/home/webuser
webuser$>exit
===== /home/webuser にディレクトリを作成 =====
==== ディレクトリ構成 ====
/home/webuser/
└ www
├ cgi-bin
├ error
├ html
└ icons
==== ディレクトリ作成 ====
=== webuserでログイン後 ===
webuser$>pwd
/home/webuser
webuser$>mkdir www
webuser$>mkdir www/cgi-bin
webuser$>mkdir www/error
webuser$>mkdir www/html
webuser$>mkdir www/icons
===== /etc/httpd/conf/httpd.conf の修正 =====
==== 以下の設定を変更 ====
=== DocumentRootの変更 ===
DocumentRoot "/var/webuser/www/html"
↓
"/home/webuser/www/html"
↓
"/home/webusr/www/html">
=== icons パスの変更 ===
Alias /icons/ "/var/www/icons/"
↓
"/home/webuesr/www/icons/"
↓
"/home/webuser/www/icons">
=== cgi-bin パスの変更 ===
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
↓
"/home/webuesr/www/cgi-bin/"
↓
"/home/webuser/cgi-bin">
=== error パスの変更 ===
Alias /error/ "/var/www/error/"
↓
"/home/webuser/www/error/"
↓
"/home/webusr/www/error">
===== seLinuxの設定 =====
==== DocumentRoot 環境にラベルを設定 ====
root$>chcon system_u:object_r:httpd_sys_content_t /home/webusr/www -R
root$>chcon system_u:object_r:httpd_sys_script_exec_t /home/webusr/www/cgi-bin -R
===== apache の再起動 ====
==== httpd.conf の設定を反映させるため再起動 ====
root$>/etc/rc.d/init.d/httpd restart
httpd を停止中: [ OK ]
httpd を起動中: [ OK ]