*Apache2.x(ssl+PHP) [#ua42169a]
RIGHT:更新日&lastmod();  

Apache2.xを[[ここ:http://www.apache.jp/misc/download.html]] opensslを[[ここ:http://ring.tains.tohoku.ac.jp/archives/net/openssl/source/]]から、~
PHPを[[ここ:http://www.php.net/]]または[[Ring:http://www.ring.gr.jp/pub/net/www/php/distributions/]]からDownloadしてくる。~
Apache2.xからはmod_sslは実装されているので必要ない。
PDFlibを[[ここ:http://www.pdflib.com/jp/]]からDownloadしてくる。

**opensslのinstall [#r752c198]
 $ tar zxvf openssl-0.9.7d.tar.gz
 $ cd openssl-0.9.7d
 $ ./config
 $ make
 $ make test
 $ su
 # make install

**apache2.xのinstall [#e01f395e]

 $ tar zxvf httpd-2.0.50.tar.gz

***IE6のバグ [#w4ab6af3]
ページアクセス時にxxx.php?data=abcのような変数渡しをするとdigest
認証でエラーする。(IE6のバグ?)

[[apache1.3.xと同じ。:https://wwwism.dyndns.org/hp/linux/apache.htm]] 

そこでhttpd-2.0.50/modules/aaa/mod_auth_digest.c
 1680行くらいを修正
                    && d_uri.path[0] == '*' && d_uri.path[1] == '\0'))
 #ifdef  NOT_FOR_ME  <---追加
            /* check that query matches */
            || (d_uri.query != r_uri.query
                && (!d_uri.query || !r_uri.query
                    || strcmp(d_uri.query, r_uri.query)))
 #endif  <---追加
            ) {
	(略)
              }

***ここから本来のインストール [#q157ac4f]

 $ cd ../httpd-2.0.50
 $ CFLAGS="-O2" ./configure \
   --prefix=/usr/local/apache2050 --enable-module=so \
   --enable-shared=ssl --enable-ssl [--with-ssl=/usr/local/ssl] \
   --enable-auth_digest --enable-rewrite
  (--enable-auth_digest: Digest認証)
   --with-included-apr
  (--with-included-apr 2.2.4では無いと以下のエラーが出る)

[[sslについては>#ssl]]/usr/local/sslは不要

&color(red){''Apache2.2.4でのconfigエラーにつて''};

config時のエラー

 Configuring Apache Portable Runtime Utility library...
 
 checking for APR-util... yes
 configure: error: Cannot use an external APR-util with the bundled APR


apr と apr-util のバージョン 1.0 や 1.1 がシステムの一部として既にインストールされている場合、 apr/apr-util を 1.2 にアップグレードするか、 httpd を隔離した環境でビルドする必要がある。または --with-included-aprでにげる。

 Apache Portable Runtime(APR)
 
 Apach の過般なライブラリで,Apach のサーバコードの OS 依存の部分を 
 OS 非依存の部分から分割するために作られた

''apr と apr-utilのインストール''

apr
 $ cd srclib/apr
 $ ./configure --prefix=/usr/local/apr-httpd/
 $ make
 $ su
 # make install

apr-util
 $ cd ../apr-util
 $ ./configure --prefix=/usr/local/apr-util-httpd/ --with-apr=/usr/local/apr-httpd/
 $ make
 $ su
 # make install

httpd のconfigで--with-apr=/usr/local/apr-httpd/ --with-apr-util=/usr/local/apr-util-httpd/を追加 


''httpdのインストールの続き''
 $ make 
 $ su
 # make install
 # cd /usr/local
 # ln -s apache2050 apache2

/usr/local/apache2/conf/httpd.confを修正

 ##User nobody
 ##Group #-1
 User www
 Group www

[&color(red){apache2.2.x};は言語の順番、ユーザディレクトの設定が別のファイルになった。
 # Language settings
 #Include conf/extra/httpd-languages.conf
 Include conf/extra/httpd-languages.conf
 とし、

 extra/httpd-languages.confファイルで以下のようにする]

 ##LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW
 LanguagePriority ja en ca cs da de el eo es et fr he hr it ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW

 # User home directories
 #Include conf/extra/httpd-userdir.conf
 Include conf/extra/httpd-userdir.conf

 ------------------------------------------------ ]

 ##AddDefaultCharset ISO-8859-1
 AddDefaultCharset off

 #AddHandler cgi-script .cgi
 AddHandler cgi-script .cgi .pl

 ##ServerAdmin you@example.com
 ServerAdmin okada@YYY.ac.jp

 #ServerName www.example.com:80
 ServerName uso5002.YYY.ac.jp

 <Directory />
 ##    Options FollowSymLinks
 ##    AllowOverride None
    Options All MultiViews -Indexes <-- -Indexesはindex.html等がないときディレクトリを表示させない(個人ディレクトリの下)
     AllowOverride All
 </Directory>

''この<Directory />ディレクティブの意味''

 AccessFileName .acl 

という設定があると、以下のようにして無効にされていない限り、 ドキュメント /usr/local/web/index.html を返す前に、サーバは /.acl, /usr/.acl, /usr/local/.acl, /usr/local/web/.acl から ディレクティブを読み込みます。

 <Directory />
 AllowOverride None
 </Directory> 




 ##    Options Indexes FollowSymLinks
     Options All MultiViews -Indexes <-- -Indexesはindex.html等がないときディレクトリを表示させない(documentsrootの下)

 ##    AllowOverride None
     AllowOverride All

 ##DirectoryIndex index.html index.html.var
 DirectoryIndex index.html index.htm index.php index.cgi index.pl index.shtml

[&color(red){apache2.2.x};についてDirectoryIndexを追加する

 # DirectoryIndex: sets the file that Apache will serve if a directory
 # is requested.
 #
&color(red){以下を追加 DirectoryIndex index.html index.htm index.php index.cgi index.pl index.shtml};

 <IfModule dir_module>
     DirectoryIndex index.html
 </IfModule>

 -----------------------------------------------------------------]


233行目くらいの~
LoadModule auth_digest_module modules/mod_auth_digest.so~
があればをコメントアウトする。~

--------------httpd.confここまで---------------------------

&color(red){apache2.2.x};については~
statusを表示するには~
httpd.confの

 # Real-time info on requests and configuration
 ##Include conf/extra/httpd-info.conf
 Include conf/extra/httpd-info.conf

を修正し

extra/httpd-info.conf


    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from 10          <---アクセス許可IPを追加
    Allow from 192.244.75  <---アクセス許可IPを追加


server-infoについてはmod_info.cが必要なため、コメントアウトする

 ##
 ##    SetHandler server-info
 ##    Order deny,allow
 ##    Deny from all
 ##    Allow from 10
 ##    Allow from 192.244.75
 ##

https://www.abc-u.ac.jp/server-statusでアクセス


モジュールの組み込みの確認

 % usr/local/apache2050/bin/httpd -l
 Compiled in modules:
   core.c
   mod_access.c
   mod_auth.c
   mod_auth_digest.c  <---ここで確認
   mod_include.c
   mod_log_config.c
   mod_env.c
 (以下略)

***モジュールについて [#x8ecbc59]

モジュールについては2種類あり静的モジュールは上記なように、httpd -lで確認できる~
もうひとつのモジュールはDSO(Dynamic Shared Object)は必要に応じて組み込むためプログラムの軽量化が出来る。これは

 ./configure --enable-proxy=shared

のように=sharedをつける。確認は

 ./httpd -M
 Loaded Modules:
 (略)
 so_module (static)
 php5_module (shared) <--ここを確認

**mod_rewriteについて [#m0f84769]
URLのリダイレクト等に使用できるモジュールでコンパイル時に--enable-rewriteでconfigureする

httpd.confで以下のようにすると存在しないファイルは[[missing-2.php>Web Memo/PHPメモ#JUMP]]で処理を行う

 RewriteEngine On
 ##RewriteBase
 
 RewriteCond /usr/local/apache223/htdocs%{REQUEST_FILENAME} !-f <--条件不成立で次の行へ、成立でRewriteRuleへ     (1)
 RewriteCond /usr/local/apache223/htdocs%{REQUEST_FILENAME} !-d <--条件成立でRewriteRuleへ、不成立でRewriteRuleを行わない    (2)
 ##RewriteRule (.*) http://www.abc.ac.jp%{REQUEST_FILENAME} [R,L] <--全てのファイルはhttp://www.abc.ac.jpの同じURLにリダイレクト R:リダイレクト L:ここでルールの終了   (3)
 RewriteRule (.*) /missing-2.php (4)
 RewriteLogLevel 9   <--数値が大きいほど情報が多くなる。9だとほとんどの情報が出力される
 RewriteLog "logs/rewrite_log"

(1)は指定ファイルが存在しない場合の成立、(2)は指定ディレクトリが存在しない場合に成立

(1)(2)(3)を指定して(4)は指定しなときは存在しないファイル、ディレクトリは(3)で指定したURLへ。

また、(4)だけ指定は全て(4)のPHPに行くので、PHP内部で処理

(1)(2)(4)指定して(3)は指定しなときは存在しないファイル、ディレクトリは(4)で指定したPHPへ。そこで処理。

**Digest認証の利用の仕方 [#v3b919de]

パスワードの作成
 $ /usr/local/apache2/bin/htdigest -c /home/okada/hogehoge/htdtpsswd ism abc
                                                                     ^^^(1)
 Adding password for center in realm ism.
 New password:
 Re-type new password:

出来たファイルの確認
 ls -l
 合計 12
 -rwxr-xr-x    1 okada    okada          46 Apr  5 10:50 htdtpsswd*

新しいユーザの追加・変更
 % /usr/local/apache2/bin/htdigest /export/home/okada/himitsu/htdtpsswd ism  je2ism
 Adding user je2ism in realm ism
 (Changing password for user je2ism in realm ism)
 New password:
 Re-type new password:
 
&color(red){Vine4.xからhtdigestからhtdigest2になっているようだ};

.htaccess

 <Limit HEAD GET POST>
 
  AuthDigestFile /home/okada/hogehoge/htdtpsswd <---Apache2.2.x以前
&color(red){Apache2.2.x以降はAuthDigestFileはなくなり、AuthUserFile(Basic認証と同じ)になった。};
  AuthUserFile /home/okada/hogehoge/htdtpsswd <---Apache2.2.x以降
  AuthName ism  <---(1)と合わせる
  AuthType Digest
  Require valid-user  <---ユーザ認証の場合はここまでOK
  Satisfy any   <---この行があると以下のIPでは認証が不要。それ以外はパスワードが 必要
  order deny,allow
  allow from 192.168.1.0/24  <---IPアクセス制限
  deny from all
 
 </Limit>

''Digest認証:''
 HTTP/1.1対応のブラウザでのみ利用可能
 認証情報はMD5で暗号化され、チャレンジ・レスポンス型で認証されるので、
 セッション開設ごとに値が変わるので暗号解読が困難となり、パケット盗聴
 されても解読はかなり困難である。

''Basic認証:''
 認証情報には一般的にはプレインテキストを MIME エンコードしたものが使用
 されるので、パケットを盗聴されると簡単にデコードできてしまうという欠点
 がある。但し、MD5での暗号化も可能。


**Virtua lHost(名前ベース)の設定 [#b89e1516]

''Apache2.2.xでは''
httpd-vhosts.confの中に以下を追加する

 <Directory "/usr/local/apache223/htdocs">
 (略)
 </Directory>

 [以下を追加]
 <Directory "/usr/local/apache2052/v-host1">
     AllowOverride All
     AllowOverride All
 
     Order allow,deny
     Allow from all
 
 </Directory>

あとは2.0.xと同じようにextra/httpd-vhosts.conf追加し
 #Include conf/extra/httpd-vhosts.conf
のコメントをはずす。

''Apache2.0.xでは''~
ひとつの物理ホストを異なるホスト名でアクセスするときに利用する。~
ただし、~okadaのように個人ディレクトリはどのホスト名でも同じになる~

例えば、v-host0.YYY.ac.jp、v-host1.YYY.ac.jpという名前で異なるディレクトリにアクセスさせるには 

httpd.confにの最後に
 <VirtualHost *:80>
      DocumentRoot /usr/local/apache2052/v-host0
      ServerName   v-host0.YYY.ac.jp
 </VirtualHost>
 
 <VirtualHost *:80>
      DocumentRoot /usr/local/apache2052/v-host1
      ServerName   v-host1.YYY.ac.jp
 </VirtualHost>

と記入すればよい。

このとき本来のDocumentRootや、ServerNameは無視され、Virtual Hostのはじめの
エントリーが表示される。

例えば本来の
 DocumentRoot /usr/local/apache2052/htdocs
 ServerName    www.YYY.ac.jp
の記述があった場合

http://www.YYY.ac.jp/

にアクセスすると

/usr/local/apache2052/v-host0/

が表示される。

当然http://v-host0.YYY.ac.jpにアクセスしても

/usr/local/apache2052/v-host0/

が表示される。

また名前ベースのVirtual Hostではsslは本来の1つしか使用できない

つまり、

https://www.YYY.ac.jp/もhttps://v-host0.YYY.ac.jpもhttps://v-host1.YYY.ac.jp同じページが表示される。

**Virtua lHost(IPベース)の設定 [#cbc3b30d]
sslではipベースでないと振り分けられないので以下ようにextra/httpd-ssl.confの設定(&color(red){Apache2.2.x};)を追加する必要がある。~
これはヘッダー部まで暗号化されるのでホスト名がわからないようである。~
あわせてIPアドレスをインターフェイスにつける必要がある。

<VirtualHost _default_:443>から</VirtualHost>の間をコピーし2つ作成し

 ##<VirtualHost _default_:443>
 <VirtualHost 192.168.1.30:443>
 
 #   General setup for the virtual host
 DocumentRoot "/usr/local/apache223/htdocs"
 ##DocumentRoot "/usr/local/food"
 ##ServerName www.example.com:443
 ##ServerAdmin you@example.com
 ServerName enfant.abc-u.ac.jp:443
 ServerAdmin okada@abc-u.ac.jp
 ErrorLog /usr/local/apache223/logs/error_log-enfant
 TransferLog /usr/local/apache223/logs/access_log-enfant
 
 (略)
 </VirtualHost>
 
 <VirtualHost 192.168.1.31:443>
 
 #   General setup for the virtual host
 DocumentRoot "/usr/local/food"
 ##ServerName www.example.com:443
 ##ServerAdmin you@example.com
 ServerName food.abc-u.ac.jp:443
 ServerAdmin okada@abc-u.ac.jp
 ErrorLog /usr/local/apache223/logs/error_log-enfant
 TransferLog /usr/local/apache223/logs/access_log-enfant
 
 (略)
 </VirtualHost>


***余談 [#pbc08bb2]
WindowsXPのhostsファイルは

c:\windows\system32\drivers\etc\hosts

である。

**&aname(ssl){sslの設定}; [#cffad671]
Apache2からは configure時 --enable-sslオプションだけでopenssl,openssl-develがインストールされていれば利用できる。


キーは以下のように利用する。
 cd /usr/local/apache2/conf
 ln -s /etc/httpd/conf/ssl.crt .
 ln -s /etc/httpd/conf/ssl.key .

''Vine4.xでは''

 ln -s /etc/apache2/conf/ssl.crt .  (証明書 公開キー)
 ln -s /etc/apache2/conf/ssl.key .  (秘密キー)


自分で証明書を作成するには以下のようにする。

&color(red){''Vien4.xで作成方法は[[ここ>Linux Memo/Openssl]]にある。(Opensslはrpmインストール)''};

***openssl0.9.7.eでのトラブル [#r9018f46]
認証局を作成するために

# /usr/local/ssl/misc/CA.pl -newcaを実行すると

unknown option -next_serial

というエラー出る。

x509のオプションとしてこのバージョンでは-next_serialはないようだ。

そこで、/usr/local/ssl/misc/CA.plの107行目あたりを

 #               system ("$X509 -in ${CATOP}/$CACERT -noout "   <--コメントアウ ト
 #                       . "-next_serial -out ${CATOP}/serial");   <--コメントアウト

以下を追加する
                open OUT, ">${CATOP}/serial";
                print OUT "01\n";
                close OUT;
その結果
demoCA/serialというファイルが出来る。内容は
 01
という3バイトのファイル。

また、公開キーの作成時/usr/local/ssl/misc/CA.pl -signで

 Using configuration from /usr/share/ssl/openssl.cnf
 1215:error:0E06D06C:configuration file routines:NCONF_get_string:no
value:conf_lib.c:329:group=CA_default name=unique_subject
のようなエラーが出るが無視してもkeyは作成できた。

 # cd /root
 # mkdir sslfiles
 # cd sslfiles

***CA証明書の作成 [#f2bcbfd0]
(認証局[自分ところ]の作成)
 # /usr/local/ssl/misc/CA.pl -newca
 CA certificate filename (or enter to create) <---Enterのみ入力
 
 Making CA certificate ...
 Using configuration from /usr/share/ssl/openssl.cnf
 Generating a 1024 bit RSA private key
 ....++++++
 ......++++++
 writing new private key to './demoCA/private/cakey.pem'
 Enter PEM pass phrase:  <---パスワード入力(1)
 Verifying password - 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]:XXX Pref
 Locality Name (eg, city) []:ZZZ
 Organization Name (eg, company) [Internet Widgits Pty Ltd]:YYY University
 Organizational Unit Name (eg, section) []:
 Common Name (eg, your name or your server's hostname) []:uso5002.zzz.ac.jp
 Email Address []:okada@YYY.ac.jp


***サーバーキーの作成 [#m3d10b9d]
(秘密キーの作成)
 #  /usr/local/ssl/misc/CA.pl -newreq
 Using configuration from /usr/share/ssl/openssl.cnf
 Generating a 1024 bit RSA private key
 ...++++++
 ......++++++
 writing new private key to 'newreq.pem'
 Enter PEM pass phrase:<---パスワード入力(2)
 Verifying password - 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]:XXX Pref
 Locality Name (eg, city) []:ZZZ
 Organization Name (eg, company) [Internet Widgits Pty Ltd]:YYY University
 Organizational Unit Name (eg, section) []:ZZZ University
 Common Name (eg, your name or your server's hostname) []:uso5002.zzz.ac.jp
 Email Address []:okada@YYY.ac.jp 
 
 Please enter the following 'extra' attributes
 to be sent with your certificate request
 A challenge password []:  <---Enterのみ入力
 An optional company name []:  <---Enterのみ入力
 Request (and private key) is in newreq.pem


***サイト証明書の発行 [#lb6f1d09]
(公開キーの作成)
 #  /usr/local/ssl/misc/CA.pl -sign
 Using configuration from /usr/share/ssl/openssl.cnf
 Enter PEM pass phrase: <---CA証明書のときのパスワード(1)と同じパスワードを入力
 Check that the request matches the signature
 Signature ok
 The Subjects Distinguished Name is as follows
 countryName           :PRINTABLE:'JP'
 stateOrProvinceName   :PRINTABLE:'XXX Pref'
 localityName          :PRINTABLE:'ZZZ'
 organizationName      :PRINTABLE:'ZZZ University'
 organizationalUnitName:PRINTABLE:'ZZZ University'
 commonName            :PRINTABLE:'uso5002.YYY.ac.jp'
 emailAddress          :IA5STRING:'okada@YYY.ac.jp'
 Certificate is to be certified until Feb 11 07:57:55 2005 GMT (365 days)
 Sign the certificate? [y/n]:y
 
 
 1 out of 1 certificate requests certified, commit? [y/n]y
 Write out database with 1 new entries
 Data Base Updated
 Signed certificate is in newcert.pem


***認証局の確認 [#bde54565]
 # cd /root/sslfiles

自分で証明書を発行してときはself signed certificateになる
 # /usr/local/ssl/bin/openssl verify ./demoCA/cacert.pem
 ./demoCA/cacert.pem: /C=JP/ST=Mie Pref/L=Matsusaka/O=Matsusaka   Univ/CN=vvine30.abc-u.ac.jp/emailAddress=okada@abc-u.ac.jp
 error 18 at 0 depth lookup:self signed certificate
 OK

OKが出ないときは以下のコマンドを実行し、issuerとsubjectが同じことを確認する。
 # /usr/local/ssl/bin/openssl x509 -noout -issuer -subject - in ./demoCA/cacert.pem
 issuer= /C=JP/ST=Mie Pref/L=Matsusaka/O=Matsusaka Univ/CN=vvine30.abc-u.ac.jp/emailAddress=okada@matsusaka-u.ac.jp
 subject= /C=JP/ST=Mie Pref/L=Matsusaka/O=Matsusaka Univ/CN=vvine30.abc- u.ac.jp/emailAddress=okada@abc-u.ac.jp

確認が出来ないときはCAの作成がうまくできていない。

***証明書(秘密キー)の確認 [#gd81d244]

 # /usr/local/ssl/bin/openssl verify -CAfile ./demoCA/cacert.pem newcert.pem
newcert.pem: OK

認証局証明書が見つからないと以下のようなエラーが出る
 error 20 at 0 depth lookup:unable to get local issuer certificate

***証明書(秘密キー)の表示 [#u919b071]

 # /usr/local/ssl/bin/openssl  x509 -in newcert.pem -text
 Certificate:
     Data:
         Version: 3 (0x2)
         Serial Number: 1 (0x1)
         Signature Algorithm: md5WithRSAEncryption
         Issuer: C=JP, ST=Mie Pref, L=abc, O=abc Univ,  CN=vvine30.abc.ac.jp/emailAddress=okada@abc-u.ac.jp
         Validity
             Not Before: Nov 24 04:30:48 2004 GMT 
             Not After : Nov 24 04:30:48 2005 GMT
         Subject: C=JP, ST=Mie Pref, L=abc, O=abc Univ, OU=abc Univ, CN=vvine30.matsusaka-u.ac.jp/emailAddress=okada@abc-u.ac.jp
         Subject Public Key Info:
             Public Key Algorithm: rsaEncryption
             RSA Public Key: (1024 bit)
                 Modulus (1024 bit):
 (略)
 MSYwJAYJKoZIhvcNAQkBFhdva2FkYUBtYXRzdXNha2EtdS5hYy5qcIIBADANBgkq
 hkiG9w0BAQQFAAOBgQBsuaErU5zV1YIbokV5qPJxhYbKHbdb7F4LwqdhJEckNnlv
 nfHpYp7wtjbG+bESjiQ0IWoU17bSb3FW3xGGx1vvr0U/X2HDySQwTw4IrOMHJaIl
 Q+QyUMnS1vL4YI00RxGOXTd9dAnLUSyzxowHorn9/i42Ul1kij4xNMzv/fPSrA==
 -----END CERTIFICATE-----



***パスフレーズの解除 [#q61532f7]
パスフレーズの解除を行うと、起動時にパスフレーズを聞かれなくなる。

 # openssl rsa -in newreq.pem -out site.key
 read RSA key
 Enter PEM pass phrase:<---CA証明書のときのパスワード(1)と同じパスワードを入力
 writing RSA key

 #  chmod 400 site.key

注)パスワードの入力を求められる状態に戻したときは 
 # openssl rsa -des3 -in site.key -out site.key


***作成したファイルを配置 [#fff09da1]
 # mkdir /usr/local/apache2/conf/ssl.crt
 # mkdir /usr/local/apache2/conf/ssl.key
公開キーのコピー
 # cp newcert.pem /usr/local/apache2/conf/ssl.crt/newcert.crt
秘密キーのコピー
 # cp site.key /usr/local/apache2/conf/ssl.key/


***ssl.confの設定 [#m18531de]
/usr/local/apache2/conf/ssl.confを以下のように修正

 ##ServerName www.example.com:443
 ServerName uso5002.YYY.ac.jp:443
 ##ServerAdmin you@example.com
 ServerAdmin okada@YYY.ac.jp
 
 
 ##SSLCertificateFile /usr/local/apache2050/conf/ssl.crt/server.crt
 SSLCertificateFile /usr/local/apache2050/conf/ssl.crt/newcert.crt
 
 
 ##SSLCertificateKeyFile /usr/local/apache2050/conf/ssl.key/server.key
 SSLCertificateKeyFile /usr/local/apache2050/conf/ssl.key/site.key

''&color(red){SSL起動時注意};''

apache-2.2.xから、ssl版起動もbin/apachectl startで可能になった。

bin/apachectl sslstartとすると

The startssl option is no longer supported.

というエラーで起動できない


''DocumetRootをSSLだけ変更するには''

DocumentRoot "/usr/local/apache2050/htdocs"

を

DocumentRoot "/usr/local/apache2050/sslhtdocs"

のように変更する

(ただし、個人のディレクトリ[~okada]等はhttpでもhttpsどちらでも同じようにアクセスできる)

''VeriSign''~
承認してもらう公開キーの作成(奥村先生のページより)

 $ openssl md5 * >rand.dat (たとえば)
 $ openssl genrsa -rand rand.dat -des3 1024 >key.pem
 XXX semi-random bytes loaded
 Generating RSA private key, 1024 bit long modulus
 ......
 Enter PEM pass phrase: hogehoge
 Verifying password - Enter PEM pass phrase: hogehoge
 $ openssl req -new -key key.pem -out csr.pem
 Using configuration from /var/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]:Mie
 Locality Name (eg, city) []:Matsusaka
 Organization Name (eg, company) [Internet Widgits Pty Ltd]:Matsusaka University
 Organizational Unit Name (eg, section) []:Webserver Team
 Common Name (eg, YOUR name) []:secure.matsusaka-u.ac.jp
 Email Address []:webmaster@matsusaka-u.ac.jp
 
 Please enter the following 'extra' attributes
 to be sent with your certificate request
 A challenge password []:
 An optional company name []:
 
csr.pem は次のようなものです。  

 -----BEGIN CERTIFICATE REQUEST-----
 ほげほげほげ……
 -----END CERTIFICATE REQUEST-----



[[VeriSign テスト用認証取得:http://oku.edu.mie-u.ac.jp/~okumura/networking/ssl.html]]の仕方が奥村先生のページにある。
[[VeriSignのセキュアサーバIDの設定:https://wwwism.dyndns.org/hp/VeriSign.htm]]

**PDFlib+PHPのinstall [#j7433b25]
***zlibのインストールを確認 [#pbb89790]

 $ rpm -qa | grep zlib
 zlib-1.1.4-0vl2
 zlib-devel-1.1.4-0vl2

***PDFlibのinstall [#jde8e915]
''PDFlib-6.0.0のインストール''

このバージョンから作成したpdfファイルに「www.pdf.com」のスタンプが入る。

消すにはライセンスを購入する必要がある。

PDFlib-5.0.3には入らなかった。

PDFlib-Lite-6.0.0p1だけで実現できるようにするにはここ にあるようにインストール
すればよい。

php用のPDFlibはバイナリとしてPDFlib-6.0.0p1-Linux.tar.gzに入っている。~
それ以外のC++やPerl、その他のドキュメント等はPDFlib-Lite-6.0.0p1-Unix-src.tar.gz~
のソースからインストールする。(PHPのライブラリは入っていない)~

このバージョンはPHP4.3.0から4.3.6/5.0.0RC3をサポート。

php用のバイナリのコピー

 $ tar zxvf PDFlib-6.0.0p1-Linux.tar.gz
 $ su
 # cp PDFlib-6.0.0p1-Linux/bind/bind/php/php-50x/libpdf_php.so /usr/local/lib/

PDFlibのinstall(PHPで使用するときはいらないかも)

 $ tar zxvf PDFlib-Lite-6.0.0p1.tar.gz
 $ cd  PDFlib-Lite-6.0.0p1
 $ ./configure --with-tifflib --with-zlib --with-pnglib --with-jpeglib
configが終了すると
最後にサマリーが出る。
 For your convenience, here's a summary of configure's results:
 
 Support for shared libraries:           yes
 C++ language binding for PDFlib:        yes
 Java language binding for PDFlib:       no
 Perl language binding for PDFlib:       yes
 Python language binding for PDFlib:     yes
 Tcl language binding for PDFlib:        yes
 PHP language binding for PDFlib:        no, see bind/pdflib/php/readme.txt
 PDF import library (PDI):               no
      Note: if you purchase the additional PDF import library (PDI)
      you can also manipulate existing PDF documents with PDFlib.
      The additional block feature can be used to personalize PDF.
      See http://www.pdflib.com for details.
 
 Please observe the licensing terms for commercial PDFlib usage.
 PDFlib license agreement and purchase order can be found in the doc directory.
 
 $ make
 $ su
 # make install
 # exit

***libxml2のインストール [#g7ce6962]
PHP5からはlibxml2のVer.2.5以降が必要なため、 VinePlusでは2.4.xではバージョンが古いためソースからインストール ここからDownlaod

 $ tar zxvf libxml2-2.6.11.tar.gz
 $ libxml2-2.6.11
 $ ./configure --with-zlib=/usr/lib
 $ make
 $ make tests
 ## XML regression tests
 ## XML regression tests on memory
 (略)
 ## examples regression tests
 make[1]: 出ます ディレクトリ `/usr/local/src/libxml2-2.6.11/doc/examples'
 
 $ su
 # make install

''libxml2-devel-2.6.9-0vl1.i386.rpmをインストールしてもよい。''

''PDFlib-5.0.3のインストール(旧バージョン)''

php用のPDFlibはバイナリとしてPDFlib-5.0.3-Linux.tar.gzに入っている。~
それ以外のC++やPerl、その他のドキュメント等はPDFlib-Lite-5.0.3-Unix-src.tar.gz~
のソースからインストールする。(PHPのライブラリは入っていない)~

このバージョンはPHP4.1.0から4.3.3をサポート。

php用のバイナリのコピー

 $ tar zxvf PDFlib-5.0.3-Linux.tar.gz
 $ su
 # cp PDFlib-5.0.3-Linux/bind/php/php-4.2.1/libpdf_php.so /usr/local/lib/

PDFlibのinstall(PHPで使用するときはいらないかも)

 $ tar zxvf PDFlib-Lite-5.0.3-Unix-src.tar.gz
 $ cd  PDFlib-Lite-5.0.3-Unix-src
 $ ./configure --with-tifflib --with-zlib --with-pnglib --with-jpeglib
configが終了すると

最後にサマリーが出る。

 For your convenience, here's a summary of configure's results:
 
 Support for shared libraries:           yes
 C++ language binding for PDFlib:        yes
 Java language binding for PDFlib:       no
 Perl language binding for PDFlib:       yes
 Python language binding for PDFlib:     yes
 Tcl language binding for PDFlib:        yes
 PHP language binding for PDFlib:        no, see bind/pdflib/php/readme.txt
 PDF import library (PDI):               no
      Note: if you purchase the additional PDF import library (PDI)
      you can also manipulate existing PDF documents with PDFlib.
      The additional block feature can be used to personalize PDF.
      See http://www.pdflib.com for details.
 
 Please observe the licensing terms for commercial PDFlib usage.
 PDFlib license agreement and purchase order can be found in the doc directory.

 $ make
 $ su
 # make install
 # exit

**PHPのinstall [#ee048c81]
Vine3.0では、flexとflexで必要なyaccがどうもないようなでインストールする。~
また、zlib-devel-1.1.4-0vl3.i386.rpmもインストールが必要。~

(develはVine-3.0/i386/Vine/RPMS.devel/にある)

***flexに関する問題 [#leca6fe6]
rpmからインストール

コマンド(apt-get)でflex、bisonをインストールしてもOK
 # apt-get update
 # apt-get install flex
 パッケージリストを読みこんでいます... 完了
 依存情報ツリーを作成しています... 完了
 以下のパッケージが新たにインストールされます:
   flex
 アップグレード: 0 個, 新規インストール: 1 個, 削除: 0 個, 保留: 0 個
 119kB のアーカイブを取得する必要があります。
 展開後に 242kB のディスク容量が追加消費されます。
 取得:1 http://updates.vinelinux.org 3.1/i386/plus flex 2.5.4a-30vl1 [119kB]
 119kB を 0s 秒で取得しました (462kB/s)
 変更を適用しています...
 Preparing...                ########################################### [100%]
    1:flex                   ########################################### [100%]
 完了

 apt-get install bison
 パッケージリストを読みこんでいます... 完了
 依存情報ツリーを作成しています... 完了
 以下のパッケージが新たにインストールされます:
   bison
 アップグレード: 0 個, 新規インストール: 1 個, 削除: 0 個, 保留: 0 個
 290kB のアーカイブを取得する必要があります。
 展開後に 661kB のディスク容量が追加消費されます。
 取得:1 http://updates.vinelinux.org 3.1/i386/plus bison 1.875-6vl1 [290kB]
 290kB を 0s 秒で取得しました (1185kB/s)
 変更を適用しています...
 Preparing...                ########################################### [100%]
    1:bison                  ########################################### [100%]
 完了

これで、yaccのソースインストールも不要。


--------------------------------------------------------------------------------

***ソースからインストール(yaccのインストール) [#v4b80bb4]
Yacc とは Yet Another Compiler Compiler を表します。 Yacc の GNU 版は Bison と呼ばれています。 これは、言語を記述する文法を、その言語のパーサーに変換するツールです。

適当なところがわからなかったので[[ここ]]からDownload。 
 $ tar zxvf byacc-1.9.tar.gz
 $ cd byacc-1.9
 $ make
 cc -O -DNDEBUG   -c -o closure.o closure.c
 cc -O -DNDEBUG   -c -o error.o error.c
 (略)
 
 Loading yacc ... main.o(.text+0x460): In function `create_file_names':
 : warning: the use of `mktemp' is dangerous, better use `mkstemp'
 done 
 
 $ su
 # cp yacc /usr/local/bin

***flexのインストール [#de6b565c]
flex はスキャナを生成するツールです。スキャナとはテキストの中にある構 造を認識するプログラムです。flex は与えられたファイルの記述を読みこん でスキャナを生成します。

[[ここ:ftp://ftp.gnu.org/pub/non-gnu/flex/]]からDownload。 
 $ tar zxvf  flex-2.5.4a.tar.gz
 $ cd flex-2.5.4
 $ configure
 $ make
 $ su
 # make install

***phpのインストール [#m752d9e8]
 $ tar jxvf php-5.0.0.tar.bz2
 $ cd php-5.0.0
 $ ./configure --with-zlib-dir=/usr/lib --with-jpeg-dir=/usr/lib \
 --with-png-dir=/usr/lib --with-tiff-dir=/usr/lib \
 [--with-pdflib=/usr/local \ <---(/usr/local/libではない)] <--不要かも?
 --with-apxs2=/usr/local/apache2/bin/apxs \
 --with-pgsql --without-mysql --enable-mbstring \
 --enable-mbstr-enc-trans --enable-mbregex \
 [--with-libxml-dir=/usr/local] <--不要かも?
 --with-gd

 Thank you for using PHP.<---(最後の行)

 $ make
 Build complete.
 (It is safe to ignore warnings about tempnam and tmpnam).<---(最後の行)
 $ su
 # make install

初めてのインストールのときは
 # cp php.ini-recommended /usr/local/lib/php.ini

(PDFlib-6.0.0p1では以下2箇所を変更追加する)

php.iniの

 extension_dir = "./"
 を
 extension_dir = "/usr/local/lib"
 に変更
 
 extension=libpdf_php.so
 を追加

/usr/local/apache2/conf/httpd.confに以下を追加

 LoadModule php5_module        modules/libphp5.so

 AddType application/x-httpd-php .php

確認
 $ /usr/local/bin/php -i | grep PDF
 PDF Support => enabled
 PDFlib GmbH Binary-Version => 6.0.0p1

apacheを再起動

# /usr/local/apache2/bin/apachectl sslstart

&color(red){phpのバージョンをあげた時はapache2.2.xの再起動はrestartでなく、stop,startの必要がある。};

以下の1行のinfo.php

 <?php
 phpinfo();
 ?>

でPDFセッション(pgsqlの前あたり)の確認


[[ここ:https://wwwism.dyndns.org/hp/pdflib-s.htm]]のサンプルで動作確認をする。

configureでどのようなオプションをつけたを表示
 $ cd /usr/local/bin
 $ ./php -i
 phpinfo()
 PHP Version => 5.0.1
 
 System => Linux uso5001.abc-u.ac.jp 2.4.27-0vl7.2 #1 Sat Dec 11  17:29:33 JST 2004 i686
 Build Date => Sep  1 2004 12:05:19
 Configure Command =>  './configure' '--with-zlib-dir=/usr/lib' '--with-jpeg-\
 dir=/usr/lib' '--with-png-dir=/usr/lib' '--with-tiff-dir=/usr/lib' \
 '--with-apxs2=/usr/local/apache2/bin/apxs' '--with-pgsql' '--without-mysql' \
 '--enable-mbstring' '--enable-mbstr-enc-trans' '--enable-mbregex'
 Server API => Command Line Interface
 Virtual Directory Support => disabled
 (以下略)

**脆弱性 [#m487f453]
4.3.7以前のすべてのバージョン

5.0.0RC3以前のすべてのバージョン

で--enable-memory-limitが有効のときPHPに対してデータをPOSTするだけで、
任意のコードを実行できる脆弱性がある。4.2.0以降は --enable-memory-limit
はconfigureの標準設定では無効になっている。(2004/7/15)

[[参考:http://slashdot.jp/developers/article.pl?sid=04/07/15/0337223&topic=56&mode=thread]]

***参考ページ [#l26d27c7]
[[奥村先生のページ:http://oku.edu.mie-u.ac.jp/~okumura/linux/?Apache%202]] 

[[Apacheパラメータ>Linux Memo/Apache2.x/Apacheパラメータ]]
--------------------------------------------------------------------------------
RIGHT:[[元ページ:http://wwwism.dyndns.org/hp/linux/apache2.htm]]


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS