2008年6月20日 星期五

[FreeBSD]PHP PEAR安裝

Setp 1.
安裝 Apache + MySQL + PHP 的基本 web 環境:

#cd /usr/ports/database/mysql50-server # 安裝 MySQL 50
#make install clean

#cd /usr/ports/www/apache20 # 安裝 Apache 20
#make install clean

#cd /usr/ports/lang/php5 # 安裝 PHP5
#make install clean # 我只有選擇下列相關套件一併安裝
[X] CLI Build CLI version
[X] CGI Build CGI version
[X] APACHE Build Apache module
[X] FASTCGI Enable fastcgi support (CGI only)
[X] PATHINFO Enable path-info-check support (CGI only)

#cd /usr/ports/lang/php5-extensions # 安裝 PHP5-Extensions
#make config # 安裝前先手動選擇所需要的延伸套件
[X] CTYPE ctype functions
[X] DOM DOM support
[X] GD GD library support
[X] GETTEXT gettext library support
[X] HASH HASH Message Digest Framework
[X] ICONV iconv support
[X] MYSQL MySQL database support
[X] PCRE Perl Compatible Regular Expression support
[X] PDO PHP Data Objects Interface (PDO)
[X] POSIX POSIX-like functions
[X] SESSION session support
[X] SIMPLEXML simplexml support
[X] SQLITE sqlite support
[X] TOKENIZER tokenizer support
[X] XML XML support
[X] XMLREADER XMLReader support
[X] XMLWRITER XMLWriter support
[X] ZLIB ZLIB support

#make install # 因為 Extensions 有選 GD library 所以必須要選擇加裝 T1LIB 及 TRUETYPE 同時 SQLITE 也必須選擇是否開啟 UTF-8 編碼

Options for php5-gd 5.1.6
[X] T1LIB Include T1lib support
[X] TRUETYPE Enable TrueType string function

Options for php5-sqlite 5.1.6 # PHP 下的精簡型文字資料庫 Text Database
[X] UTF8 Enable UTF-8 support

#vi /etc/rc.conf # 編輯 FreeBSD 的開機設定檔,設定 mysql 及 apache 開機自動啟動

mysql_enable="YES"
apache2_enable="YES"

#vi httpd.conf # 編輯 Apache 的設定檔,加入下列幾行:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.php

#cp /usr/local/etc/php.ini-dist /usr/local/etc/php.ini # 編輯 PHP5 的設定檔將複製 php.ini-dist 到 php.ini

#vi php.ini # 如果必須要相容舊語法可將 Off 改為 On
register_globals = On

#apachectl # 重新啟動 apache

#reboot # 重開機讓 MySQL 啟動

Setp 2.

安裝 PEAR 開發環境及基本套件:
#cd /usr/ports/devel/pear # 安裝 PEAR 套件管理指令 ( 這邊只是 PEAR 的套件管理指令,PEAR 的基本套件要等裝完 lynx 才可加裝 )
#make install clean

#vi /usr/local/etc/php.ini # 將 pear 的絕對路徑加到 php.ini 設定檔中

include_path = ".:/usr/local/share/pear"

#cd /usr/ports/www/lynx # 安裝 lynx
#make install clean

#lynx -source http://go-pear.org | php # 安裝 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.
Go-pear also lets you download and install the PEAR packages bundled
with PHP: MDB2.

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 # ( 我無 proxy 所以跳過 )

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 : /usr/local
2. Binaries directory : $prefix/bin
3. PHP code directory ($php_dir) : $prefix/share/pear
4. Documentation base directory : $php_dir/docs
5. Data base directory : $php_dir/data
6. Tests base directory : $php_dir/tests
7. Temporary files directory : $prefix/temp
1-7, 'all' or Enter to continue: 按 Enter

The following PEAR packages are bundled with PHP: MDB2.

Would you like to install these as well? [Y/n] : y

#apachectl restart # 重新啟動 apache

#pear list # 查看 pear 已安裝的套件版本

Installed packages, channel pear.php.net:
==============================
Package Version State
Archive_Tar 1.3.1 stable
Console_Getopt 1.2 stable
MDB2 2.2.2 stable
PEAR 1.4.11 stable
XML_RPC 1.5.0 stable

Setp 3.

安裝套件並且測試安裝結果:
#chown -Rf www:www /usr/local/share/pear # 修改 pear 套件存放目錄權限
#chown www:www /usr/local/share # 修改 pear 套件目錄權限
#pear install Benchmark # 安裝一個套件來測試看看
pear/Benchmark can optionally use PHP extension "bcmath"
downloading Benchmark-1.2.6.tgz ...
Starting to download Benchmark-1.2.6.tgz (7,915 bytes)

.....done: 7,915 bytes
install ok: channel://pear.php.net/Benchmark-1.2.6

#pear list # 再次查看所有已安裝套件
Installed packages, channel pear.php.net:
=========================================
Package Version State
Archive_Tar 1.3.1 stable
Benchmark 1.2.6 stable
Console_Getopt 1.2 stable
MDB2 2.2.2 stable
PEAR 1.4.11 stable
XML_RPC 1.5.0 stable

#cd /usr/local/share/pear/Benchmark # 查看所安裝的套件目錄
# ls -l # Benchmark 下總共有三個套件
total 30
-rw-r--r-- 1 root www 4658 9 14 17:40 Iterate.php
-rw-r--r-- 1 root www 13323 9 14 17:40 Profiler.php
-rw-r--r-- 1 root www 10095 9 14 17:40 Timer.php

#vi Timer.php # 查半 Timer.php 這個套件如何引用 Timer 裡面有說明

#vi /usr/local/www/data-dist/show.php # 寫個 php 的時間計數小程式來測試

require_once 'Benchmark/Timer.php';

$timer = new Benchmark_Timer();

$timer->start();

echo "Hello World!";

$timer->stop();

$totaltime=$timer->timeElapsed();

echo "
This Page Show Time:".$totaltime."Sec";
?>


http://xxx.xxx.xxx.xxx/show.php # 開個瀏覽器看一下 Timer 計時器是否成功

Hello World!
This Page Show Timer:0.000207185745239Sec

#pear install PEAR_Info

#vi /usr/local/www/data-dist/info.php
require_once 'PEAR/Info.php';
$pear_info = new PEAR_info();
$pear_info ->show();
?>

http://xxx.xxx.xxx.xxx/info.php # 開個瀏覽器可看見PEAR 設定檔及所安裝的套件訊息

To Add .

#pear uninstall Benchmark # 解除安裝套件
#pear help # 查看 pear 指令
<<本文引自四位的freebsd學習技術文件>>

沒有留言:

wibiya widget