LoginSignup
5
6

More than 5 years have passed since last update.

ローカルでPHP×Apache連携(Windows環境)

Posted at

目的

ローカル(Windows環境)でPHP×Apache環境を構築
html拡張子で、phpが動作するように対応する

事前準備

Download : Visual Studio 2012 更新プログラム 4 の Visual C++ 再頒布可能パッケージ - http://www.microsoft.com/ja-JP/download/details.aspx?id=30679

Aapacheインストール

  1. Apacheのダウンロード(http://www.apachelounge.com/download/)
  2. zipを解凍し、任意の場所に置く
  3. http.confの設定を変更する
# http.conf
ServerRoot "c:/your/apache/path"
DocumentRoot "c:/your/apache/path/htdocs"
<Directory "c:/your/apache/path/htdocs">
ScriptAlias /cgi-bin/ "c:/your/apache/path/cgi-bin/"
Listen 127.0.0.1:80
ServerName localhost:80

コマンドプロンプトを立ち上げ、Apahceをローカル環境のサーバとしてインストールする

$ cd Apache\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.
httpd: Syntax error on line 37 of c:/your/apache/path/conf/httpd.conf: S
erverRoot must be a valid directory

以下から起動を確認できる
1. コントロールパネル
2. 管理ツール
3. サービス

PHP

  1. PHPのダウンロード(http://windows.php.net/download/)
  2. zipを解凍し、任意の場所に置く
  3. php.ini-developmentphp.iniに変更
  4. PHPをApacheで利用できるようにhttp.confの設定を変更
    以下の設定で、html拡張子で.phpも利用できるようになる。
# http.conf
LoadModule php5_module "C:/your/path/php-5.6.3/php5apache2_4.dll"
AddHandler application/x-httpd-php .php
PHPIniDir "/your/path/php-5.6.3"
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>

Apacheを再起動し、htdocs以下にinfo.phpを作成

# info.php
<?php
phpinfo();
?>

以下のURLでPHPの設定が確認できると完了

http://localhost/info.php

5
6
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
5
6