やんちのプログラミングメモ

こんにちは、こちらはやんちのウェブページです。
このページにはやんちがプログラミング中に使用するメモを載せて行く予定です。

アクセスカウンタ
CentOS Linux 5.2 に、suPHP をセットアップしてみよう。

通常、PHP スクリプトのアクセス権は、ウェブサーバのアクセス権ですが、 suPHP を使うと、PHP スクリプトのアクセス権はユーザ権限となります。

事前にセットアップを完了しておくべきもの


今回は、以下の環境に suPHP をセットアップしてみます。
  • CentOS Linux 5.2
  • PHP-5.1.6(CGI/CLI版)
  • Apache-HTTPd-2.2.3
  • apr-1.2.7

ダウンロード


http://www.suphp.org/
より suPHP をダウンロード。

今回は、
「suphp-0.7.1.tar.gz」
をダウンロードしてみました。

解凍


「suphp-0.7.1.tar.gz」は圧縮ファイルですので、解凍してみます。

「suphp-0.7.1.tar.gz」を作業用のディレクトリに配備し、
$ tar xzvf suphp-0.7.1.tar.gz<Enter>
とすると、圧縮ファイルが解凍されます。

ファイルが解凍されたか確認してみましょう。
$ ls -F<Enter> suphp-0.7.1/ suphp-0.7.1.tar.gz $
「suphp-0.7.1/」と言うディレクトリが作成されている事が確認できました。

「suphp-0.7.1/」に入って、ディレクトリの内容も確認してみます。
$ cd suphp-0.7.1/<Enter> $ ls -F<Enter> AUTHORS INSTALL NEWS aclocal.m4 configure.ac COPYING Makefile.am README config/ doc/ ChangeLog Makefile.in acinclude.m4 configure* src/ $
ディレクトリの中にも解凍されたファイルがある事を確認できました。

ビルド設定のオプションを確認


$ ./configure --help<Enter>
とすると、ビルド設定のオプションを確認できます。

ビルド


ビルド設定
$ ./configure \ > --with-apr=/usr/bin/apr-1-config \ > --with-setid-mode=paranoid \ > --with-min-uid=100 \ > --with-min-gid=100 \ > --with-apache-user=apache \ > --with-logfile=/var/log/httpd/suphp_log<Enter>
CentOS Linux 5.2 では、「apr-config」が、「/usr/bin/apr-1-config」にあるみたい。
最初、自動検索にしたら、見つからないと言われました。

ビルド
$ make<Enter>

チェック
$ make check<Enter>
make ターゲットの「check」はテストケースがあれば、実行してくれるらしいです。

「make」、「make check」共に、エラーが無いようなら、インストールを行いましょう。

インストール


インストールを行うには、root 権限が必要ですので、作業ユーザを root に切り替えます。
$ su -<Enter> パスワード: #
root ユーザのパスワードを要求されますので、入力して下さい。

cd コマンドで、「suphp-0.7.1/」をビルドした作業ディレクトリまで、移動し、
インストールを行います。
# make install<Enter>
これで、インストールは完了。

設定


suPHP モジュール用の設定ファイル
「/etc/httpd/conf.d/mod_suphp.conf」を作成。
LoadModule suphp_module modules/mod_suphp.so <IfModule suphp_module> <Directory /home > suPHP_ENgine on </Directory> AddType application/x-httpd-php .php suPHP_AddHandler application/x-httpd-php .php DirectoryIndex index.php </IfModule>

設定ファイルをリネームし、PHP モジュールを無効にする。
# cd /etc/httpd/conf.d/<Enter> # mv php.conf php.conf.org<Enter>

「/etc/httpd/conf/httpd.conf」 を編集
VirtualHost を使用しているので、VirtualHostに項目を追加。
<VirtualHost *:80> DocumentRoot /home/test/public_html ServerName test.servername ErrorLog logs/test.servername-error_log CustomLog logs/test.servername-access_log common suPHP_UserGroup test users </VirtualHost>

suPHP 自体の設定ファイル、 「/usr/local/etc/suphp.conf」を作成
[global] ;Path to logfile logfile=/var/log/suphp.log ;Loglevel loglevel=info ;User Apache is running as webserver_user=apache ;Path all scripts have to be in docroot=${HOME}/public_html ;Path to chroot() to before executing script ;chroot=/mychroot ; Security options allow_file_groupwriteable=false allow_file_others_writeable=false allow_directory_group_writeable=false allow_directory_others_writeable=false ;Check wheter script is within DOCUMENT_ROOT check_vhost_docroot=true ;Send minor error messages to browser errors_to_browser=true ;PATH environment variable env_path=/bin:/usr/bin ;Umask to set, specify in octal notation umask=0077 ; Minimum UID min_uid=100 ; Minimum GID min_gid=100 [handlers] ;Handler for php-scripts application/x-httpd-php="php:/usr/bin/php-cgi" ;Handler for CGI-scripts application/x-suphp-cgi="execute:!self"

Apache HTTPd を再起動


変更した設定を有効にするために、HTTPd を再起動します。
# /etc/init.d/httpd restart<Enter> httpd を停止中: [ OK ] httpd を起動中: [ OK ] #

phpinfo() をテスト


「/home/*/public_html/」以下に、「phpinfo.php」を作成
<? phpinfo() ?>

ブラウザから表示してみる。
Server API CGI/FastCGI
と変わっている事を確認。
動作確認環境:
CentOS Linux 5.2
PHP-5.1.6(CGI/CLI版)
Apache-HTTPd-2.2.3
suphp-0.7.1

・2010-04-20