HOME
  Security
   Software
    Hardware
  
FPGA
  CPU
   Android
    Raspberry Pi
  
nLite
  Xcode
   etc.
    ALL
  
LINK
BACK
 

2018/02/17

Windowsパソコンに Apache 2.4 + PHP 5.2.17の Webサーバ環境を構築する手順(最後の砦) Windowsパソコンに Apache 2.4 + PHP 5.2.17の Webサーバ環境を構築する手順(最後の砦)

(過去のプログラム等でどうしても PHP 5.2系を Windowsで動かしたいと言う場合に)

Tags: [Windows開発]




● Windowsパソコンに Apache 2.4 + PHP 5.2.17の Webサーバ環境を構築する手順(最後の砦)

 過去のプログラム等でどうしても PHP 5.2系を Windowsパソコンで動かしたいと言う場合に

 Apache系と nginxの PHPスクリプトの実行速度比較
 Webサーバ + PHPスクリプトの構成で動くアプリを実行した例です。
実行環境処理時間nginx速度比(遅さ)実行環境
Apache 2.0.63 + PHP 4.4.9590秒6倍Windows XP + Atom D525
Apache 2.2.25 + PHP 4.4.9110秒1.15倍Windows 10 + Atom X5-Z8350
Apache 2.4.29 + PHP 5.2.17120秒1.25倍Windows 10 + Atom X5-Z8350
nginx 1.12.2 + PHP 5.2.1795秒-Windows 10 + Atom X5-Z8350
※ PHP 5.2.17は PHP 4互換モードを有効(zend.ze1_compatibility_mode = On)
※ Windows 10 + Atom X5-Z8350実行環境は Morefine M1sを使用


●用意する物

 ・Apache本体 Apache 2.4.29 Win32
httpd-2.4.29-win32-VC11.zip
httpd-2.4.29-win32-VC11.zip
Apache 2.4 VC11 Windows Binaries and Modules
 ※ 64bit版の必要性を感じないので 32bit版を使用します。

 ・PHP 5.2.17本体
php-5.2.17-Win32-VC6-x86.zip
windows.php.net - /downloads/releases/archives/

 ・Apache 2.4で PHP5を動かす為の差し替え DLL
php5apache2_4.dll-php-5.2-win32.zip



● Webサーバのディレクトリ構成

C:\00_Web\
C:\00_Web\bin\
C:\00_Web\bin\Apache24\
C:\00_Web\bin\PHP52\

Webサーバの Document Root
C:\00_Web\bin\Apache24\htdocs\


● Apache本体をインストールする。

httpd-2.4.29-win32-VC11.zip
 を解凍する。

 好みで下記のディレクトリにインストールする。
C:\00_Web\bin\Apache24\

● PHP本体をインストールする。

php-5.2.17-Win32-VC6-x86.zip
 を解凍する。

 好みで下記のディレクトリにインストール(解凍)する。
C:\00_Web\bin\PHP52

● PHP差し替え DLLをインストールする。

php5apache2_4.dll-php-5.2-win32.zip
 を解凍する。

 必ず PHPと同じディレクトリに php5apache2_4.dllをコピーする。
C:\00_Web\bin\PHP52\php5apache2_4.dll

● Apacheの設定ファイル httpd.confファイルを編集する

※ 2018/12追記 最新の httpd-2.4.37-win32-VC11.zipでは設定項目が微妙に変化していて下記の変更方法で動きません。 Define SRVROOT "c:/Apache24"とかの設定項目が追加されている。


C:\00_Web\bin\Apache24\conf\httpd.conf
 をテキストエディタで開いて下記の行を追加する。
 38行目あたり。
# ServerRoot "c:/Apache24"
ServerRoot "C:\00_Web\bin\Apache24"

 224行目あたり。
ServerName localhost:80
※ Could not reliably determine the server's fully qualified domain name, using xxx.xxx.xxx.xxx for ServerName

 「c:/Apache24/」を「C:\00_Web\bin\Apache24\」に書き換える
# DocumentRoot "c:/Apache24/htdocs"
# <Directory "c:/Apache24/htdocs">
DocumentRoot "C:\00_Web\bin\Apache24\htdocs"
<Directory "C:\00_Web\bin\Apache24\htdocs">
#     ScriptAlias /cgi-bin/ "c:/Apache24/cgi-bin/"
    ScriptAlias /cgi-bin/ "C:\00_Web\bin\Apache24\cgi-bin\"
# <Directory "c:/Apache24/cgi-bin">
<Directory "C:\00_Web\bin\Apache24\cgi-bin">

 73行目あたり。
# Example:
# LoadModule foo_module modules/mod_foo.so
#
LoadModule php5_module C:\00_Web\bin\PHP52\php5apache2_4.dll

 435行目あたり。AddHandler ~~ .php行を追加する。
    #
    # 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
    AddHandler application/x-httpd-php .php

 httpd.confファイルの一番最後に下記をコピペする。
 PHPIniDirは php.iniを C:\00_Web\bin\PHP52から読み込む設定。
 (Windowsディレクトリに php.iniを置いて、C:\Windowsディレクトリを汚したくない。)
<IfModule php5_module>
    PHPIniDir "C:\00_Web\bin\PHP52"
</IfModule>

● PHPの設定ファイル php.iniファイルの読み込み先の設定

PHP - 設定ファイル
 設定ファイル (php.ini) は PHP の起動時に読み込まれます。 PHP のサーバーモジュール版では、Web サーバーの起動時に 一度だけ読み込まれます。CGI 版と CLI 版では、スクリプトが呼び出される度に読み込まれます。

 PHPRC 環境変数。
 PHP.exe単体で動かす場合で php.iniファイルの場所を指定する場合。
 (httpd.confファイルは Apache Webサーバで PHPを動かす場合にだけ有効なので)
set PHPRC=C:\00_Web\bin\PHP52
 ※ 上記の環境変数の設定をしなくても php.exeと同じディレクトリの php.iniを自動で読み込みました。

● PHPの設定ファイル php.iniファイルを編集する

C:\00_Web\bin\PHP52\php.ini-dist
 または、
C:\00_Web\bin\PHP52\php.ini-recommended
 のファイルを php.iniの名前にリネームする(コピーでも良い)

C:\00_Web\bin\PHP52\php.ini
 をテキストエディタで開いて好みで編集する。
[PHP]
; Enable compatibility mode with Zend Engine 1 (PHP 4.x)
; zend.ze1_compatibility_mode = Off
zend.ze1_compatibility_mode = On

; short_open_tag = Off
short_open_tag = On

; extension_dir = "./"
; extension_dir = "./ext/" 相対パス指定は動かない
extension_dir = "C:/00_Web/bin/PHP52/ext/"

extension=php_mbstring.dll

[mbstring]
mbstring.language = Japanese
mbstring.internal_encoding = UTF-8
mbstring.http_output = UTF-8

 ※ PHP 5.2を使う理由は PHP 4系の互換オプションが使えるから。
コア php.ini ディレクティブに関する説明
zend.ze1_compatibility_mode = On
 Zend Engine 1 (PHP 4) との互換モードを有効にします。 この設定は、オブジェクトのコピー、キャスト (プロパティを 保持しないオブジェクトが FALSE あるいは 0 のいずれになるか)、 そして 比較 に影響を与えます。このモードの場合、オブジェクトを渡す際の デフォルトの方法は、参照渡しではなく値渡しとなります。
 警告 この機能は 非推奨 で、 PHP 5.3.0 以降では 削除 されました。
PHP 4 から PHP 5.0.x への移行 - 新しいオブジェクトモデル

● Apache Webサーバの実行ファイルを手動で実行する。

C:\00_Web\bin\Apache24\bin\httpd.exe
 を必要な時に実行する。

 おなじみの phpinfo.phpを動かして、PHPの動作を確認する。

phpinfo.php
<?php
  phpinfo();
?>
Build Date Jan 6 2011 17:26:08
Loaded Configuration File C:\00_Web\bin\PHP52\php.ini

mbstring
Multibyte Support enabled
Multibyte string engine libmbfl
Multibyte (japanese) regex support enabled
Multibyte regex (oniguruma) version 4.4.4
Multibyte regex (oniguruma) backtrack check On

mbstring extensionの有効化をチェック
C:\00_Web\bin\Apache24\htdocs\phpmbstring.php
<?php
  print_r(mb_get_info());
?>

http://localhost/phpmbstring.php
Array (
 [internal_encoding] => UTF-8
 [http_input] =>
 [http_output] => UTF-8
 [func_overload] => 0
 [func_overload_list] => no overload
 [mail_charset] => ISO-2022-JP
 [mail_header_encoding] => BASE64
 [mail_body_encoding] => 7bit
 [illegal_chars] => 0
 [encoding_translation] => Off
 [language] => Japanese
 [detect_order] => Array (
  [0] => ASCII
  [1] => JIS
  [2] => UTF-8
  [3] => EUC-JP
  [4] => SJIS )
 [substitute_character] => 63
 [strict_detection] => Off
)



●コピペ実行用お気楽バッチファイル

echo zipファイルを解凍する
mkdir C:\00_Web\bin\
..\UnZip.exe httpd-2.4.29-win32-VC11.zip C:\00_Web\bin\
mkdir C:\00_Web\bin\PHP52\
..\UnZip.exe php-5.2.17-Win32-VC6-x86.zip C:\00_Web\bin\PHP52\
mkdir C:\00_Web\bin\TMP\
..\UnZip.exe php5apache2_4.dll-php-5.2-win32.zip C:\00_Web\bin\TMP\
copy "C:\00_Web\bin\TMP\PHP 5.2.17\php5apache2_4.dll" C:\00_Web\bin\PHP52\
rmdir /Q /S C:\00_Web\bin\TMP\

copy ..\mbsed.exe C:\00_Web\bin\

echo Webサーバの Document Root C:\00_Web\html\
mkdir C:\00_Web\html\

echo Webサーバの cgi-bin C:\00_Web\cgi-bin\
mkdir C:\00_Web\cgi-bin\

echo httpd.confを sedコマンドの置換処理で書き換える
echo Webサーバの Document Root = C:\00_Web\html\
cd /d C:\00_Web\bin\Apache24\conf\
copy httpd.conf httpd_org.conf

..\..\mbsed.exe -e "s/^ServerRoot \"c:\/Apache24\"/ServerRoot \"C:\\00_Web\\bin\\Apache24\"/" httpd.conf --in-place=.bak
del httpd.conf.bak

..\..\mbsed.exe -e "s/^LoadModule access_compat_module/LoadModule php5_module C:\\00_Web\\bin\\PHP52\\php5apache2_4.dll\nLoadModule access_compat_module/" httpd.conf --in-place=.bak
del httpd.conf.bak

..\..\mbsed.exe -e "s/#ServerName www.example.com:80/ServerName localhost:80/" httpd.conf --in-place=.bak
del httpd.conf.bak

..\..\mbsed.exe -e "s/cgi-script .cgi$/cgi-script .cgi\n    AddHandler application\/x-httpd-php .php/" httpd.conf --in-place=.bak
del httpd.conf.bak

..\..\mbsed.exe -e "s/c:\/Apache24\/htdocs/C:\\00_Web\\html/g" httpd.conf --in-place=.bak
del httpd.conf.bak

..\..\mbsed.exe -e "s/c:\/Apache24\/cgi-bin\//C:\\00_Web\\cgi-bin\\/g" httpd.conf --in-place=.bak
del httpd.conf.bak

..\..\mbsed.exe -e "s/c:\/Apache24\/cgi-bin/C:\\00_Web\\cgi-bin/g" httpd.conf --in-place=.bak
del httpd.conf.bak

rem 最後に PIniDirの定義を追加している。
echo. >>httpd.conf
echo # PHPIniDir >>httpd.conf
echo ^&lt;IfModule php5_module^&gt; >>httpd.conf
echo     PHPIniDir "C:\00_Web\bin\PHP52" >>httpd.conf
echo ^&lt;/IfModule^&gt; >>httpd.conf


echo php.iniを sedコマンドの置換処理で書き換える
cd /d C:\00_Web\bin\PHP52\
copy php.ini-recommended php.ini

..\mbsed.exe -e "s/^zend.ze1_compatibility_mode = Off/zend.ze1_compatibility_mode = On/" php.ini --in-place=.bak
del php.ini.bak

..\mbsed.exe -e "s/^short_open_tag = Off/short_open_tag = On/" php.ini --in-place=.bak
del php.ini.bak

rem "./ext/" 相対パス指定は動かない
..\mbsed.exe -e "s/^extension_dir = \".\/\"/extension_dir = \"C:\/00_Web\/bin\/PHP52\/ext\/\"/" php.ini --in-place=.bak
del php.ini.bak

..\mbsed.exe -e "s/^;extension=php_mbstring.dll/extension=php_mbstring.dll/" php.ini --in-place=.bak
del php.ini.bak

echo PHPで httpsで始まるページが取得できない場合
echo PHP Warning: file_get_contents() [function.file-get-contents]: Unable to find the wrapper "https" - did you forget to enable it when you configured PHP ?
echo allow_url_fopen = Offの場合は {2}echo allow_url_fopen = Onも必要
..\mbsed.exe -e "s/^;extension=php_openssl.dll/extension=php_openssl.dll/g" php.ini --in-place=.bak
del php.ini.bak


..\mbsed.exe -e "s/^;mbstring.language = Japanese/mbstring.language = Japanese/" php.ini --in-place=.bak
del php.ini.bak

..\mbsed.exe -e "s/^;mbstring.internal_encoding = EUC-JP/mbstring.internal_encoding = UTF-8/" php.ini --in-place=.bak
del php.ini.bak

..\mbsed.exe -e "s/^;mbstring.http_output = SJIS/mbstring.http_output = UTF-8/" php.ini --in-place=.bak
del php.ini.bak


● mbsed.exe Windowsのコマンドラインで sedコマンド

GNU sed with Oniguruma (Onigsed)とは?

鬼車を使っていないバージョン(2009/10/5)
md5 3fd753202cb5dbc565eeba29abd049d *sed-mbcs-win32-20091004.zip
sha1 9f4f44f67cb1fa6ad9c95fa3ac232be625b36f6 sed-mbcs-win32-20091004.zip



● Windowsパソコンに Apache 2.4 + PHP 5.6.36の高速 Webサーバ環境を構築する手順

PHP For Windows
 から、PHP 5.6 (5.6.36)の VC11 x86 Thread Safe (2018-Apr-26 07:43:31)をダウンロードし、上記と同様に解凍してセットアップします。

 Apacheと PHPの各種設定で PHPバイナリへの PATHを変更します。
 php.iniファイルは php.ini-development、または、php.ini-productionを元に作成します。(php.ini-recommendedファイルは無くなった)
copy php.ini-development php.ini

LoadModule php5_module C:\00_Web\bin\PHP56\php5apache2_4.dll
 ※ php5apache2_4.dllは PHP 5.6.36の ZIPに含まれています。

php-5.6.36-Win32-VC11-x86.zip
 x86版を使用します。

 ※ Apacheサーバとの組み合わせの時の PHPは Thread Safe版を使用します。
 ※ Thread Safe版にしか php5apache2_4.dllが存在しません。


● Windowsパソコンに Apache 2.4 + PHP 7.2.7の高速 Webサーバ環境を構築する手順

PHP For Windows
 から、PHP 7.2 (7.2.7)の VC15 x86 Thread Safe (2018-Jun-20 02:53:58)をダウンロードし、上記と同様に解凍してセットアップします。

 Apacheと PHPの各種設定で PHPバイナリへの PATHを変更します。
 php.iniファイルは php.ini-development、または、php.ini-productionを元に作成します。(php.ini-recommendedファイルは無くなった)
copy php.ini-development php.ini

LoadModule php7_module C:\00_Web\bin\PHP72\php7apache2_4.dll
 ※ php7apache2_4.dllは PHP 7.2.7の ZIPに含まれています。

php-7.2.7-Win32-VC15-x86.zip
 x86版を使用します。

 ※ Apacheサーバとの組み合わせの時の PHPは Thread Safe版を使用します。
 ※ Thread Safe版にしか php7apache2_4.dllが存在しません。



Tags: [Windows開発]

●関連するコンテンツ(この記事を読んだ人は、次の記事も読んでいます)

Apache Webサーバを過剰なアクセスや DoS攻撃から守る modモジュールの紹介
Apache Webサーバを過剰なアクセスや DoS攻撃から守る modモジュールの紹介

  対 DoS攻撃用の Apache2モジュール mod_evasive、mod_dosdetector、mod_limitipconn、fail2ban等の紹介

Windowsパソコンに Apache 2.2 + PHP 4.4.9の Webサーバ環境を構築する手順(最後の砦)
Windowsパソコンに Apache 2.2 + PHP 4.4.9の Webサーバ環境を構築する手順(最後の砦)

  過去の遺産等のしがらみでどうしても PHP 4.4系を Windowsで動かしたいと言う場合に

Windowsパソコンに nginx + PHP 5.2.17の高速 Webサーバ環境を構築する手順
Windowsパソコンに nginx + PHP 5.2.17の高速 Webサーバ環境を構築する手順

  nginxを使って Apacheよりも高速な Webサーバ環境を Windowsで構築する PHP 5.2系

C# .NETで ZIPファイル解凍ツール UnZipをソースリスト 1行で自作する方法、Windows .NET専用
C# .NETで ZIPファイル解凍ツール UnZipをソースリスト 1行で自作する方法、Windows .NET専用

  Visual Studio 2013の C# .NET 4.5で ZipFile.ExtractToDirectoryを使い、UnZip解凍ツールを作成




[HOME] | [BACK]
リンクフリー(連絡不要、ただしトップページ以外は Web構成の変更で移動する場合があります)
Copyright (c) 2018 FREE WING,Y.Sakamoto
Powered by 猫屋敷工房 & HTML Generator

http://www.neko.ne.jp/~freewing/software/windows_apache_24_php_5217/