さくらサーバにPEAR
PEARを自由に使えるようにローカル環境にセットアップする。
インストールするレイアウトのイメージ。
$HOME/local ├─temp └─lib ├─bin └─php ├─docs ├─data └─tests 1. Installation prefix ($prefix) : /home/user/local 2. Temporary files directory : $prefix/temp 3. Binaries directory : $prefix/lib/bin 4. PHP code directory ($php_dir) : $prefix/lib/php 5. Documentation base directory : $php_dir/docs 6. Data base directory : $php_dir/data 7. Tests base directory : $php_dir/tests
レイアウトを用意して
$ mkdir $HOME/local/temp $HOME/local/lib/php $HOME/local/lib/php/data $HOME/local/lib/php/tests $HOME/local/lib/php/docs $ cd $HOME/local/src $ wget -O go-pear.php http://pear.php.net/go-pear $ cd $HOME/local $ php -f $HOME/local/src/go-pear.php
$ php -f $HOME/local/src/go-pear.php 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. Go-pear also lets you download and install the following optional PEAR packages: PEAR_Frontend_Web-beta, PEAR_Frontend_Gtk2, MDB2. If you wish to abort, press Control-C now, or press Enter to continue: HTTP proxy (http://user:password@proxy.myhost.com:port), or Enter for none:: 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 ($prefix) : /home/user/local/src 2. Temporary files directory : $prefix/temp 3. Binaries directory : $prefix/bin 4. PHP code directory ($php_dir) : $prefix/PEAR 5. Documentation base directory : $php_dir/docs 6. Data base directory : $php_dir/data 7. Tests base directory : $php_dir/tests 1-7, 'all' or Enter to continue: 1 Installation prefix ($prefix) [/home/user/local/src] : /home/user/local 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 ($prefix) : /home/user/local 2. Temporary files directory : $prefix/temp 3. Binaries directory : $prefix/bin 4. PHP code directory ($php_dir) : $prefix/PEAR 5. Documentation base directory : $php_dir/docs 6. Data base directory : $php_dir/data 7. Tests base directory : $php_dir/tests 1-7, 'all' or Enter to continue: 3 Binaries directory [$prefix/bin] : $prefix/lib/bin 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 ($prefix) : /home/user/local 2. Temporary files directory : $prefix/temp 3. Binaries directory : $prefix/lib/bin 4. PHP code directory ($php_dir) : $prefix/PEAR 5. Documentation base directory : $php_dir/docs 6. Data base directory : $php_dir/data 7. Tests base directory : $php_dir/tests 1-7, 'all' or Enter to continue: 4 PHP code directory ($php_dir) [$prefix/lib/php/] : $prefix/lib/php 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 ($prefix) : /home/user/local 2. Temporary files directory : $prefix/temp 3. Binaries directory : $prefix/lib/bin 4. PHP code directory ($php_dir) : $prefix/lib/php 5. Documentation base directory : $php_dir/docs 6. Data base directory : $php_dir/data 7. Tests base directory : $php_dir/tests 1-7, 'all' or Enter to continue: The following PEAR packages are bundled with PHP: PEAR_Frontend_Web-beta, PEAR_Frontend_Gtk2, MDB2. Would you like to install these as well? [Y/n] : Y Loading zlib: ok Bootstrapping Installer................... Bootstrapping PEAR.php............(remote) ok Bootstrapping Archive/Tar.php............(remote) ok Bootstrapping Console/Getopt.php............(remote) ok Extracting installer.................. Downloading package: PEAR.............ok Downloading package: Structures_Graph....ok Preparing installer.................. Updating channel "doc.php.net" Update of Channel "doc.php.net" succeeded Updating channel "pear.php.net" Update of Channel "pear.php.net" succeeded Updating channel "pecl.php.net" Update of Channel "pecl.php.net" succeeded Installing selected packages.................. Downloading and installing package: PEAR.............warning: pear/PEAR requires package "pear/Archive_Tar" (recommended version 1.3.2) warning: pear/PEAR requires package "pear/Structures_Graph" (recommended version 1.0.2) warning: pear/PEAR requires package "pear/Console_Getopt" (recommended version 1.2.3) pear/PEAR can optionally use package "pear/XML_RPC" (version >= 1.4.0) downloading PEAR-1.7.2.tgz ... Starting to download PEAR-1.7.2.tgz (302,744 bytes) ..............................................................done: 302,744 bytes install ok: channel://pear.php.net/PEAR-1.7.2 PEAR: Optional feature webinstaller available (PEAR's web-based installer) PEAR: Optional feature gtkinstaller available (PEAR's PHP-GTK-based installer) PEAR: Optional feature gtk2installer available (PEAR's PHP-GTK2-based installer) PEAR: To install optional features use "pear install pear/PEAR#featurename" Installing bootstrap package: Structures_Graph.......install ok: channel://pear.php.net/Structures_Graph-1.0.2 Downloading and installing package: Archive_Tar-stable.......downloading Archive_Tar-1.3.2.tgz ... Starting to download Archive_Tar-1.3.2.tgz (17,150 bytes) ...done: 17,150 bytes install ok: channel://pear.php.net/Archive_Tar-1.3.2 Downloading and installing package: Console_Getopt-stable.......downloading Console_Getopt-1.2.3.tgz ... Starting to download Console_Getopt-1.2.3.tgz (4,011 bytes) ...done: 4,011 bytes install ok: channel://pear.php.net/Console_Getopt-1.2.3 Downloading and installing package: PEAR_Frontend_Web-beta.......downloading PEAR_Frontend_Web-0.7.3.tgz ... Starting to download PEAR_Frontend_Web-0.7.3.tgz (53,152 bytes) ...done: 53,152 bytes downloading HTML_Template_IT-1.2.1.tgz ... Starting to download HTML_Template_IT-1.2.1.tgz (21,565 bytes) ...done: 21,565 bytes install ok: channel://pear.php.net/HTML_Template_IT-1.2.1 install ok: channel://pear.php.net/PEAR_Frontend_Web-0.7.3 Downloading and installing package: PEAR_Frontend_Gtk2.......Did not download optional dependencies: pear/XML_Parser, pear/XML_Util, use --alldeps to download automatically Did not download optional dependencies: pear/System_Command, use --alldeps to download automatically pear/PEAR_Frontend_Gtk2 requires PHP extension "php-gtk" (version >= 2.0.0dev) pear/Config can optionally use package "pear/XML_Parser" pear/Config can optionally use package "pear/XML_Util" pear/Gtk2_EntryDialog requires PHP extension "php-gtk" (version >= 2.0.0dev) pear/Gtk2_FileDrop requires PHP extension "php-gtk" (version >= 2.0.0dev) pear/MIME_Type can optionally use package "pear/System_Command" downloading Config-1.10.11.tgz ... Starting to download Config-1.10.11.tgz (27,939 bytes) ...done: 27,939 bytes downloading MIME_Type-1.2.0.tgz ... Starting to download MIME_Type-1.2.0.tgz (11,581 bytes) ...done: 11,581 bytes install ok: channel://pear.php.net/Config-1.10.11 install ok: channel://pear.php.net/MIME_Type-1.2.0 Downloading and installing package: MDB2.............downloading MDB2-2.4.1.tgz ... Starting to download MDB2-2.4.1.tgz (119,790 bytes) ...done: 119,790 bytes install ok: channel://pear.php.net/MDB2-2.4.1 MDB2: Optional feature fbsql available (Frontbase SQL driver for MDB2) MDB2: Optional feature ibase available (Interbase/Firebird driver for MDB2) MDB2: Optional feature mysql available (MySQL driver for MDB2) MDB2: Optional feature mysqli available (MySQLi driver for MDB2) MDB2: Optional feature mssql available (MS SQL Server driver for MDB2) MDB2: Optional feature oci8 available (Oracle driver for MDB2) MDB2: Optional feature pgsql available (PostgreSQL driver for MDB2) MDB2: Optional feature querysim available (Querysim driver for MDB2) MDB2: Optional feature sqlite available (SQLite2 driver for MDB2) MDB2: To install optional features use "pear install pear/MDB2#featurename" ****************************************************************************** WARNING! The include_path defined in the currently used php.ini does not contain the PEAR PHP directory you just specified: </home/user/local/lib/php> If the specified directory is also not in the include_path used by your scripts, you will have problems getting any PEAR packages working. Would you like to alter php.ini </usr/local/php/5.2.8/lib/php.ini>? [Y/n] : Y ****************************************************************************** WARNING! I cannot write to /usr/local/php/5.2.8/lib/php.ini, but I succesfully created a php.ini under </home/user/local/php.ini-gopear>. Please replace the file </usr/local/php/5.2.8/lib/php.ini> with </home/user/local/php.ini-gopear> or modify your php.ini by adding: include_path=".:/home/user/local/lib/php" Current include path : .:/usr/local/php/5.2.8/lib/php Configured directory : /home/user/local/lib/php Currently used php.ini (guess) : /usr/local/php/5.2.8/lib/php.ini Press Enter to continue: ** WARNING! The link /usr/local/bin/pear does not point to the installed /home/user/local/lib/bin/pear The 'pear' command is now at your service at /home/user/local/lib/bin/pear ** The 'pear' command is not currently in your PATH, so you need to ** use '/home/user/local/lib/bin/pear' until you have added ** '/home/user/local/lib/bin' to your PATH environment variable. Run it without parameters to see the available actions, try 'pear list' to see what packages are installed, or 'pear help' for help. For more information about PEAR, see: http://pear.php.net/faq.php http://pear.php.net/manual/ Thanks for using go-pear!
PEARの動作確認がてら使うNet_UserAgent_Mobileをインストール。
$ pear list Installed packages, channel pear.php.net: ========================================= Package Version State Archive_Tar 1.3.2 stable Config 1.10.11 stable Console_Getopt 1.2.3 stable HTML_Template_IT 1.2.1 stable MDB2 2.4.1 stable MIME_Type 1.2.0 stable PEAR 1.7.2 stable PEAR_Frontend_Web 0.7.3 beta Structures_Graph 1.0.2 stabl $ pear install -f Net_UserAgent_Mobile $ pear list Installed packages, channel pear.php.net: ========================================= Package Version State Archive_Tar 1.3.2 stable Config 1.10.11 stable Console_Getopt 1.2.3 stable HTML_Template_IT 1.2.1 stable MDB2 2.4.1 stable MIME_Type 1.2.0 stable Net_UserAgent_Mobile 1.0.0RC1 beta PEAR 1.7.2 stable PEAR_Frontend_Web 0.7.3 beta Structures_Graph 1.0.2 stabl
とくにはまることもなくインストール完了。
php.iniが書き換えできないというwarningが出てローカルにコピーが作られている。
ちょうど自分php.iniを用意しようと思っていたので、中身を確認してこれを流用する。
$ diff /usr/local/php/5.2.8/lib/php.ini $HOME/local/php.ini-gopear 1283a1284,1289 > > > ;***** Added by go-pear > include_path=".:/home/user/local/lib/php" > ;***** >
php.iniをApacheのドキュメントルート直下にコピーして設定を変更する。
エラーログやセッションファイルの書き込み用にディレクトリも用意する。
$ cp $HOME/local/php.ini-gopear $HOME/www/php.ini $ $HOME/var $HOME/var/log $HOME/var/sess $ vi $HOME/www/php.ini $ diff $HOME/local/php.ini-gopear $HOME/www/php.ini 83c83 < short_open_tag = On --- > short_open_tag = Off 101c101 < output_buffering = Off --- > output_buffering = 4096 301c301 < error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR --- > error_reporting = E_ALL 332c332 < log_errors = Off --- > log_errors = On 364c364 < ;html_errors = Off --- > html_errors = Off 383c383 < ;error_log = filename --- > error_log = /home/user/var/log/php_error_log 386c386 < error_log = syslog --- > ;error_log = syslog 424c424 < register_long_arrays = On --- > register_long_arrays = Off 429c429 < register_argc_argv = On --- > register_argc_argv = Off 445c445 < magic_quotes_gpc = On --- > magic_quotes_gpc = Off 463c463 < ;default_charset = "iso-8859-1" --- > default_charset = "shift_jis" 560c560 < allow_url_fopen = On --- > allow_url_fopen = Off 992c992 < ;session.save_path = "/tmp" --- > session.save_path = "/home/user/var/sess" 997c997 < ;session.cookie_secure = --- > session.cookie_secure = 0 1001c1001 < ; session.use_only_cookies = 1 --- > session.use_only_cookies = 1 1030,1031c1030,1031 < session.gc_probability = 1 < session.gc_divisor = 100 --- > session.gc_probability = 1 > session.gc_divisor = 24 1035c1035 < session.gc_maxlifetime = 1440 --- > session.gc_maxlifetime = 3600 1060c1060 < session.entropy_length = 0 --- > ;session.entropy_length = 0 1063c1063 < session.entropy_file = --- > ;session.entropy_file = 1065c1065 < ;session.entropy_length = 16 --- > session.entropy_length = 16 1067c1067 < ;session.entropy_file = /dev/urandom --- > session.entropy_file = /dev/urandom 1071c1071 < session.cache_limiter = nocache --- > session.cache_limiter = private_no_expire 1198c1198 < ;mbstring.http_input = auto --- > mbstring.http_input = pass 1202c1202 < ;mbstring.http_output = SJIS --- > mbstring.http_output = pass 1209c1209 < ;mbstring.encoding_translation = Off --- > mbstring.encoding_translation = Off 1213c1213 < ;mbstring.detect_order = auto --- > mbstring.detect_order = SJIS,EUC-JP,JIS,UTF-8,ASCII 1217c1217 < ;mbstring.substitute_character = none; --- > mbstring.substitute_character = none;
PHPの設定内容の確認と動作の確認。
ApacheモジュールのPHPはコントロールパネルから「PHP言語に関する設定」にいき、「PHP設定ファイルの編集」の「保存」をしないとphp.iniが切り替わらないから注意。
$ php -i | less $ php -c $HOME/www/php.ini -i | less $ echo "<?php phpinfo() ?>" > phpinfo.php $ cat phpinfo.php <?php phpinfo() ?> $ echo "<?php trigger_error('test notice', E_USER_NOTICE) ?>" >> error.php $ echo "<?php trigger_error('test error', E_USER_ERROR) ?>" >> error.php # echo "<?php trigger_error('test error', E_USER_ERROR) ?>" >> error.php $ cat error.php <?php trigger_error('test notice', E_USER_NOTICE) ?> <?php trigger_error('test warning', E_USER_WARNING) ?> <?php trigger_error('test error', E_USER_ERROR) ?> $ echo '<?php session_start(); if(!isset($_SESSION["i"])) $_SESSION["i"]=0; echo ++$_SESSION["i"]; ?>' >> session.php $ cat session.php <?php session_start(); if(!isset($_SESSION["i"])) $_SESSION["i"]=0; echo ++$_SESSION["i"]; ?>
ブラウザ経由でそれぞれのPHPスクリプトを動作確認して、ログやセッションファイルの書き込みも確認する。
$ls $HOME/var/log php_error_log $ cat $HOME/var/log/php_error_log [14-Mar-2009 11:40:57] PHP Notice: test notice in /home/user/www/error.php on line 1 [14-Mar-2009 11:40:57] PHP Warning: test warning in /home/user/www/error.php on line 2 [14-Mar-2009 11:40:57] PHP Fatal error: test error in /home/user/www/error.php on line 3 $ ls $HOME/var/sess sess_4f8e0b693b9b0508cc6c1470381c80a8 $ cat $HOME/var/sess/sess_4f8e0b693b9b0508cc6c1470381c80a8 i|i:5;