アプリケーション開発環境として主にWindowsを使っています。
開発時の検証で使用するミドルウェアがApacheを使用することが多いので、ここでは開発環境であるWindowsにApacheを構築する方法を説明します。
前提
- Windows10(64ビット)環境を前提とします。
- ApacheのWindows版としていくつか候補がありますが、ここではApache Loungeのものを使用します。
- 配置先は”C:\devenv\apache24″とします。検証でapacheを使用する他のミドルウェアを使用する場合、同様に”C:\devenv”配下に配置する想定です。
構築手順
Apacheのダウンロードと展開
- ダウンロード
Apache公式サイトのダウンロードからApache Loungeを開き、zipファイルをダウンロードします。
(ここでは、”httpd-2.4.37-win64-VC15.zip”とします。) - 展開先フォルダの作成
“C:\devenv”フォルダを作成します。 - 展開
上記のzipファイルを任意のフォルダに解凍し、このフォルダに含まれている”Apache24″を”C:\devenv”直下に移動またはコピーします。
設定ファイルの更新
“C:\devenv\Apache24\conf\httpd.conf”を次のように編集します。
(後で何を変更したか把握できるよう、編集前にhttpd.conf.org等にコピーしておくことをお勧めします。)
...
#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# Do not add a slash at the end of the directory path. If you point
# ServerRoot at a non-local disk, be sure to specify a local disk on the
# Mutex directive, if file-based mutexes are used. If you wish to share the
# same ServerRoot for multiple httpd daemons, you will need to change at
# least PidFile.
#
Define SRVROOT "C:\devenv\Apache24"
ServerRoot "${SRVROOT}"
...
#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
Listen localhost:8070
...
#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName httpserv:8070
...12行目: Apacheのホームディレクトリを指定
25行目: ローカルホストからのアクセスのみ許可(ポート番号は8070)
35行名: 暫定のデフォルトのホスト名
サービスとして登録
スタートメニューを右クリックし、”Windows PowerShell(管理者)”を起動し、次のようにコマンドを実行する。
> cd C:\devenv\Apache24\bin
> .\httpd.exe -k install
Installing the 'Apache2.4' service
The 'Apache2.4' service is successfully installed.
Testing httpd.conf....
Errors reported here must be corrected before the service can be started.
> Set-Service -Name Apache2.4 -StartupType Manual ※手動起動にしたい場合は実行
> Start-Service Apache2.4動作確認
ブラウザで”http://localhost:8070″を開く。
“It works!”と表示されることを確認する。
参考: サービスの解除
「サービスとして登録」と同様に”PowerShell(管理者)”を起動し、次のコマンドを実行する。
> cd C:\devenv\Apache24\bin
> .\httpd.exe -k uninstall
Removing the 'Apache2.4' service
The 'Apache2.4' service has been removed successfully.