apacheのバージョンアップ

サーバー更新に伴いapacheをバージョンアップしたので手順をメモる。

 

ダウンロード

以下のサイトからダウンロードする。
Download – The Apache HTTP Server Project
Windows版はApache VS17 binaries and modules download (apachelounge.com)
現時点の最新版 「httpd-2.4.57-win64-VS17.zip」

インストール

現バージョンとは別の適当なフォルダーに展開する。
他システムへの移行等を考慮してOSのCドライブは避ける。例:D:\Program Files\Apache24

設定ファイル

各設定変更ファイル一覧 (該当箇所のみ記載)
・httpd.conf
・httpd-ssl.conf
・httpd-vhosts.conf
・httpd-mpm.conf

httpd.conf

Define SRVROOT "d:/Program Files/Apache24"
ServerRoot "${SRVROOT}"
#
LoadModule access_compat_module modules/mod_access_compat.so
LoadModule headers_module modules/mod_headers.so
LoadModule md_module modules/mod_md.so
LoadModule php_module "d:/Program Files/php/php8apache2_4.dll"
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
LoadModule ssl_module modules/mod_ssl.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule watchdog_module modules/mod_watchdog.so
 
User apache
Group user

# ServerAdmin: Your address, where problems with the server should be
# e-mailed.  This address appears on some server-generated pages, such
# as error documents.  e.g. admin@your-domain.com
#
ServerAdmin admin@example.com
 
ServerName localhost:80
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
#DocumentRoot "D:/www/public_html" <<<<<コメントアウト 「httpd-ssl.conf」の個別ディレクティブ指定
< Directory "D:/www/public_html">
    #
    Options -Indexes +FollowSymLinks +ExecCGI
    Options +Includes
    #
    AllowOverride All
    #
    Require all granted
</Directory>
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.html index.htm index.shtml index.shtm index.php index.cgi index.pl
</IfModule>
 
#
# The following lines prevent .htaccess and .htpasswd files from being 
# viewed by Web clients. 
#
<Files ".ht*">
    Require all denied
</Files>
#
<IfModule alias_module>
    #
    ScriptAlias /cgi-bin/ "${SRVROOT}/cgi-bin/"
</IfModule>
#
<Directory "${SRVROOT}/cgi-bin">
    AllowOverride None
    Options None
    Require all denied
</Directory>
<IfModule mime_module>

    TypesConfig conf/mime.types

    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz

    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
    AddType application/x-httpd-cgi .cgi
    AddType application/x-httpd-cgi .pl

    AddHandler php-script .php
    AddHandler cgi-script .cgi .pl

    PHPIniDir "d:/Program Files/php"
    LoadFile  "d:/Program Files/php/php8ts.dll"
    LoadFile  "d:/Program Files/php/libssh2.dll"
    LoadFile  "d:/Program Files/php/nghttp2.dll"
    LoadFile  "d:/Program Files/php/libcrypto-1_1-x64.dll"
    LoadFile  "d:/Program Files/php/libssl-1_1-x64.dll"
    LoadFile  "d:/Program Files/php/libsqlite3.dll"

    AddType text/x-server-parsed-html .shtml
    Options Includes
    AddOutputFilter INCLUDES .shtml
</IfModule>
 
#
# Server-pool management (MPM specific)
Include conf/extra/httpd-mpm.conf
 
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
 
# Secure (SSL/TLS) connections
Include conf/extra/httpd-ssl.conf
#
# Note: The following must must be present to support
#       starting without SSL on platforms with no /dev/random equivalent
#       but a statically compiled-in mod_ssl.
#
< IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
< /IfModule>

httpd-ssl.conf

MDomain hoge.com
< VirtualHost _default_:443>
#   General setup for the virtual host
DocumentRoot "D:/www/public_html"
ServerName hoge.com
ServerAlias www.hoge.com
ServerAdmin admin@example.com
ErrorLog "${SRVROOT}/logs/error.log"
TransferLog "${SRVROOT}/logs/access.log"
 
#   SSL Engine Switch:
#   Enable/Disable SSL for this virtual host.
SSLEngine on
 
#SSLCertificateFile "${SRVROOT}/conf/server.crt"
#SSLCertificateFile "${SRVROOT}/conf/server-dsa.crt"
#SSLCertificateFile "${SRVROOT}/conf/server-ecc.crt"
 
#SSLCertificateKeyFile "${SRVROOT}/conf/server.key"
#SSLCertificateKeyFile "${SRVROOT}/conf/server-dsa.key"
#SSLCertificateKeyFile "${SRVROOT}/conf/server-ecc.key"
#    ┋  この間省略    
< /VirtualHost>
 
< IfModule md_module>
MDBaseServer            off
MDCertificateProtocol   ACME
MDCAChallenges          http-01 tls-alpn-01
MDRenewMode             auto 
MDPrivateKeys           RSA 2048
MDRenewWindow           33%
MDStoreDir              md
 
# fake証明書用
MDCertificateAuthority https://acme-staging-v02.api.letsencrypt.org/directory
# 本番証明書用
#MDCertificateAuthority  https://acme-v02.api.letsencrypt.org/directory
MDCertificateAgreement  https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf
< /IfModule>

httpd-vhosts.conf

# Virtual Hosts
#
# Required modules: mod_log_config
 
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# 
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
 
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any  block.
#
 
< VirtualHost *:80>
    ServerAdmin admin@example.com
    DocumentRoot "D:/www/public_html"
    ServerName hoge.com
    ServerAlias www.hoge.com
    ErrorLog "${SRVROOT}/logs/error.log"
    CustomLog "${SRVROOT}/logs/access.log" common
< /VirtualHost>
 
#<VirtualHost *:80>
#    ServerAdmin webmaster@dummy-host2.example.com
#    DocumentRoot "${SRVROOT}/docs/dummy-host2.example.com"
#    ServerName dummy-host2.example.com
#    ErrorLog "logs/dummy-host2.example.com-error.log"
#    CustomLog "logs/dummy-host2.example.com-access.log" common
#</VirtualHost>

httpd-mpm.conf

Windowsサーバーの安定化対策
外部からのIEでのアクセス時に急に画面が止まるなどの接続が不安定になる現象が発生していたので,安定化対策として設定。

# WinNT MPM
# ThreadsPerChild: constant number of worker threads in the server process
# MaxConnectionsPerChild: maximum number of connections a server process serves
< IfModule mpm_winnt_module>
    ThreadsPerChild        150
    MaxConnectionsPerChild   0
    AcceptFilter http none 
    AcceptFilter https none 
    EnableSendfile off 
    EnableMMAP off 
    ThreadStackSize 8388608
< /IfModule>

設定ファイルの新旧比較・変更

新旧比較ツール(WinMerge)を使用して,新設定ファイルを変更する。
Apacheの新旧バージョンが同じ2.4であれば「conf」フォルダーを旧から新フォルダーにそのままコピーしても問題ない。と思う。

ファイル移動

運用中のapacheを停止して,ルートのフォルダー名変更(例:Apache24 → 旧_Apache24)
新バージョンのapacheフォルダー名をApache24に変更

apacheのサービス登録

【バージョンアップ時は設定済みのため不要】
Apacheをインストールしたディレクトリからコマンドプロンプトを管理者として起動し、httpd -k install と入力。

Apache をサービスに登録(管理者)
d:/Program Files/Apache24/bin> httpd -k install


Apache をサービスから削除
d:/Program Files/Apache24/bin> httpd -k uninstall

apacheの実行ユーザー設定

【バージョンアップ時は設定済みのため不要】
セキュリテイ対策としてapacheを一般ユーザー権限で実行させる。
Apacheのサービスユーザーアカウントはデフォルト(admin)を使用しないで専用ユーザーアカウント(apache)を作成してサービスのログオンタブのアカウントに登録する。アクセス権限を限定することで,セキュリティを確保する。
具体例:アカウント名:apache 所属グループ:user
apacheのDocumentRoot,md,logsフォルダーを変更許可に設定する。

DocumentRoot

httpd.confでデフォルトの「User daemon」 , 「Group daemon」指定から
「User apache」 , 「Group user」に一応変更したが,Windowsでは関係ないかも。

apacheの起動

コマンドプロンプトから httpd -k start と入力しエラー表示されなければ起動している。
又はサービスのGUIから起動させる。

Apache を起動
d:/Program Files/Apache24/bin> httpd -k start

Apache を停止
d:/Program Files/Apache24/bin> httpd -k stop

エラーログ確認

apacheのlogsフォルダーからerrlogを開いてエラーが無い事を確認。

その他ソフトのインストール

Apache以外に下記のソフトもバージョンアップ(インストール)した。
1.PHP
2.MySQL
3.Perl
4.Wordpress (データー移行)
これらについては後日まとめて記載する。

コメントは受け付けていません。