|
2006-01-14
PEARのインストール †PEAR(PHP Extension and Application Repository)とはPHPの拡張ライブラリの一種で、その一部はPHPとともに配布されており、事実上、PHPの標準クラスライブラリといえます。 また、PEARは、TeXのCTAN(Comprehensive TeX Archive Network)またはPerlのCPAN(Comprehensive Perl Archive Network)と同様に「偉大な」ライブラリのコードレポジトリです。 PEARの日本語マニュアルは以下を参照して下さい。 パッケージマネージャのインストール †インストールの準備 †プラウザで次のサイトにアクセスすると、phpのソースコードが表示されます。 <?php //; echo; echo "YOU NEED TO RUN THIS SCRIPT WITH PHP NOW!"; echo; echo "Try this: lynx -source http://pear.php.net/go-pear | php -q"; echo; exit # -*- PHP -*- # +----------------------------------------------------------------------+ # | PHP Version 5 | # +----------------------------------------------------------------------+ # | Copyright (c) 1997-2005 The PHP Group | # +----------------------------------------------------------------------+ # | This source file is subject to version 2.02 of the PHP license, | # | that is bundled with this package in the file LICENSE, and is | # | available at through the world-wide-web at | # | http://www.php.net/license/2_02.txt. | # | If you did not receive a copy of the PHP license and are unable to | # | obtain it through the world-wide-web, please send a note to | # | license@php.net so we can mail you a copy immediately. | # +----------------------------------------------------------------------+ # | Authors: Tomas V.V.Cox <cox@idecnet.com> | # | Stig Bakken <ssb@php.net> | # | Christian Dickmann <dickmann@php.net> | # | Pierre-Alain Joye <pajoye@pearfr.org> | # | Greg Beaver <cellog@php.net> | # +----------------------------------------------------------------------+ # $Id: go-pear,v 1.79 2006/01/02 18:08:28 cellog Exp $ ・ ・ ・ 表示されたソースコードを以下の場所に保存します。
C:\php5mb はPHPのインストールフォルダです。PEARフォルダがない場合は作成して下さい。インストールしたPHPのディストリビューションによっては既に PEAR\go-pear.php が存在する場合があります。その場合は、既存の go-pear.php を使う事もできます。 次にPHPインストールフォルダ(C:\php5mb)に go-pear.bat を作成します。このバッチファイルも既存の場合は、それを使う事ができます。存在しない場合は、以下のように作成して下さい。 C:\php5mb\go-pear.bat @ECHO OFF set PHP_BIN=php.exe %PHP_BIN% -n -d output_buffering=0 PEAR\go-pear.php %1 pause インストーラの実行 †最終的にはgo-pear.batを実行すればPEARのパッケージマネージャがインストールできます。パッケージマネージャの取得については以下が参考になります。 以下に、筆者の実際に行ったgo-pear.batの実行結果を示します。幾つかの質問がありますが、ほとんどはENTERキーを押すだけでOKです。但し、HTTPプロキシを使用している場合は気を付けてください。 C:\php5mb>go-pear Welcome to go-pear! Go-pear will install the 'pear' command and all the files needed by it. This command is your tool for PEAR installation and maintenance. Use 'php PEAR\go-pear.php local' to install a local copy of PEAR. Go-pear also lets you download and install the PEAR packages bundled with PHP: DB, Net_Socket, Net_SMTP, Mail, XML_Parser, PHPUnit. If you wish to abort, press Control-C now, or press Enter to continue: →→ <ENTER> HTTP proxy (http://user:password@proxy.myhost.com:port), or Enter for none:: →→ <ENTER> Below is a suggested file layout for your new PEAR installation. To change individual locations, type the number in front of the directory. Type 'all' to change all of them or simply press Enter to accept these locations. 1. Installation prefix : C:\php5mb 2. Binaries directory : $prefix 3. PHP code directory ($php_dir) : $prefix\pear 4. Documentation base directory : $php_dir\docs 5. Data base directory : $php_dir\data 6. Tests base directory : $php_dir\tests 7. php.exe path : C:\php5mb\php.exe 1-7, 'all' or Enter to continue: →→ <ENTER> The following PEAR packages are bundled with PHP: DB, Net_Socket, Net_SMTP, Mail, XML_Parser, PHPUnit. Would you like to install these as well? [Y/n] :Y →→Y <ENTER> Loading zlib: ok Downloading package: PEAR-stable......ok Downloading package: Archive_Tar-stable....ok Downloading package: Console_Getopt-stable....ok Downloading package: XML_RPC-stable....ok Bootstrapping: PEAR...................(remote) ok Bootstrapping: Archive_Tar............(remote) ok Bootstrapping: Console_Getopt.........(remote) ok Downloading package: DB...............ok Downloading package: Net_Socket.......ok Downloading package: Net_SMTP.........ok Downloading package: Mail.............ok Downloading package: XML_Parser.......ok Downloading package: PHPUnit..........ok Extracting installer..................ok WARNING: channel "pear.php.net" has updated its protocols, use "channel-update p ear.php.net" to update warning: pear/PEAR requires package "pear/Archive_Tar" (version >= 1.3.1) warning: pear/PEAR requires package "pear/Console_Getopt" (version >= 1.2) pear/PEAR can optionally use package "pear/XML_RPC" (version >= 1.4.0) pear/PEAR can optionally use package "pear/PEAR_Frontend_Web" (version >= 0.5.0) pear/PEAR can optionally use package "pear/PEAR_Frontend_Gtk" (version >= 0.4.0) install ok: channel://pear.php.net/PEAR-1.4.6 WARNING: channel "pear.php.net" has updated its protocols, use "channel-update p ear.php.net" to update install ok: channel://pear.php.net/Archive_Tar-1.3.1 WARNING: channel "pear.php.net" has updated its protocols, use "channel-update p ear.php.net" to update install ok: channel://pear.php.net/Console_Getopt-1.2 WARNING: channel "pear.php.net" has updated its protocols, use "channel-update p ear.php.net" to update install ok: channel://pear.php.net/XML_RPC-1.4.4 WARNING: channel "pear.php.net" has updated its protocols, use "channel-update p ear.php.net" to update install ok: channel://pear.php.net/DB-1.7.6 WARNING: channel "pear.php.net" has updated its protocols, use "channel-update p ear.php.net" to update install ok: channel://pear.php.net/Net_Socket-1.0.6 WARNING: channel "pear.php.net" has updated its protocols, use "channel-update p ear.php.net" to update pear/Net_SMTP can optionally use package "pear/Auth_SASL" install ok: channel://pear.php.net/Net_SMTP-1.2.7 WARNING: channel "pear.php.net" has updated its protocols, use "channel-update p ear.php.net" to update install ok: channel://pear.php.net/Mail-1.1.9 WARNING: channel "pear.php.net" has updated its protocols, use "channel-update p ear.php.net" to update install ok: channel://pear.php.net/XML_Parser-1.2.7 WARNING: channel "pear.php.net" has updated its protocols, use "channel-update p ear.php.net" to update pear/PHPUnit can optionally use package "pear/PHP_Compat" install ok: channel://pear.php.net/PHPUnit-1.3.2 ****************************************************************************** WARNING! The include_path defined in the currently used php.ini does not contain the PEAR PHP directory you just specified: <C:\php5mb\pear> If the specified directory is also not in the include_path used by your scripts, you will have problems getting any PEAR packages working. Current include path : .;C:\php5\pear Configured directory : C:\php5mb\pear Currently used php.ini (guess) : Press Enter to continue: →→ <ENTER> The 'pear' command is now at your service at c:\php5mb\pear.bat * WINDOWS ENVIRONMENT VARIABLES * For convenience, a REG file is available under C:\php5mb\PEAR_ENV.reg . This file creates ENV variables for the current user. Double-click this file to add it to the current user registry. 続行するには何かキーを押してください . . . インストール後の設定 †PEARパッケージマネージャのインストールが終わったら、phpスクリプトからPEARパッケージが利用できるようにphp.iniを編集します。本編では「php.iniの設定」に従い以下のように設定します。 php.ini include_path = ".;C:/php5mb/includes;C:/php5mb/PEAR" コマンドライン・インストーラの使用 †PEARパッケージマネージャがインストールされた環境では、PEARコマンドライン・インストーラの利用ができます。コマンドライン・インストーラはPEAR パッケージをシステムにインストールする最も簡単な方法です。コマンドライン・インストーラの詳細については以下を参照して下さい。 Windowsのコマンドライン・インストーラはバッチファイルとして提供されます。
このバッチファイルはパッケージマネージャをインストールした時にPHPのインストールフォルダ(C:\php5mb)に作成されます。コマンドプロンプト上からpear.batを実行する場合は、環境変数(Path)にpear.batの在処を設定して置くと便利です。 よく使うPEARコマンド †
PEARコマンドの使用例 †以下にPEARコマンドを使ってXML_RSSをインストールする例を挙げます。 (1)listコマンドでパッケージのインストールの有無を確認します C:\php5mb>pear list INSTALLED PACKAGES, CHANNEL PEAR.PHP.NET: ========================================= PACKAGE VERSION STATE Archive_Tar 1.3.1 stable Console_Getopt 1.2 stable DB 1.7.6 stable Mail 1.1.9 stable Net_SMTP 1.2.7 stable Net_Socket 1.0.6 stable PEAR 1.4.6 stable PHPUnit 1.3.2 stable XML_Parser 1.2.7 stable XML_RPC 1.4.4 stable (2)searchコマンドでXML_RSSを検索します C:\php5mb>pear search XML_RSS Retrieving data...0%....50%....MATCHED PACKAGES, CHANNEL PEAR.PHP.NET: ======================================= PACKAGE STABLE/(LATEST) LOCAL XML_RSS 0.9.2/(0.9.9 beta) RSS parser (3)installコマンドでXML_RSSをインストールします C:\php5mb>pear install -a XML_RSS downloading XML_RSS-0.9.2.tgz ... Starting to download XML_RSS-0.9.2.tgz (3,515 bytes) ....done: 3,515 bytes downloading XML_Tree-1.1.tgz ... Starting to download XML_Tree-1.1.tgz (4,826 bytes) ...done: 4,826 bytes install ok: channel://pear.php.net/XML_Tree-1.1 install ok: channel://pear.php.net/XML_RSS-0.9.2 (4)listコマンドでインストールができた事を確認します C:\php5mb>pear list INSTALLED PACKAGES, CHANNEL PEAR.PHP.NET: ========================================= PACKAGE VERSION STATE Archive_Tar 1.3.1 stable Console_Getopt 1.2 stable DB 1.7.6 stable Mail 1.1.9 stable Net_SMTP 1.2.7 stable Net_Socket 1.0.6 stable PEAR 1.4.6 stable PHPUnit 1.3.2 stable XML_Parser 1.2.7 stable XML_RPC 1.4.4 stable XML_RSS 0.9.2 stable XML_Tree 1.1 stable PEARの使用 †準備ができたら実際にPHPでPEARを使って見ましょう。ここではphpinfo()のPEAR版であるPear_Infoを使ってPEARのインストール情報を表示してみます。 (1)Pear_Infoをインストールします C:\ php5mb>pear install -a Pear_Info downloading PEAR_Info-1.6.1.tgz ... Starting to download PEAR_Info-1.6.1.tgz (6,717 bytes) .....done: 6,717 bytes install ok: channel://pear.php.net/PEAR_Info-1.6.1 (2)テストプログラム(pear_info.php)を準備します pear_info.php <?php require_once "PEAR/Info.php"; $info =& new PEAR_Info(); $info->show(); ?> (3)ブラウザからpear_info.phpを呼び出すとPearのインストール情報が出力されます
レンタルサーバなどへの手動インストールについて †(筆者もそうですが)レンタルサーバを使用しており、(ローカルログインや Telnet や SSH による)サーバへの直接アクセスができない場合、PEAR パッケージマネージャを使用することはできません。このような場合は、手動でPEARをインストールする事が必要になります。PEARの手動インストールについては以下を参照して下さい。 以下では筆者が実際に行っているレンタルサーバへのインストール方法を示します。 PEARパッケージをローカルにインストールする †前節までに説明した要領でローカル環境(Windows)にPERAをインストールします。 パッケージのソースコードをアップロードする †ローカル環境(Windows)にインストールしたPERAをFTPでレンタルサーバにアップロードします。筆者は(少々強引ですが)、
以下を全てレンタルサーバの仮想ディレクトリ(/PEAR)にアップロードしています。 include_path ディレクティブを設定する †最後に、PHPのinclude_path ディレクティブを設定します。レンタルサーバではphp.iniを編集する事ができないので、.htaccessを使って設定する事にします。.htaccessは以下のような内容で仮想ルート(/)に設置します。 .htaccess php_value include_path ".:/usr/local/lib/php:/usr/local/lib/php/Smarty:{user-root}/PEAR"
上例の最初3つのパスはレンタルサーバであらかじめ設定されている値です。これはサーバ上でphpinfo()関数を実行すれば取得できます。また上の{user-root}は仮想ルートに対するサーバ上の物理パスを表しています。レンタルサーバ業者に問い合わせるか、もしくは以下のphpスクリプト(pwd.php)を実行するなどして取得してください。 pwd.php <?php echo getcwd() ?> include_pathディレクティブを設定する他の方法としては、PEARパッケージを使う各スクリプト中で、以下のようにしてinclude_path を設定する方法があります。 <?php
ini_set("include_path", '{user-root}/PEAR' . PATH_SEPARATOR . ini_get("include_path"));
?>
|