FreeBSD/suPHP のバックアップ(No.3)


suPHP

環境

FreeBSD 6.1-RELEASE-p15
Apache/2.2.4
PHP 5.2.1
suPHP 0.6.2

PHPをCGIモードで動かすよう再コンパイル・インストール

# tar zxvf php-5.2.1.tar.gz
# cd php-5.2.1
# ./configure --with-mysql=/usr/local \
 --enable-cgi --disable-cli --disable-pear \
 --enable-force-cgi-redirect \
 --with-tsrm-pth --enable-mbstring \
 --enable-mbstr-enc-trans --enable-trans-sid \
 --enable-versioning
#make ;make install

php.iniの編集

cgi.force_redirect = 0

※PHPをCGIモードで動作させる場合、これをセットしないと「Security Alert! The PHP CGI cannot be accessed directly.」が出てしまう。

suPHPインストール

ソースダウンロードここで最新版をダウンロードしてくる

suPHP Homepage

tarボールの展開

$ tar zxvf suphp-0.6.2.tar.gz
$ cd suphp-0.6.2

コンフィグ

$ ./configure --with-min-uid=100 --with-min-gid=100 \
--with-apache-user=www --with-php=/usr/local/bin/php \
--with-logfile=/var/log/apache/suphp.log --with-apxs=/usr/local/sbin/apxs \
--sysconfdir=/usr/local/etc --disable-checkpath \
--with-apr=/usr/local/bin/apr-1-config --with-setid-mode=owner

suPHP_AddHandlerを使えるようにmod_suphp.cを修正

下記のように修正すると、httpd.confでsuPHP_AddHandlerが使用可能になる。

$ vi ./src/apache2/mod_suphp.c
324     AP_INIT_ITERATE("suPHP_AddHandler", suphp_handle_cmd_add_handler, NULL, ACCESS_C       ONF, "Tells mod_suphp to handle these MIME-types"),
                    ↓↓
324     AP_INIT_ITERATE("suPHP_AddHandler", suphp_handle_cmd_add_handler, NULL, RSRC_CONF | ACCESS_C        ONF, "Tells mod_suphp to handle these MIME-types"),

make,make instlal

$ su
# make ;make install

設定ファイルの用意

# cat /usr/local/etc/suphp.conf
[global]
;Path to logfile
logfile=/var/log/apache/suphp.log

;Loglevel
loglevel=info

;User Apache is running as
webserver_user=www

;Path all scripts have to be in
docroot=/

;Path to chroot() to before executing script
;chroot=/mychroot

; Security options
allow_file_group_writeable=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=false

;Send minor error messages to browser
errors_to_browser=true

;PATH environment variable
env_path=/bin:/usr/bin:/usr/local/bin:/usr/local/sbin

;Umask to set, specify in octal notation
umask=0022

; Minimum UID
min_uid=100

; Minimum GID
min_gid=100


[handlers]
;Handler for php-scripts
x-httpd-php=php:/usr/local/bin/php

;Handler for CGI-scripts
x-suphp-cgi=execute:!self

httpd.confの変更

httpd.confに下記を追加する。

LoadModule suphp_module       libexec/apache22/mod_suphp.so
suPHP_Engine on
AddHandler x-httpd-php .php 
suPHP_AddHandler x-httpd-php

Apache再起動

# /usr/local/etc/rc.d/apache22.sh restart

確認

  • ログが流れているのを確認
    # tail -f /var/log/apache/suphp.log