The Will Will Web

記載著 Will 在網路世界的學習心得與技術分享

Ubuntu 8.04 LTS 如何安裝 PHP4

據我所知 Ubuntu Linux 大概從 6.06 (Dapper) 開始就不支援 PHP4 了,且 PHP 官方網站也宣布從 2007-12-31 起停止了 PHP4 的計畫(也就是以後也不會再出新版),不過我想應該還是有不少網站是用 PHP4 寫的,要讓這些網站在短時間內全部升級改寫成 PHP5 的版本還真不太容易。今天我也把 Ubuntu 8.04 LTS 裝起來了,並嘗試著也將 php4 裝起來,以下是在 Ubuntu 8.04 成功安裝 php4 的心得分享(當然這個方法在 Ubuntu 6.06, 6.10 或 7.10 一樣適用)。

1. 建立一個檔案到 /etc/apt/sources.list.d/ 目錄下:

# vi /etc/apt/sources.list.d/dapper.sources.list

   檔案內容僅需要輸入一行即可:

deb http://tw.archive.ubuntu.com/ubuntu/ dapper universe main restricted multiverse

2. 執行 apt-get update 指令更新 Packages 資料庫

root@ubuntu804:~# apt-get update
Hit http://tw.archive.ubuntu.com hardy Release.gpg
Hit http://tw.archive.ubuntu.com hardy-updates Release.gpg
Hit http://tw.archive.ubuntu.com dapper Release.gpg
Hit http://tw.archive.ubuntu.com hardy Release
Hit http://tw.archive.ubuntu.com hardy-updates Release
Hit http://tw.archive.ubuntu.com dapper Release
Hit http://tw.archive.ubuntu.com hardy/main Packages
Hit http://tw.archive.ubuntu.com hardy/restricted Packages
Hit http://tw.archive.ubuntu.com hardy/main Sources
Hit http://tw.archive.ubuntu.com hardy/restricted Sources
Hit http://tw.archive.ubuntu.com hardy/universe Packages
Hit http://tw.archive.ubuntu.com hardy/universe Sources
Hit http://tw.archive.ubuntu.com hardy/multiverse Packages
Hit http://tw.archive.ubuntu.com hardy/multiverse Sources
Hit http://tw.archive.ubuntu.com hardy-updates/main Packages
Hit http://tw.archive.ubuntu.com hardy-updates/restricted Packages
Hit http://tw.archive.ubuntu.com hardy-updates/main Sources
Hit http://security.ubuntu.com hardy-security Release.gpg
Hit http://tw.archive.ubuntu.com hardy-updates/restricted Sources
Hit http://security.ubuntu.com hardy-security Release
Hit http://security.ubuntu.com hardy-security/main Packages
Hit http://tw.archive.ubuntu.com hardy-updates/universe Packages
Hit http://security.ubuntu.com hardy-security/restricted Packages
Hit http://security.ubuntu.com hardy-security/main Sources
Hit http://security.ubuntu.com hardy-security/restricted Sources
Hit http://tw.archive.ubuntu.com hardy-updates/universe Sources
Hit http://security.ubuntu.com hardy-security/universe Packages
Hit http://security.ubuntu.com hardy-security/universe Sources
Hit http://security.ubuntu.com hardy-security/multiverse Packages
Hit http://security.ubuntu.com hardy-security/multiverse Sources
Hit http://tw.archive.ubuntu.com hardy-updates/multiverse Packages
Hit http://tw.archive.ubuntu.com hardy-updates/multiverse Sources
Hit http://tw.archive.ubuntu.com dapper/universe Packages
Hit http://tw.archive.ubuntu.com dapper/main Packages
Hit http://tw.archive.ubuntu.com dapper/restricted Packages
Hit http://tw.archive.ubuntu.com dapper/multiverse Packages
Reading package lists... Done

   你可以發現最後面取得的時 dapper/universe 套件,這裡面就有包括 php4 的所有相關套件。

3. 搜尋所有 php4 相關的套件

root@ubuntu804:~# apt-cache search php4
apache2-prefork-dev - development headers for apache2
cakephp - MVC rapid application development framework for PHP
cakephp1.2 - MVC rapid application development framework for PHP (1.2 version)
caudium - An extensible WWW server written in Pike
dtc - web control panel for admin and accounting hosting services
libphp-phplot - The graphic library for PHP
php-image-canvas - Image_Canvas module for PEAR
php-image-graph - Image_Graph module for PEAR
php5-syck - YAML parser kit -- PHP5 bindings
php-doc - Documentation for PHP4 and PHP5
dbtcp - Miscellaneous command-line DBTCP utils
fibusql - Web based double-entry accounting
libapache-mod-php4 - server-side, HTML-embedded scripting language (apache 1.3 module)
libapache2-mod-php4 - server-side, HTML-embedded scripting language (apache 2.0 module)
odontolinux - Dental office management software (PHP4 + PostgreSQL)
php4 - server-side, HTML-embedded scripting language (meta-package)
php4-apd - PHP code execution profiler and debugger
php4-auth-pam - A PHP extension for PAM authentication
php4-cgi - server-side, HTML-embedded scripting language (CGI binary)
php4-clamavlib - PHP ClamAV Lib - ClamAV Interface for PHP4 Scripts
php4-cli - command-line interpreter for the php4 scripting language
php4-common - Common files for packages built from the php4 source
php4-curl - CURL module for php4
php4-dbtcp - PHP bindings for DBTCP
php4-dev - Files for PHP4 module development
php4-domxml - XMLv2 module for php4
php4-gd - GD module for php4
php4-gpib - libgpib php bindings
php4-idn - PHP api for the IDNA library
php4-imagick - ImageMagick module for php4
php4-imap - IMAP module for php4
php4-interbase - interbase/firebird module for php4
php4-json - json serialiser for PHP4
php4-kadm5 - An extension to manage kerberos admin information
php4-lasso - Liberty ID-FF library - PHP 4 bindings
php4-ldap - LDAP module for php4
php4-mapscript - module for php4-cgi to use mapserver
php4-maxdb - PHP extension to access MaxDB databases
php4-mcal - MCAL calendar module for php4
php4-mcrypt - MCrypt module for php4
php4-mhash - MHASH module for php4
php4-mysql - MySQL module for php4
php4-odbc - ODBC module for php4
php4-pear - PHP Extension and Application Repository (transitional package)
php4-pear-log - Log module for PEAR
php4-pgsql - PostgreSQL module for php4
php4-ps - An extension to create PostScript files
php4-pspell - pspell module for php4
php4-recode - Character recoding module for php4
php4-rrdtool - RRD module for php4
php4-snmp - SNMP module for php4
php4-spplus - Secured payment system of the Caisse d'Epargne (French bank)
php4-sqlite - PHP4 bindings to SQLite, a file-based SQL engine
php4-sqlrelay - SQL Relay PHP API
php4-sybase - Sybase / MS SQL Server module for php4
php4-tclink - TrustCommerce TCLink module for php4
php4-uuid - OSSP uuid module for php4
php4-xslt - XSLT module for php4
php4-yaz - php/yaz z39.50 module
phpgroupware-felamimail - phpGroupWare felamimail (Squirrelmail) module

4. 安裝 php4-cli

root@ubuntu804:~# apt-get install php4-cli
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  libdb4.3 libpcre3 libzzip-0-12 php4-common
Suggested packages:
  php-pear
The following NEW packages will be installed:
  libdb4.3 libpcre3 libzzip-0-12 php4-cli php4-common
0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
Need to get 0B/2389kB of archives.
After this operation, 5018kB of additional disk space will be used.
Do you want to continue [Y/n]?
Selecting previously deselected package libdb4.3.
(Reading database ... 16202 files and directories currently installed.)
Unpacking libdb4.3 (from .../libdb4.3_4.3.29-11ubuntu1_i386.deb) ...
Selecting previously deselected package libpcre3.
Unpacking libpcre3 (from .../libpcre3_7.4-1ubuntu2_i386.deb) ...
Selecting previously deselected package libzzip-0-12.
Unpacking libzzip-0-12 (from .../libzzip-0-12_0.12.83-5_i386.deb) ...
Selecting previously deselected package php4-common.
Unpacking php4-common (from .../php4-common_4%3a4.4.2-1build1_i386.deb) ...
Selecting previously deselected package php4-cli.
Unpacking php4-cli (from .../php4-cli_4%3a4.4.2-1build1_i386.deb) ...
Setting up libdb4.3 (4.3.29-11ubuntu1) ...
Setting up libpcre3 (7.4-1ubuntu2) ...

Setting up libzzip-0-12 (0.12.83-5) ...

Setting up php4-common (4:4.4.2-1build1) ...
Setting up php4-cli (4:4.4.2-1build1) ...

Processing triggers for libc6 ...
ldconfig deferred processing now taking place

5. 大功告成!我們來測試一下 php4 是否可以正常執行:

root@ubuntu804:~# php4 -v
PHP Warning:  mime_magic: type search/400       \\input         text/x-tex invalid in Unknown on line 0
PHP Warning:  mime_magic: type search/400       \\section       text/x-tex invalid in Unknown on line 0
PHP Warning:  mime_magic: type search/400       \\setlength     text/x-tex invalid in Unknown on line 0
PHP Warning:  mime_magic: type search/400       \\documentstyle text/x-tex invalid in Unknown on line 0
PHP Warning:  mime_magic: type search/400       \\chapter       text/x-tex invalid in Unknown on line 0
PHP Warning:  mime_magic: type search/400       \\documentclass text/x-tex invalid in Unknown on line 0
PHP Warning:  mime_magic: type regex            [Cc]onstant[[:space:]]+[Ss]tory text/x-inform invalid in Unknown on line 0
PHP 4.4.2-1build1 (cli) (built: Apr  6 2006 09:44:32)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies

   你可以發現執行的過程會出現一堆 PHP Warning 的警告訊息,這是因為 Ubuntu 8.04 中預設的 /usr/share/file/magic.mime (MIME 定義檔) 檔案中有幾行 php4 認不得,而導致出現警示訊息,不過這幾行並不會影響 PHP 的運作。

   因為在 magic.mime 中的這 7 行是用來定義 TeX documents 與 Inform interactive fiction language 的檔案類型,因為很少用到,所以我覺得將這幾行註解掉應該沒關係!所以我們還是修改一下 magic.mime 檔案,將這幾行「太新」的 MIME 定義給註解掉,讓 php4 不會出現警告訊息。你開啟 /usr/share/file/magic.mime 檔案後直接跳到第598行:

# TeX documents, from Daniel Quinlan (quinlan@yggdrasil.com)
0       search/400      \\input         text/x-tex
0       search/400      \\section       text/x-tex
0       search/400      \\setlength     text/x-tex
0       search/400      \\documentstyle text/x-tex
0       search/400      \\chapter       text/x-tex
0       search/400      \\documentclass text/x-tex

# Type: Inform interactive fiction language
# URL:  http://www.inform-fiction.org/
# From: Reuben Thomas <rrt@sc3d.org>
0       regex           [Cc]onstant[[:space:]]+[Ss]tory text/x-inform

這要將這幾行最前面加上井字號 ( # ) 後存檔,然後我們在測試一下 php4 是否正常執行:

root@ubuntu804:~# php -v
PHP 4.4.2-1build1 (cli) (built: Apr  6 2006 09:44:32)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies

完成 php4 安裝!

相關連結