Apacheをrpmでインストール

更新日 2012-10-16 (火) 11:28:46

Vine5xでのmod-sslがLoadできない問題対策

Vine5.1で修正され不要になった

httpd.confにmod-sslのloadを追加しファイルファイルの最後にextra/httpd-ssl.confを指定。Vine4xまでは conf.d/ssl.confがこのファイルだったがVine5ではファイルはあるが知らない書式が書かれている。現在は内容は不明。

LoadModule mem_cache_module modules/mod_mem_cache.so
LoadModule cgi_module modules/mod_cgi.so 

LoadModule ssl_module modules/mod_ssl.so <=追加

#
# The following modules are not loaded by default:


最後に以下を追加

Include conf/extra/httpd-ssl.conf

LoadModuleしないと以下のエラーで起動できない

Invalid command 'SSLPassPhraseDialog', perhaps misspelled or defined by a module not included in the server configuration

Aliasでディレクトリ設定

/etc/apache2/conf.d/openpne.conf

Alias /openpne /var/www/OpenPNE/public_html

というファイルを作成すればよい

Apacheの確認

以下のrpmがあればOK,なければインストール

apache2-manual-2.2.3-0vl3
apache2-2.2.3-0vl3
mod_ssl-apache2-2.2.3-0vl3

/etc/apache2にconf等のファイルがある。
/var/wwwにアクセスさせるホームページがある。

ユーザでの利用

デフォルトでは~userではアクセスできないので以下のようhttp.confを変更

<IfModule mod_userdir.c>
    #
    # UserDir is disabled by default since it can confirm the presence
    # of a username on the system (depending on home directory
    # permissions).
    #
##    UserDir disable   <==コメントアウト

    #
    # To enable requests to /~user/ to serve the user's public_html
    # directory, remove the "UserDir disable" line above, and uncomment
    # the following line instead:
    #
    #UserDir public_html
    UserDir public_html <==コメントアウトを削除

</IfModule>

# 
# Control access to UserDir directories.  The following is an example
# for a site where these directories are restricted to read-only.
#
          (以下コメントアウトを削除)
<Directory /home/*/public_html>
    AllowOverride FileInfo AuthConfig Limit
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    <Limit GET POST OPTIONS>
        Order allow,deny
        Allow from all
    </Limit>
    <LimitExcept GET POST OPTIONS>
       Order deny,allow
       Deny from all
    </LimitExcept>
</Directory>

その他の変更(http.conf)

##DirectoryIndex index.html index.html.var
DirectoryIndex index.html index.htm index.php index.cgi index.pl index.shtml
##LanguagePriority en ja 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
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

起動

/etc/rc.d/init.d/apache2 start

1.xがhttpdで起動してる場合は起動を停止する。

SSL

/etc/apache2/conf.d/ssl.confに公開キーや秘密キーの設定がある。

ベリサインの証明書のインストール

/etc/apache2/conf.d/ssl.conf中に公開キーと秘密キーが指定されている

サーバキー(秘密キー)
SSLCertificateKeyFile /etc/apache2/conf/ssl.key/server.key

証明書(公開キー)
SSLCertificateFile /etc/apache2/conf/ssl.crt/server.crt

をベリサインのキーに書き換える

さらに新規の場合は中間CA証明書も指定する。 このキーは毎年変更する必要はない

https://www.verisign.co.jp/repository/intermediate/server/c3SecureServerCA_1024.html

に中間CA証明書があるのですべてコピーし適当なファイル名(inca.pem)で保存.

SSLCertificateChainFile /etc/apache2/conf/inca.pem

として指定する。
(Vine4.xはApache+mod_SSLで動作している)

その後再起動

中間CA証明書はNetscape7でないと確認できない。また最近のブラウザは中間CA証明書がなくても、ベリサインのページ取りに行くようで動作するが、場合によってはうまく動作しない場合があり、初めてのアクセス時に認証できないとか認証期間切れ等のエラーが出る。一度OKすると2回目からは聞きかれないが・・・

参考

http://www.verisign.co.jp/ssl/help/install/iapache_new_intca_s.html


以下のファイル(MySQL,PostgreSQL)は Vine Plusにある

MySQLのインストール

# apt-get install mysql
# apt-get install mysql-client

必要に応じ mysql-XXXをインストール

確認

$ rpm -qa | grep MySQL
MySQL-server-5.0.27-0vl3
MySQL-client-5.0.27-0vl3
MySQL-shared-5.0.27-0vl3

設定ファイルを/etcに作成

# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf 

defaultの文字コードをutfに設定

/etc/my.cnfに追加

[mysqld]

デフォルトのサーバ文字コードを指定
default-character-set=utf8 ← 追加(ujis, sjis, utf8等が指定可能)

サーバーの文字コード設定をクライアントでもそのまま使う
skip-character-set-client-handshake ← 追加

PostgreSQLのインストール

# apt-get install postgresql
# apt-get install postgresql-server

いくつかのコマンドは/usr/binにある (createdb等)
環境ファイルは/var/lib/pgsql/dataにある

必要に応じ postgresql-XXXをインストール

phpのインストール

# apt-get install php5-apache2
# apt-get install php5-pgsql
# apt-get install php5-mysql

php.ini等は/etc/php5のしたにある

設定内容はソースからインストールと同じように行う

注)indexの拡張子の表示順序はhttpd.confでよりphpについてはconf.d/php5.confの以下の部分が優先されるためコメントアウトする

# DirectoryIndex index.php index.phtm

php.iniについての注意

Vine5xでは以下のようにしなとエラーが出る(phpのバージョンの問題なようだ。今回バージョンはphp5-5.3.0)

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
;date.timezone =
date.timezone = Asia/Tokyo  <==指定が必要

プログラムでの対応は

<?php
ini_set("date.timezone", "Asia/Tokyo");
?>

エラー内容

It is not safe to rely on the system's timezone settings.
Please use the date.timezone setting, the TZ environment variable or the
 date_default_timezone_set() function.
In case you used any of those methods and you are still getting this warning, 
you most likely misspelled the timezone identifier.
We selected 'Asia/Tokyo' for '9.0/no DST' instead

php.iniの最後にVineで追加された項目がある。

[Vine]
output_buffering = Off
expose_php = Off
;;memory_limit = 32M
memory_limit = 512M
variables_order = "GPCS"
;;default_charset = EUC-JP
extension_dir = /usr/lib/php5

この部分のdefault_charset = EUC-JPが有効だと、送られたHTTPのヘッダーに

Content-Type: text/html; default_charset=EUC-JP

が無条件で付き、作成したphpファイルのヘッダーに

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

と記入してもutf-8としてブラウザが判断しないので、文字化けになるので コメントアウトしておく。文字コードはphpファイルで指定するようにしておく

その他メモリの指定もここにされているので注意する

さらにmoodleでutf8でもトラブルがあったので以下をコメントアウト

;;mbstring.language = Japanese
;;mbstring.internal_encoding = EUC-JP
;;mbstring.http_input = auto
;;mbstring.http_output = pass
;;mbstring.encoding_translation = On

Directoryディレクティブの意味

All
MultiViewsを除くすべてのオプションを有効にします。MultiViewsを有効にしたい場合には、明示的にMultiViewsを追加する必要がある

FollowSymLinks
ファイルシステム内の別の場所にシンボリックリンクを作成して表示用のファイルを保持したい場合があります。このためには少なくともFollowSymLinksオプションを有効にする

SymLinksifOwnerMatch
所有者が一致した場合にのみシンボリックリンク経由でのアクセスを許可

Multiviews
HTTP/1.1 の規格に記述されているコンテントネゴシエーションの1形態であるマルチビューを有効にするためのオプション
例えば/usr/local/apache2/htdocs/testにリクエストがありtestというファイルが存在しない場合に、Apacheはディレクトリ内のtest.*をすべて検索し最適なファイルをユーザに返す

AllowOverride
該当ディレクトリに存在する.htaccessファイルによって上書きされる(許可)ディレクティブの種類を指定します。All・Noneもしくは個別のディレクティブの組み合わせで指定することが可能
「AllowOverride None」は.htaccessファイル内に記述されているディレクティブは使用されない。
「AllowOverride AuthConfig」は.htaccess内のAuthType・AuthUserFile・AuthName・Requireディレクティブの設定値の上書きが許可

Order
ホストに対するデフォルトのアクセス可能状態と、Allow/Deny ディレクティブの評価順を指定する

allow,deny (デフォルト)
allow -> deny順に評価されるのですべて拒否

deny,allow
deny -> allow順に評価されるのですべて許可

Allow from all | host または Deny from all | host
「Allow from all」はすべて許可「Allow from apache.org」はDNS名の一部
「Allow from 192.168.11.0/24」 ネットワークアドレスを許可

<Limit method ...> </Limit>と<LimitExcept method ...> </LimitExcept>は反対の意味を持つ

Virtual Host(IPベース)

Host名 v-host
IP 192.168.30.18
ドキュメントroot /usr/local/enfant

/etc/apache2/conf/httpd.confの最後の行に以下を追加

Include conf/extra/httpd-vhosts.conf

extra/httpd-vhosts.confのサンプルを見ながら、サンプルを以下のように修正

##<VirtualHost *:80>
##    ServerAdmin webmaster@dummy-host.example.com
##    DocumentRoot /www/docs/dummy-host.example.com
##    ServerName dummy-host.example.com
##    ServerAlias www.dummy-host.example.com
##    ErrorLog /var/log/apache2/dummy-host.example.com-error_log
##    CustomLog /var/log/apache2/dummy-host.example.com-access_log common
##</VirtualHost>

##<VirtualHost *:80>
##    ServerAdmin webmaster@dummy-host2.example.com
##    DocumentRoot /www/docs/dummy-host2.example.com
##    ServerName dummy-host2.example.com
##    ErrorLog /var/log/apache2/dummy-host2.example.com-error_log
##    CustomLog /var/log/apache2/dummy-host2.example.com-access_log common
##</VirtualHost>

(以下を追加)
<VirtualHost *:80>
##    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot /usr/local/v-host
    ServerName v-host.abc-u.ac.jp
    ErrorLog /var/log/apache2/v-host-error_log
    CustomLog /var/log/apache2/v-host-access_log common
</VirtualHost>

httpd.confの最後あたりのVirtual Hostの設定はHost名ベースのバーチャルホストのようでsslがたぶん対応できないと思う。

またailiasでディレクトリ指定するときは、以下のように<VirtualHost *:80>の中に指定する。このとき、ディレクティブアクセス内容はhttpd.confに指定してあればいいようだ

<VirtualHost *:80>
    DocumentRoot /var/www/html
    ServerName manabi.abc.ac.jp
    ErrorLog /var/log/apache2/error_log
    CustomLog /var/log/apache2/access_log common
    Alias       /moodle/  "/var/www/moodle/"   <==ここ

</VirtualHost>

しかし、このときServerNameがmanabi.abc.ac.jpなため、IPアドレスや,HOST名だけでアクセスされた場合はデフォルトで一番初めに指定した<VirtualHost *:80>にアクセスされるため、この表記が一番初めの場合はmanabi.abc.ac.jp以外でも指定バーチャルホスト指定外では表示されてしまうようだ。

次のSSLでも同じように

Alias /moodle/ "/var/www/moodle/"

を追加する

SSLも追加

/etc/apache2/conf.d/ssl.confの中の以下の部分をコピーし編集する。

デフォルトでVine4.xはこちらを参照するようだ/etc/apache2/conf/extra/httpd-ssl.confは/etc/apache2/conf/httpd.confでIncludeすればいいのかもしれないがまだ不明

##
## SSL Virtual Host Context
##

(以下の場所はDefaultでメインを指定する=>特に編集必要なし)
<VirtualHost _default_:443>

#  General setup for the virtual host
DocumentRoot "/var/www/html"
ServerName new.host.name:443
ServerAdmin you@your.address
ErrorLog logs/ssl_error_log
TransferLog logs/ssl_access_log

(略)

</VirtualHost>

(以下追加)

##
## SSL Virtual Host2(enfant) Context
##

##<VirtualHost _default_:443>
<VirtualHost 192.168.30.18:443>

#  General setup for the virtual host
DocumentRoot "/usr/local/v-host"
ServerName v-host.abc-u.ac.jp:443
##ServerAdmin you@your.address
ErrorLog logs/enfant-ssl_error_log
TransferLog logs/enfant-ssl_access_log

(略)

</VirtualHost>

あとはApacheを再起動

Vine3.xでの問題

phpを有効のして起動すると

# /etc/rc.d/init.d/apache2 start
httpdを起動中: [Mon Sep 08 09:33:50 2008] [crit] Apache is running a threaded  
MPM, but your PHP Module is not compiled to be threadsafe.  You need to  recompile PHP.
Pre-configuration failed

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

Vine3.xにおけるapache2のデフォルトはworkerモデルになっており,phpのモジュール版はpreforkモデルでないと正しく動作しない.apache2をpreforkモデル に変更するには以下のようにする.

# /sbin/update-alternatives --config apache2

There are 4 alternatives which provide `apache2'.

  Selection    Alternative
-----------------------------------------------
*+    1        /usr/sbin/apache2.worker
      2        /usr/sbin/apache2.prefork
      3        /usr/sbin/apache2.threadpool
      4        /usr/sbin/apache2.perchild

Press enter to keep the default[*], or type selection number: 2 <=2を選択
Using `/usr/sbin/apache2.prefork' to provide `apache2'.

文字化け

Apache2の仕様の問題で、デフォルトの文字設定(ISO-8859-1)では、日本語が文字化けします。(htmlのcharsetは無視される) これを正常に日本語表示可能にするにはhttpd.confに以下のように追記

AddDefaultCharset ISO-8859-1
(以下を追加)
AddDefaultCharset shift_jis
AddDefaultCharset EUC-JP
AddDefaultCharset none

個人ディレクトリでCGI(Perl)が動かない問題

Vine4.xは大丈夫そう?

/etc/apache2/logs/error_log

[Tue Sep 09 11:21:16 2008] [error] [client 202.59.188.153] (13)Permission
denied: exec of '/usr/lib/apache2/suexec' failed

suEXECがオンになっている最近の設定で,番号の低いグループでCGIが動かないといったトラブルが発生するみたい

/usr/lib/apache2/suexecをリネームする

apt-get でまた入る可能性あり

# /usr/lib/apache2/suexec.err -V
 -D AP_DOC_ROOT="/var/www"
 -D AP_GID_MIN=500
 -D AP_HTTPD_USER="apache"
 -D AP_LOG_EXEC="/var/lib/log/apache2/suexec.log"
 -D AP_SAFE_PATH="/usr/local/bin:/usr/bin:/bin"
 -D AP_UID_MIN=500
 -D AP_USERDIR_SUFFIX="public_html"

個人のホームディレクトリに public_html ディレクトリを作り,その中に index.html を入れてうまくいかない場合は,たいていホームディレクトリのパーミッションが悪いのでしょう。 700ではうまくいきません。少なくとも 701 にしておく必要があります。

参考ページ

Apache基本設定


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