Technical

PHP

windows VISTA

Download - The Apache HTTP Server Project
http://httpd.apache.org/download.cgi
apache_2.2.11-win32-x86-openssl-0.9.8i.msiを使用
apache_2.2.11-win32-x86-openssl-*.*.**.msi 暗号か通信SSLを利用しない場合
apache_2.2.11-win32-x86-no_ssl.msi 暗号か通信SSLを利用する場合(ローカル確認ならこちら)
 インストールの確認
  http://localhost/ → It works!

php Releases
http://www.php.net/releases/index.php
php-5.2.8-Win32.zip

PHPの設定

1.「php」フォルダの中の「php5ts.dll」ファイルを「C:\WINDOWS\system32」にコピーする 
2.「php」フォルダの中の「php.ini-dist」ファイルを「C:\WINDOWS」にコピーし、
  ファイル名を「php.ini」に変更する 
3.「php.ini」ファイルを編集するために、メモ帳などで開く 
4.includeファイルへのパスを有効にする 
;;;;;;;;;;;;;;;;;;;;;;;;; 
; Paths and Directories ; 
;;;;;;;;;;;;;;;;;;;;;;;;; 

; UNIX: "/path1:/path2" 
;include_path = ".:/php/includes" 

; Windows: "\path1;\path2" 
;include_path = ".;c:\php\includes"  ←この「;」を外す 

5.Apacheのドキュメントルートを指定する 
  (Cドライブをドキュメントルートとして設定しています) 
; The root of the PHP pages, used only if nonempty. 
; if PHP was not compiled with FORCE_REDIRECT, you SHOULD set doc_root 
; if you are running php as a CGI under any web server (other than IIS) 
; see documentation for security issues. The alternate is to use the 
; cgi.force_redirect configuration below 
doc_root ="C:"  ←このように設定 

6.拡張モジュールのディレクトリを指定する 
; Directory in which the loadable extensions (modules) reside. 
extension_dir = "C:\php\ext" ←このように設定 

7.Dyanamic Extensionsの設定 
;extension=php_bz2.dll 
;extension=php_curl.dll 
;extension=php_dba.dll; 
extension=php_dbase.dll 
;extension=php_exif.dll 
;extension=php_fdf.dll 
;extension=php_gd2.dll ←この「;」を外す 

さらに下に行き、 
;extension=php_imap.dll 
;extension=php_interbase.dll 
;extension=php_ldap.dll 
;extension=php_mbstring.dll ←この「;」を外す 

7-1. Sqliteの設定
extension=php_pdo.dll
extension=php_pdo_sqlite.dll
extension=php_sqlite.dll

8.マジッククオートを設定をオフにする
; Magic quotes
;
; Magic quotes for incoming GET/POST/Cookie data.
magic_quotes_gpc = Off ←「Off」に設定する

9.タイムゾーンを設定する
[Date]
; Defines the default timezone used by the date functions
date.timezone = Asia/Tokyo ←この「;」を外し、「Asia/Tokyo」に設定する

10.文字コードの設定を行なう
 (PHPプログラムをEUC-JPで保存し、ブラウザへEUC-JPで出力する場合)
; PHP's built-in default is text/html
default_mimetype = "text/html"
;default_charset = "EUC-JP" ←この「;」を外し、「EUC-JP」に設定

さらに下に行き、 
[mbstring] 
; language for internal character representation. 
;mbstring.language = Japanese ←この「;」を外す 

; internal/script encoding. 
; Some encoding cannot work as internal encoding. 
; (e.g. SJIS, BIG5, ISO-2022-*) 
;mbstring.internal_encoding = EUC-JP ←この「;」を外す 

; http input encoding. 
;mbstring.http_input = auto ←この「;」を外す 

; http output encoding. mb_output_handler must be 
; registered as output buffer to function 
;mbstring.http_output = EUC-JP ←この「;」を外し、「EUC-JP」に設定 

; enable automatic encoding translation according to 
; mbstring.internal_encoding setting. Input chars are 
; converted to internal encoding by setting this to On. 
; Note: Do _not_ use automatic encoding translation for 
; portable libs/applications. 
mbstring.encoding_translation = On ←この「;」を外し、「On」に設定 

; automatic encoding detection order. 
; auto means 
;mbstring.detect_order = auto ←この「;」を外す 

; substitute_character used when character cannot be converted; one from another 
;mbstring.substitute_character = none; ←この「;」を外す 
; overload(replace) single byte functions by mbstring functions. 
; mail(), ereg(), etc are overloaded by mb_send_mail(), mb_ereg(), 
; etc. Possible values are 0,1,2,4 or combination of them. 
; For example, 7 for overload everything. 
; 0: No overload 
; 1: Overload mail() function 
; 2: Overload str*() functions 
; 4: Overload ereg*() functions 
;mbstring.func_overload = 0 ←この「;」を外す 

これでphpの設定は終わりです。 


Apacheの設定

1.Apacheの設定ファイル「httpd.conf」を編集する 
  「C:\Apache Software Foundation\Apache2.2\conf」フォルダにある「httpd.conf」をメモ帳などで開く

2.Dynamic Shared Object (DSO) Supportの編集 
#LoadModule usertrack_module modules/mod_usertrack.so 
#LoadModule version_module modules/mod_version.so 
#LoadModule vhost_alias_module modules/mod_vhost_alias.so 
LoadModule php5_module c:/php/php5apache2_2.dll ←この行を追加する 

3.AddTypeの追加 
AddType application/x-compress .Z 
AddType application/x-gzip .gz .tgz 
AddType application/x-httpd-php .php ←この行を追加する 
AddType application/x-httpd-php-source .phps ←この行を追加する 

4.DirectoryIndexの設定 

# DirectoryIndex: sets the file that Apache will serve if a directory 
# is requested. 

DirectoryIndex index.html index.html.var index.php ←この行を編集する 

5.「httpd.conf」ファイルを保存する 

Apacheの設定はこれで終わりです。 


Apache再起動


Apache+PHPの連携の確認 
 http://localhost/phpbook/phpinfo.php


txt

参考
 SHOEISHA PHPの絵本
 http://vtec-php.at.webry.info/200812/article_1.html
 Apache2.2.11 + PHP5.2.8

サンプルソース

「テーブル作成」
<html><body>
<?php
if($db = sqlite_open("db_ehon")) {
$query = "CREATE TABLE tbl_ehon(id INTEGER,title VARCHAR(10),price INTEGER)";
$result = sqlite_query($db,$query);
print " [db_ehon]を作成しました";
} else {
die("データベースに接続できません。");
}
sqlite_close($db);
?>
</body>
</html>

「データ追加」
<html><body>
<?php
if($db = sqlite_open("db_ehon")) {
$query = "DELETE FROM tbl_ehon";
$result = sqlite_query($db,$query);
$query = "INSERT INTO tbl_ehon(id,title,price) VALUES(1,'Aの本',1001)";
$result = sqlite_query($db,$query);
$query = "INSERT INTO tbl_ehon(id,title,price) VALUES(2,'bの本',2001)";
$result = sqlite_query($db,$query);
$query = "INSERT INTO tbl_ehon(id,title,price) VALUES(3,'cの本',3001)";
$result = sqlite_query($db,$query);
print " [db_ehon]にデータを登録しました。";
} else {
die("データを登録できません。");
}
sqlite_close($db);
?>
</body>
</html>

「データ取得」
<html><body>
<?php
if($db = sqlite_open("db_ehon")) {
$query = "SELECT * FROM tbl_ehon";
$result = sqlite_query($db,$query);
while ($info = sqlite_fetch_array($result)) {
print "id = {$info['id']},";
print "title = {$info['title']},";
print "price = {$info['price']}";
print "<br>\n";
}
} else {
die("データを取得できません。");
}
sqlite_close($db);
?>
</body>
</html>