通勤時の電車の中では本を読んでいるか、暇つぶしに2ch見てるわけだが。どうせ携帯で見るなら自宅サーバのリソースも余ってることだし有効活用したい。そんなわけでrep2を使うことにした。
インストール
とりあえずダウンロードして、/var/www/localhost/rep2とかに置く。apacheは当然SSL有効でコンパイルしておくこと。phpはやたらに使用可能なフラグが多いのでメモっておく。
# emerge -pv php
These are the packages that would be merged, in order:
Calculating dependencies... done!
[ebuild R ] dev-lang/php-5.1.6-r6 USE="apache2 bzip2 cjk cli crypt curl curlwrappers gd iconv mysql ncurses nls pcre readline sasl session spell ssl threads unicode xml xmlrpc zlib (-adabas) -apache -bcmath -berkdb (-birdstep) -calendar -cdb -cgi -concurrentmodphp -ctype -db2 -dbase (-dbmaker) -debug -discard-path -doc (-empress) (-empress-bcs) (-esoob) -exif -fastbuild (-fdftk) (-filepro) (-firebird) -flatfile -force-cgi-redirect (-frontbase) -ftp -gd-external -gdbm -gmp -hardenedphp -hash -hyperwave-api -imap (-informix) -inifile -interbase -iodbc -ipv6 -java-external -kerberos -ldap -libedit -mcve -memlimit -mhash -ming -msql -mssql -mysqli -oci8 (-oci8-instant-client) -odbc -pcntl -pdo -pdo-external -pic -posix -postgres -qdbm -recode -reflection -sapdb -sharedext -sharedmem -simplexml -snmp -soap -sockets (-solid) -spl -sqlite (-sybase) (-sybase-ct) -sysvipc -tidy -tokenizer -truetype -vm-goto -vm-switch -wddx -xmlreader -xmlwriter -xpm -xsl -yaz -zip" 0 kB
rep2はPEARモジュールのいくつかが必須なので、PEARもと必須モジュールを入れる。eixで見つからなかったものはpearコマンドで入れ、見つかったものはemergeで入れた。
# emerge PEAR-PEAR
# pear install Net_UserAgent_Mobile-beta
# pear install PHP_Compat
# emerge PEAR-HTTP_Request
# emerge PEAR-Pager
# emerge PEAR-File
phpの設定
/etc/php/apache2-php5/php.iniの次のコメントアウトを外す。
[mbstring]
mbstring.internal_encoding = EUC-JP
mbstring.http_input = auto
mbstring.http_output = EUC-JP
mbstring.detect_order = auto
mbstring.substitute_character = none;
apacheの設定
SSLを使うため、認証局と証明書が必要。[修正版][memo] postfix + dovecotでSMTP AUTH & IMAPなメールサーバを立ち上げるで作成したものがあるのでそれを流用する。
# cp -p /etc/ssl/postfix/server.crt /etc/apache2/ssl/
# cp -p /etc/ssl/postfix/server.key /etc/apache2/ssl/
次にBasic認証に使う.htaccessをフォルダで上書きできるようにしておくため、/etc/apache2/modules.d/41_mod_ssl.default-vhost.confと/etc/apache2/vhosts.d/00_default_vhost.confの<directory “/var/www/localhost/htdocs”>部分を以下のように設定する。
<directory "/var/www/localhost/htdocs">
Options FollowSymLinks
AllowOverride AuthConfig
</directory>
.htaccessの設定
/var/www/localhost/htdocs/rep2に.htaccessを作成(サイト全体に認証をかけたいならhtdocsの下でも可)。
# vi /var/www/localhost/htdocs/rep2/.htaccess
AuthName "User Authentication Required"
AuthType Basic
Require valid-user
AuthUserFile /etc/apache2/.htpasswd
# htpasswd2 -c /etc/apache2/.htpasswd ユーザ名
apacheの起動パラメータ
gentooのapacheは、有効にしたいモジュールを明示しないといけないので、/etc/conf.d/apache2を修正。
# vi /etc/conf.d/apache2
APACHE2_OPTS="-D SSL -D PHP5 -D DEFAULT_VHOST -D SSL_DEFAULT_VHOST"
# /etc/init.d/apache2 restart
これで https://ホスト名:443/rep2/ に行けばユーザ名とパスワードが聞かれるはず。念のため携帯からもアクセスして問題なく認証できれば万事OK。ただ携帯でパスワードを入力するのは面倒なので、どうにか携帯の固有IDでパスできないか調べ中。auだとHTTP_X_UP_SUBNOで取れるみたいなんだが…
gentoo, memo, server