LoginSignup
2
1

More than 1 year has passed since last update.

WindowsにApache+PHPの環境構築

Posted at

Apache

Apacheのダウンロード

Apache Loungeというサイトからダウンロードする
https://www.apachelounge.com/download/#google_vignette

2022/8/19時点では「httpd-2.4.54-win64-VS16.zip 」となっている。

image.png

解凍すると下記のようなファイル・フォルダ構成になっている。

image.png

「Apache24」というフォルダを「c:\var\」の配下にコピーする。
(varフォルダがなければ作る。varという名前でなくても別に良い)

image.png

Apacheの設定

httpd.confの編集

C:\var\Apache24\conf\httpd.conf

ServerName

http.conf
ServerName localhost:80
ServerRoot
http.conf
Define SRVROOT "c:/Apache24"

ServerRoot "${SRVROOT}"

↓

Define SRVROOT "c:/var/Apache24"

ServerRoot "${SRVROOT}"

DocumentRoot

html や php ファイルを配置するドキュメントルートパスを指定。
→SRVROOTを使っているので変更なし

DocumentRoot "${SRVROOT}/htdocs"

ScriptAlias

CGI用エイリアスのパスを指定。
→SRVROOTを使っているので変更なし

ScriptAlias /cgi-bin/ "${SRVROOT}/cgi-bin/"

cgi-binのDirectory

→SRVROOTを使っているので変更なし

<Directory "${SRVROOT}/htdocs">

Listen

ポート番号を指定。

Listen 80

Apacheを起動する

C:\var\Apache24\bin\httpd.exe

実行すると下記の画面が表示される。

image.png

ブラウザで「http://localhost/」を開く。

image.png

「It works!」と表示されていれば成功。

PHP

PHPのダウンロード

PHPのサイトからダウンロードする。
https://windows.php.net/download

ダウンロードした圧縮ファイルを解凍し「c:\var\」へ移動する。

コマンドプロンプトにて動作を確認する

> php -v
> php -i

バージョンやPHP情報が表示されたら成功。

apach2.4用のdllを入手する

解凍したphpのフォルダ内に「php~apache2_4.dll」というファイルがない場合、
ApacheをダウンロードしたApache Loungeというサイトの「Addtional」からダウンロードする。

image.png
image.png

Apache+PHP

Apacheのhttpd.confをPHP用に修正します。

LoadModule

LoadModule php5_module "C:\var\php-5.6.0-Win32-VC11-x64\php5apache2_4.dll"

Directory

<Directory />
    AllowOverride none
    Require all denied
</Directory>

↓

<Directory />
    AllowOverride All
    Require all granted
</Directory>

Options Index

    Options Indexes FollowSymLinks
↓
    Options Indexes FollowSymLinks ExecCGI
    Options +Includes

TypesConfig

<IfModule mime_module>
    #
    # TypesConfig points to the file containing the list of mappings from
    # filename extension to MIME-type.
    #
    TypesConfig conf/mime.types

↓
<IfModule mime_module>
    #
    # TypesConfig points to the file containing the list of mappings from
    # filename extension to MIME-type.
    #
    TypesConfig conf/mime.types
    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

    #
    # AddHandler allows you to map certain file extensions to "handlers":
    # actions unrelated to filetype. These can be either built into the server
    # or added with the Action directive (see below)
    #
    # To use CGI scripts outside of ScriptAliased directories:
    # (You will also need to add "ExecCGI" to the "Options" directive.)
    #
    #AddHandler cgi-script .cgi

    # For type maps (negotiated resources):
    #AddHandler type-map var
↓

DirectoryIndex

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>
↓
<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

PHPIniDir

PHPIniDir  "C:\var\php-5.6.0-Win32-VC11-x64"

動作確認

テスト用PHPファイルを用意

\var\Apache24\htdocs\test.php
<?php

phpinfo()

?>

ブラウザで「http://localhost/test.php」を確認。

image.png

phpinfoが表示されたら成功!

おわり。

2
1
2

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
2
1