PostgreSQL6.4.2 Apache1.3.6+PHP3.0.7+openssl0.9.3a+mod_ssl on FreeBSD 2.2.8-RELEASE / FreeBSD 3.2-RELEASE
まず一連の作業で必要なツールをインストールしておきます。
●GNUmake gmake
FreeBSD2.2.8-Rの2枚目のpackage/Allに入っているので
pkg_add gmake-**.tgzをインストールしておきます。
●gdbm /packages/delel以下にある
●gcc 2.7.2以上
●bison
●flex 2.5.2または2.5.4
次にカーネルの再構築
通常のデバイスの組み込み後最後の
options SYSVSHMの後に
options SYSVSEM
options SYSVMSG
の2行を必ず入れてリコンパイルします。
makemake install後リブート suして、
postgres:postgresと言うuserとgroupを作っておき
mkdir /usr/local/pgsqlchown -R postgres:postgres /usr/local/pgsql
しておきます。
http://www.sra.co.jp/people/t-ishii/PostgreSQL/6.4/install-basic.html#freebsd
/usr/local/pgsqlにpostgresql-6.4.2-pached.tar.gz
をコピーしておいてtar zxvf します。
cd postgres-6.4.2/href
してから./configure --with-mb=EUC_JP
gmake all ★必ずGNUmakeを使うこと
gmake install
これでインストールは終わり。その後設定。
.bash_profileに以下を追加します。
PATH="$PATH":/usr/local/pgsql/bin
環境変数(bashです)
export POSTGRES_HOME=/usr/local/pgsql
export PGLIB=$POSTGRES_HOME/lib
export PGDATA=$POSTGRES_HOME/data
export MANPATH="$MANPATH":$POSTGRES_HOME/man
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH":"$PGLIB"
を加えて以上が完了したら
source ~/.bash_profile
データベースを初期化します。(これは一度だけ実行すれば良いです。)
$ initdb
これで /usr/local/pgsql/data/ 以下にデータベース領域が初期設定されます。
次にpostgres デーモン(postmaster)を立ち上げます。
デフォルトでは localhost からの接続のみ許可されておりremote host からのアクセスは
一切できないようになっています。とりあえずどこからでもアクセスできるようにしたい場合
は、
/usr/local/pgsql/data/pg_hba.conf の
#host all 0.0.0.0 0.0.0.0 trustの
行頭の#を削除。
なお変更したいときは
chmod 600 pg_hba.conf
しておかないと変更できません。あとでちゃんと
chmod 400 pg_hba.confで元通りにしておくこと。
それからいよいよ動作テストです。postmaster が動いていなければ立ち上げます。
$ postmaster -S -i
(あとで起動用スクリプトをつくっておきますが。)
regression 用のディレクトリに移ります。
$ cd href/test/regress
regression test を実施します。
$ gmake all runtest
テスト項目毎に ok/fail が出力されますが "fail" と出てもあわてないこと。
いくつかのエラーはでます。全滅に近ければコンパイルに失敗していますが、3つや4つの
エラーはOKです。(かなりいい加減。)
最後に /usr/local/etc/rc.d/ にpostgresqlの起動スクリプトを書いて実行属性を与えておきます。(例)
postgresql.sh
#! /bin/sh
rm /tmp/.s.PGSQL.*
su postgres -c "/usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data -S -i"
★ rm /tmp/.s.PGSQL.* は異常終了するとロックファイルができて、postgresqlが起動しないこと
があるのでいれておきます。
高村のホームに戻る いとうのホームへ
openssl0.9.3aのインストール
先にopensslをインストールしておきます。 以下はrootで作業。
ftp://ftp.openssl.org/source/ からopenssl-0.9.3a.tar.gz をgetしてきます。 cd /usr/local/href/ tar xzfv openssl-0.9.3a.tar.gz cd openssl-0.9.3a ./Configure FreeBSD make clean make depend make make rehash make test make install で終わり。インストール先はSSLeayと同じ /usr/local/ssl になります。
いとうのホームへ
Apache1.3.6+PHP3.0.7+日本語パッチ+openssl0.9.3a+mod_sslのインストール
http://www.unico-net.co.jp/~goji/FreeBSD/ssl.html 以下はrootで作業します。 すでに apache 1.3.x を動かしている場合は、 /usr/local/apache/bin/apachectl stop でapacheを停止させます。 念のために httpd.confやDocumentRoot以下をバックアップしておきましょう。 ソースは /usr/local/href 以下にあるものとします。 apache_1.3.6.tar.gz mod_ssl-2.3.5-1.3.6.tar.gz php-3.0.7.tar.gz php-3.0.7-kanji.4.patch regex.tar.gz です。 tar xvzf /usr/local/href/php-3.0.7.tar.gz tar xvzf /usr/local/href/apache_1.3.6.tar.gz tar xvzf /usr/local/href/mod_ssl-2.3.5-1.3.6.tar.gz export LD_LIBRARY_PATH=/usr/local/pgsql/lib ( make の途中で PostgreSQL のライブラリ libpq を見に行けるように) cd /usr/local/href/apache_1.3.6/ ./configure --prefix=/usr/local/apache cd ../mod_ssl-2.3.5-1.3.6 ./configure --prefix=/usr/local/apache --with-layout=Apache --with-apache=/usr/local/href/apache_1.3.6 --with-ssleay=/usr/local/href/openssl-0.9.3a --with-perl=/usr/bin/perl cd /usr/local/href/php-3.0.7 patch -p1 < ../php-3.0.7-kanji.4.patch mv regex regex.org tar zxf ../regex.tar.gz cd regex make cd .. pwd /usr/local/href/php-3.0.7 ./configure --prefix=/usr/local --with-pgsql --with-apache=../apache_1.3.6 --enable-track-vars --with-apxs=/usr/local/apache/bin/apxs --without-system-regex --without-gd ee Makefileして APXS_LDFLAGS = -L./regex -lregex -lm に変更して make clean make make install cd ../apache_1.3.6/hrefcp Configuration.apaci Configuration cd /usr/local/href/apache_1.3.6 OPTIM="-O2" ./configure --prefix=/usr/local/apache --enable-module=most --activate-module=href/modules/php3/libphp3.a --disable-rule=WANTHSREGEX (ここでSSL関係・PHP3関係のモジュールが表示されなければ×) make clean make make install ここまでで、Apache としてはインストールが完了です。早速動かして試してみます。 動かす人の登録は済んでいますか? wwwadmin:www を /stand/sysinstallや adduserで先に作っておきます。 User wwwadmin Group www ServerAdmin webmaster@hoge.net ServerName www.hoge.net# # This may also be "None", "All", or any combination of "Indexes", # "Includes", "FollowSymLinks", "ExecCGI", or "MultiViews". # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # Options Indexes FollowSymLinks Includes ExecCGI # # This controls which options the .htaccess files in directories can # override. Can also be "All", or any combination of "Options", "FileInfo", # "AuthConfig", and "Limit" # AllowOverride All # # Controls who can get stuff from this server. # Order allow,deny Allow from all UserDir "/usr/home/*/public_html" 等と書いておきます。他のapache1.3.xが動いている計算機からコピーしてくるとき は特に先の User wwwadmin Group www ServerAdmin webmaster@hoge.net ServerName www.hoge.net が大事です。 とくにUserとGroupが実在しなければ絶対に起動しません。 デフォルトでnobody:nobodyになっている場合もありますが、避けた方がよいようです。 いよいよ起動 /usr/local/apache/bin/apachectl start /usr/local/apache/bin/apachectl start: httpd started この後ブラウザでそのサーバにアクセスしてみて、 「It Worked!」 (元々 /usr/local/apache/htdocs があった時は元々のページ)が表示されれば成功 です。うまくいったら、 /usr/local/etc/rc.d/apache.sh とでも名前を付けて以下のようなスクリプトを書 いて実行属性を与えておきます。 apache.sh (例) #!/bin/sh # apache=/usr/local/apache/bin/httpd apachectl=/usr/local/apache/bin/apachectl export LD_LIBRARY_PATH=/usr/local/pgsql/lib if [ -f $apache ]; then $apachectl start echo -n ' Apache Server Started ' fi 途中のexportはphpを組み込むときのおまじないです。(これが無いとまたapacheが動 きません。)
いとうのホームへ
PHP3の設定
次は PHP3 の設定を行います。 cd ../php-3.0.7 cp php3.ini-dist /usr/local/lib/php3.ini さらにhttpd.confに以下の設定が必要です。 cd /usr/local/apache/conf/ php3 を含む行 #AddType application/x-httpd-php3 .phtml の行頭の '#' を削除して、右端の .phtml を .php3 に変更します。 これが PHP3 スクリプトファイルの拡張子となります。変更を反映させるために Apache を再起動 します。 /usr/local/apache/bin/apachectl restart /usr/local/apache/bin/apachectl restart: httpd restarted PHP3スクリプトがちゃんと機能するか以下の様に試せsます。 cp /usr/local/href/php-3.0.5/examples/date.php3 /usr/local/apache/htdocs この後、適当なブラウザで http://そのサーバのIPアドレス/date.php3 にアクセ スして、こんな表示がされれば成功です。 ----------------------------------------------------------------------------- Date/Time Functions Demo Functions demonstrated The date() function is used to display times and dates in various ways. The function takes a format string and a time as arguments. If the time argument is left off, the current time and date will be used. The time argument is specified as an integer in number of seconds since the Unix Epoch on January 1, 1970. The format string is used to indicate which date/time components should be displayed and how they should be formatted. For example, if we wanted to print the current date and time, we might use a tag like: Fri Dec 05, 2008 18:08:27. This looks like: Fri Nov 27, 1998 17:16:45 (ここが今現在の時刻になっていればOK) -----------------------------------------------------------------------------
いとうのホームへ
PHP3をADOで組み込む
何故かFreeBSD3.2では上記の方法ではPHP3が組み込めず。ADOで組み込んでみました。
cd /usr/local/href/apache_1.3.6/href/modules/standard
で
make
を一発かまして mod_so.c から mod_so.o を作ってから
OPTIM="-O2" ./configure --prefix=/usr/local/apache --enable-module=most --enable-module=so --disable-rule=WANTHSREGEX
して
make clean
make
make install とADOが利用可能な状態のapacheを作ります。 httpd.confにphp3をADOで組み込み旨記述
LoadFile /usr/local/pgsql/lib/libpq.so
LoadModule php3_module libexec/libphp3.so
してapacheを(リ)スタートすればよし。
いとうのホームへ
mod_ssl関係の設定
サイト秘密キーの作成をします。 キー作成のために、適当に選んだファイル seed1 〜 5 を用意しておきます。 (キーはパスフレーズにより DES3 を用いて暗号化される。) # pwd /usr/local/apache/etc/ssl # mkdir keys # chmod 0700 keys # cd keys # /usr/local/ssl/bin/openssl genrsa \ -des3 \ -rand seed1:seed2:seed3:seed4:seed5 \ 1024 \ > httpd.key ........... Enter PEM pass phrase: <** パスフレーズ **> Verifying password -- Enter PEM pass phrase: <** パスフレーズ **> # chmod 0400 httpd.key ここで作成された秘密キー httpd.key は厳重に管理すること。 -------------------------------------------------------------------------------- サイト証明書作成 自分で自身のサイトの証明書を用意する方法。サイトの証明にお金をかけたくない場 合や、通信の暗号化だけを主な目的にする場合に有用。クレジット番号を入力しなけれ ばならないような、社会的な信用も得たい場合には、次に書かれているような第三者 機関が運用している CA に証明書を発行してもらう必要があるでしょう。但し、ほと んどの CA は有料です。 # pwd /usr/local/apache/etc/ssl # mkdir certs # chmod 0700 certs # cd certs # /usr/local/ssl/bin/openssl req \ -new \ -x509 \ -days 30 \ -key ../keys/httpd.key \ > httpd.pem Using configuration from /usr/local/ssl/openssl.cnf Enter PEM pass phrase: <** パスフレーズ **> You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]:JP State or Province Name (full name) [Some-State]:Tochigi Locality Name (eg, city) []:Utsunomiya Organization Name (eg, company) [Internet Widgits Pty Ltd]:UNICO Co.,LTD. Organizational Unit Name (eg, section) []: Common Name (eg, YOUR name) []:www.unico-net.co.jp Email Address []:webmaster@unico-net.co.jp # chmod 0400 httpd.pem ここで作成されたサイト証明書 httpd.pem も秘密キーと同様に厳重に管理すること。 ----------------------------------------------------------------------------- 第三者機関の CA による証明書の取得 前述のように、自分で自身の証明書を用意せず、第三者機関が運用する CA に証明書を 発行してもらう方法。 # pwd /usr/local/apache/etc/ssl/certs # /usr/local/ssl/bin/openssl req \ -new \ -key ../keys/httpd.key \ > httpd.csr Using configuration from /usr/local/ssl/openssl.cnf Enter PEM pass phrase: <** パスフレーズ **> You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]:JP State or Province Name (full name) [Some-State]:Tochigi Locality Name (eg, city) []:Utsunomiya Organization Name (eg, company) [Internet Widgits Pty Ltd]:UNICO Co.,LTD. Organizational Unit Name (eg, section) []: Common Name (eg, YOUR name) []:www.unico-net.co.jp Email Address []:webmaster@unico-net.co.jp Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: ここで作成された証明書署名要求(CSR) httpd.csr を証明機関(CA)に送り、発行され た証明書を /usr/loalc/apache/etc/ssl/certs/httpd.pem として置いておきます。 詳しくは、各 CA に聞いてみること。 # chmod 0700 httpd.pem (このサイト証明書 httpd.pem も秘密キーと同様に厳重に管理すること。) 主な CA 日本ベリサイン http://www.verisign.co.jp/ Thawte Consulting 国内窓口 http://www.medix.co.jp/Thawte/General/index.html CertiSign Certificadora Digital Ltd. http://www.certisign.com.br/ IKS GmbH http://www.iks-jena.de/produkte/ca/ Uptime Commerce Ltd. http://www.uptimecommerce.com/ BelSign NV/SA http://www.belsign.be/ ------------------------------------------------------------------------------ Apache(httpd.conf) の設定(mod_ssl の場合) SSL を用いて HTTP を暗号化する際、URL スキームは https:// となり、標準では 443 ポートが使用されます。また、一つのサーバーで通常の HTTP も同時に運用す るので、HTTPS はバーチャルサーバーとして設定しました。 ドキュメントは、/usr/local/apache/secure-docs、証明書は、 /usr/local/apache/etc/ssl/certs/httpd.pem、秘密キーは、 /usr/local/apache/etc/ssl/keys/httpd/key にそれぞれ置いておきます。 ### Section 2: 'Main' server configuration Listen 80 Listen 443 SSLEngine off ### Section 3: Virtual Hosts AddType application/x-x509-ca-cert .crt AddType application/x-pkcs7-crl .crl SSLPassPhraseDialog exec:/usr/local/apache/etc/ssl/keys/pp-filter SSLSessionCache dbm:/usr/local/apache/logs/ssl_scache SSLSessionCacheTimeout 300 SSLRandomSeed startup builtin SSLRandomSeed connect builtin SSLLog /var/log/ssl_engine.log SSLLogLevel infoDocumentRoot /usr/local/apache/secure-docs ServerName www.unico-net.co.jp ServerAdmin webmaster@unico-net.co.jp ErrorLog /var/log/httpsd_error.log TransferLog /var/log/httpsd_access.log SSLEngine on SSLCipherSuite ALL:!ADH:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL SSLCertificateFile /usr/local/apache/etc/ssl/certs/httpd.pem SSLCertificateKeyFile /usr/local/apache/etc/ssl/keys/httpd.key SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown CustomLog /var/log/ssl_request.log \ "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b" SSLPassPhraseDialog について SSL を組み込んだ Apache が起動する際に、証明書ファイルと秘密キーファイルを 読み込む必要があります。秘密キーは暗号化されているので、それを復号するために パスフレーズを入力することが必要ですが、システムブート時に httpd を自動的に 起動したい場合に不都合が出て来ます。そこで、標準出力にパスフレーズを吐き出 させるプログラムを用意し、それを食わせて起動させるように設定します。 # cat /usr/local/apache/etc/ssl/keys/pp-filter #!/bin/sh echo <** パスフレーズ **> このファイルは、root のみ実行できるようにしておきます。(必ず!!) なお、"builtin" を指定しておくと、httpd を起動時にパスフレーズの入力を対話的 に行うことになります。(つまり自動起動はできない) ./apachectl start ではなくて ./apachectl startssl で -DSSLオプション付き起動になります。Options Includes IncludesNoExec ExecCGI FollowSymLinks AllowOverride Limit allow from all SSLRequireSSL