CentOS サーバー構築マニュアル

home > CentOS5 > Apache2 PHP5 ImageMagick インストール

Apache2 PHP5 ImageMagick インストール




■Apache2 インストール
[root@ns1 ~]# yum -y install httpd
[root@ns1 ~]# yum clean packages

■httpd.conf編集
[root@ns1 ~]# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.org
[root@ns1 ~]# vi /etc/httpd/conf/httpd.conf

ServerTokens OS
↓
ServerTokens Prod ←変更(サーバーの情報を隠す)

KeepAlive Off
↓
KeepAlive On ←変更(クライアントとの接続を保持する)

ServerAdmin root@localhost
↓
ServerAdmin hostmaster@centos.orz ←変更(管理者のメールアドレスを記載)

#ServerName www.example.com:80
↓
ServerName www.centos.orz:80 ←コメント解除&変更(ホスト名を記載)

DocumentRoot "/var/www/html"
↓
DocumentRoot "/home/hoge/public_html" ←変更(ドキュメントルートを変更)

<Directory "/var/www/html">
↓
<Directory "/home/hoge/public_html"> ←変更(ディレクトリを変更)

#
# Possible values for the Options directive are "None", "All",
# or any combination of:
#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important.  Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
    Options Indexes FollowSymLinks
    ↓
    Options Includes ExecCGI FollowSymLinks ←変更(CGI,SSIを許可。ファイル一覧表示禁止)

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
    AllowOverride None
    ↓
    AllowOverride All ←変更(.htaccess許可)

#
# Controls who can get stuff from this server.
#
    Order allow,deny
    Allow from all

</Directory>

    UserDir disable
    ↓
    #UserDir disable ←コメントアウト(ユーザーディレクティブを許可)

    #UserDir public_html
    ↓
    UserDir public_html ←コメント解除(ユーザーのディレクトリをpublic_htmlとする)

↓下記をコメント解除
<Directory /home/*/public_html>
    #AllowOverride FileInfo AuthConfig Limit Indexes
    ↓
    AllowOverride All ←変更(.htaccess許可)

    #Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    ↓
    Options Includes ExecCGI FollowSymLinks ←変更(CGI,SSIを許可。ファイル一覧表示禁止)
    <Limit GET POST OPTIONS PROPFIND>
        Order allow,deny
        Allow from all
    </Limit>
    <LimitExcept GET POST OPTIONS PROPFIND>
        Order deny,allow
        Deny from all
    </LimitExcept>
</Directory>
↑上記をコメント解除

DirectoryIndex index.html index.html.var
↓
DirectoryIndex index.html index.htm index.cgi index.php ←変更(index.cgi index.phpを追加)

ErrorLog logs/error_log
↓
ErrorLog /var/log/httpd/hoge-error_log ←変更(エラーログ)

CustomLog logs/access_log combined
↓
SetEnvIf Request_URI "default\.ida" nolog
SetEnvIf Request_URI "cmd\.exe" nolog
SetEnvIf Request_URI "root\.exe" nolog
SetEnvIf Request_URI "Admin\.dll" nolog
SetEnvIf Request_URI "NULL\.IDA" nolog
SetEnvIf Request_URI "\.(gif)|(jpg)|(png)|(ico)|(css)$" nolog
CustomLog /var/log/httpd/hoge-access_log combined env=!nolog ←変更(アクセスログ)

ServerSignature On
↓
ServerSignature Off ←変更(Apacheのバージョン情報を隠す)

AddLanguage ja .ja ←この行を最上位に移動

LanguagePriority ja ←jaを先頭に移動

AddDefaultCharset UTF-8
↓
#AddDefaultCharset UTF-8 ←コメントアウト(デフォルトの文字コードを設定しない)

AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php ←追加(.phpを使えるようにする)

#AddHandler cgi-script .cgi
↓
AddHandler cgi-script .cgi .pl ←コメント解除&変更(.cgi .plを使えるようにする)

#NameVirtualHost *:80
↓
NameVirtualHost *:80 ←コメント解除(バーチャルホスト許可)
※黄色い部分は環境に合わせて変更してください。

■VirtualHost設定
[root@ns1 ~]# vi /etc/httpd/conf.d/virtual.conf

↓下記を記入
<VirtualHost *:80>
    ServerName any
    DocumentRoot /tmp
</VirtualHost>
<VirtualHost *:80>
    ServerName www.centos.orz
    ServerAlias centos.orz
    ServerAdmin hostmaster@centos.orz
    DocumentRoot /home/hoge/public_html
    ErrorLog /var/log/httpd/hoge-error_log
    CustomLog /var/log/httpd/hoge-access_log combined env=!nolog
</VirtualHost>

■mod_deflate(ファイル圧縮転送)設定
[root@ns1 ~]# vi /etc/httpd/conf.d/deflate.conf

↓下記を記入
<Location />
  # Insert filter
  SetOutputFilter DEFLATE

  # Netscape 4.x has some problems...
  BrowserMatch ^Mozilla/4 gzip-only-text/html

  # Netscape 4.06-4.08 have some more problems
  BrowserMatch ^Mozilla/4\.0[678] no-gzip

  # MSIE masquerades as Netscape, but it is fine
  # BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

  # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
  # the above regex won't work. You can use the following
  # workaround to get the desired effect:
  BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

  # Don't compress images
  SetEnvIfNoCase Request_URI \
      \.(?:gif|jpe?g|png|ico|z|taz|t?gz|t?bz2?|zip|lzh|sit|rar|pdf|mp3|ogg|wma|rm|wmv|mov|mpe?g)$ \
      no-gzip dont-vary

  # Make sure proxies don't deliver the wrong content
  Header append Vary User-Agent env=!dont-vary
</Location>

■welcome.confリネーム
[root@ns1 ~]# mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf.org

■PHP5 インストール
[root@ns1 ~]# yum -y install php php-mbstring php-mysql
[root@ns1 ~]# yum clean packages

■php.ini編集
[root@ns1 ~]# cp /etc/php.ini /etc/php.ini.org
[root@ns1 ~]# vi /etc/php.ini

expose_php = On
↓
expose_php = Off ←変更(バージョンを隠す)

;error_log = filename
↓
error_log = /var/log/httpd/php-error.log ←コメント解除&変更(エラーログ保存)

;default_charset = "iso-8859-1"
↓
default_charset = "UTF-8" ←コメント解除&変更(デフォルト文字コードをUTF-8に変更)

;mbstring.language = Japanese
↓
mbstring.language = Japanese ←コメント解除(デフォルト言語)

;mbstring.internal_encoding = EUC-JP
↓
mbstring.internal_encoding = UTF-8 ←コメント解除&変更(内部文字エンコーディングのデフォルト値)

;mbstring.http_input = auto
↓
mbstring.http_input = auto ←コメント解除(HTTP入力文字エンコーディング)

;mbstring.http_output = SJIS
↓
mbstring.http_output = pass ←コメント解除&変更(HTTP出力文字エンコーディング)

;mbstring.encoding_translation = Off
↓
mbstring.encoding_translation = On ←コメント解除&変更(内部文字エンコーディングの有効・無効)

;mbstring.detect_order = auto
↓
mbstring.detect_order = auto ←コメント解除(文字コード検出のデフォルト値)

;mbstring.substitute_character = none;
↓
mbstring.substitute_character = none; ←コメント解除(無効な文字を代替する文字を定義)

■ImageMagick インストール
[root@ns1 ~]# yum -y install ImageMagick ImageMagick-perl
[root@ns1 ~]# yum clean packages

■Apache起動
[root@ns1 ~]# /etc/rc.d/init.d/httpd start
[root@ns1 ~]# chkconfig httpd on
[root@ns1 ~]# chkconfig --list httpd
httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off

■perlとconvertのシンボリックリンク作成
[root@ns1 ~]# ln -s /usr/bin/perl /usr/local/bin/perl
[root@ns1 ~]# ln -s /usr/bin/convert /usr/local/bin/convert

外部に公開する場合 外部に公開する場合

プロトコル(TCP)ポート80番(HTTP)を開放。



Home PageTop Forum Last updated 2008-05-12

Copyright centos.server-manual.com このサイトはリンクフリーです。ご自由にリンクしてください。