LoginSignup
11
9

More than 3 years have passed since last update.

Windows10にApacheをインストールする方法

Last updated at Posted at 2019-08-13
  • 環境
    • OS : Windows10 64bit
    • ターミナル : Git Bash

Apacheを配置する

  1. Apache Haus Downloadsの[Apache 2.4 Server Binaries]から使いたいzipをダウンロードする
    • 今回は、「httpd-2.4.41-o111c-x86-vc15-r2.zip」にした。
    • image.pngここを押下するとダウンロードできる
  2. zipファイルを任意のディレクトリに展開する
    • 今回は、「C:/apps/」配下に展開した。
  3. バージョンを確認してみる
$ /c/apps/httpd-2.4.41-o111c-x86-vc15-r2/Apache24/bin/httpd -V
Server version: Apache/2.4.41 (Win32)
Server built:   Aug 10 2019 12:59:56
Distributed by: The Apache Haus
Compiled with:  Visual Studio 2017
Server's Module Magic Number: 20120211:88
Server loaded:  APR 1.7.0, APR-UTIL 1.6.1
Compiled using: APR 1.7.0, APR-UTIL 1.6.1
Architecture:   32-bit
Server MPM:     WinNT
  threaded:     yes (fixed thread count)
    forked:     no
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses disabled)
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/Apache24"
 -D HTTPD_EXEC="/Apache24/bin/httpd.exe"
 -D DEFAULT_PIDLOG="logs/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error.log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"

* The Apache Haus
* is not affiliated with, or endorsed by, the Apache Software Foundation.
* Apache HTTP Server, Apache, and the Apache feather logo are trademarks of
* The Apache Software Foundation.

httpd.confにSRVROOTを設定する

httpd.confは、httpd-2.4.41-o111c-x86-vc15-r2/Apache24/conf配下に格納されている。

httpd.conf
# 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:\apps\httpd-2.4.41-o111c-x86-vc15-r2\Apache24"
ServerRoot "${SRVROOT}"
# 省略

Apacheを起動する

# 応答が無ければOK
$ /c/apps/httpd-2.4.41-o111c-x86-vc15-r2/Apache24/bin/httpd

  1. Apacheを起動する
    1. 初めて起動するとダイアログが表示される
    2. image.png
  2. http://localhost/ をブラウザで表示する
    1. こんな感じの画面が表示される
    2. image.png
  3. Ctrl+C等でApacheプロセスを終了させる。

Apacheをサービスに登録する

参考 : Windowsサービス一覧をコマンドで取得する - shibainu55日記

サービスに登録されていないことを確認する

$ sc query state=all | grep SERVICE_NAME | grep -i apa
SERVICE_NAME: Intel(R) Capability Licensing Service TCP IP Interface

サービスへの登録方法を確認する

$ /c/apps/httpd-2.4.41-o111c-x86-vc15-r2/Apache24/bin/httpd -h
# 省略
  -k install         : install an Apache service

ターミナルを管理者権限で起動する

ターミナルを管理者権限で起動していない場合のエラー
# GitBashに文字化け対応を入れていなかったため、エラーメッセージは一部文字化けしてしまった
$ /c/apps/httpd-2.4.41-o111c-x86-vc15-r2/Apache24/bin/httpd -k install
Installing the 'Apache2.4' service
(OS 5)▒A▒N▒Z▒X▒▒▒▒▒ۂ▒▒▒܂▒▒▒▒B  : AH00369: Failed to open the Windows service manager, perhaps you forgot to log in as Adminstrator?

サービスに登録する

$ /c/apps/httpd-2.4.41-o111c-x86-vc15-r2/Apache24/bin/httpd -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.

$

サービスに登録されたことを確認する

$ sc query state=all | grep SERVICE_NAME | grep -i apa
SERVICE_NAME: Intel(R) Capability Licensing Service TCP IP Interface
SERVICE_NAME: Apache2.4

[サービス]ダイアログ([Win+R > services.msc])でも確認できます。
image.png

サービスを起動する

$ sc start Apache2.4

SERVICE_NAME: Apache2.4
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 2  START_PENDING
                                (NOT_STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x7d0
        PID                : 13692
        FLAGS              :

エラーになったときの原因

# 原因 : ターミナルを管理者権限で起動していない
$ sc start Apache2.4
[SC] StartService: OpenService FAILED 5:

アクセスが拒否されました。

# 原因 : 指定したサービス名に誤記がある
$ sc start Apach2.4
[SC] StartService: OpenService FAILED 1060:

指定されたサービスはインストールされたサービスとして存在しません。

# 原因 : 既に起動している
$ sc start Apache2.4
[SC] StartService FAILED 1056:

サービス インスタンスは既に実行されています。

サービスを停止する

$ sc stop Apache2.4

SERVICE_NAME: Apache2.4
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 3  STOP_PENDING
                                (NOT_STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x2
        WAIT_HINT          : 0x7530

エラーになったときの原因

# 原因 : 既に停止している
$ sc stop Apache2.4
[SC] ControlService FAILED 1062:

そのサービスを開始できませんでした。
11
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
9