php 安裝設定教學
官方網站:http://www.php.net/
實作版本下載點:
php 4.x:http://tw.php.net/distributions/php-4.4.2-Win32.zip
php 5.x:http://tw.php.net/distributions/php-5.1.1-installer.exe、http://tw.php.net/distributions/php-5.1.1-Win32.zip
功能:伺服器端的程式語言,可產生動態網頁,並可搭配 MySQL 資料庫儲存並管理資料。
php 4.x 與 php 5.x 還是有相容性上的問題,如果完全沒有舊程式的包袱,建議一開始就可以安裝 php 5.x 版了。但如果有使用到某些 blog 系統、論壇等等的,可能得要 php 4.x 才能夠正常執行喔!
以下的安裝步驟將分為 4.x 與 5.x 兩種不同的版本說明。
php 4.x 篇
安裝步驟
- 將 php-4.4.2-Win32.zip 解壓縮至 C:\PHP 資料夾。
- 複製 php.ini-recommended 到 %SYSTEMROOT% 資料夾下並改名為 php.ini。
- 複製 C:\PHP\sapi\php4apache2.dll 到 C:\PHP。
- 複製 C:\PHP\libeay32.dll 與 C:\PHP\ssleay32.dll 至 %SYSTEMROOT%\System32 資料夾。
- 就是這麼簡單,接下來設定的部分請參考 php 5.x 的說明即可。
php 5.x 篇
安裝步驟
- 下載並執行 php-5.1.1-installer.exe。
- 安裝程式起始(Installation Wizard)畫面:
- 直接按 Next。
- 使用許可協議(License Agreement)畫面:
- 按 I Agree。
- 讀我檔案(Read This First)畫面:
- 直接按 Next。
- 安裝類型選擇(Installation Type)畫面:
- 點選 Standard。
- 按 Next。
- 安裝目錄設定(Choose Destination Location)畫面:
- 直接按 Next。
- 郵件設定(Mail Configuration)畫面:
- SMTP Server 請依照 ISP 提供的資料設定。
- 'From' Address fot the Mail 請填自己的 Email 信箱。
- 按 Next。
- 伺服器類型選擇(Server Type)畫面:
- 點選 Apache。
- 按 Next。
- 準備開始安裝(Start Installation)畫面:
- 直接按 Next。
- Apache 設定(Apache Configuration)畫面:
- 若出現此訊息可先按 OK 略過,稍後再進行設定。
- 安裝完成(Installation Complete)畫面:
- 按 OK。
- 安裝成功。
- 解壓縮 php-5.1.1-Win32.zip 至 C:\PHP 資料夾,並覆蓋所有檔案。
- 複製 C:\PHP\libeay32.dll 與 C:\PHP\ssleay32.dll 至 %SYSTEMROOT%\System32 資料夾。
設定步驟
php.ini 設定
用記事本開啟 %SystemRoot%\php.ini,並按照以下原則進行修改。
請自行以關鍵字尋找並取代預設設定,若沒有預設設定則新增在檔案最後面即可。
強調的部分請依實際情況修改。
請注意斜線(/)與反斜線(\)的不同,以免造成不必要的錯誤。
設定完成後必須重新啟動伺服器以套用新的設定。
- 延伸函式庫目錄與常用延伸函式庫設定
設定說明:
- 以 C:\PHP\ext 目錄作為延伸函式庫存放路徑。
- php_mbstring.dll 為多位元字元函式庫,可改善對中文及其他多位元組成的文字的處理能力。
- 其餘延伸函式庫請依需要自行設定。
extension_dir = "C:/PHP/ext" extension=php_mbstring.dll extension=php_curl.dll extension=php_gd2.dll include_path = ".;C:/PHP;C:/PHP/cli;C:/PHP/dlls;C:/PHP/extensions;C:/PHP/sapi"
httpd.conf 設定
用記事本開啟 C:\Program Files\Apache Group\Apache2\conf\httpd.conf,並按照以下原則進行修改。
請自行以關鍵字尋找並取代預設設定,若沒有預設設定則新增在檔案最後面即可。
強調的部分請依實際情況修改。
請注意斜線(/)與反斜線(\)的不同,以免造成不必要的錯誤。
設定完成後必須重新啟動伺服器以套用新的設定。
- 使 Apache 支援 php
設定說明:
- 檔案位置與名稱根據所用的版本稍微有些不同,請於 C:\PHP 資料夾中尋找合適版本。這裡以 Apache 2.x 搭配 php 5.x 設定為例。
LoadModule php5_module "C:/PHP/php5apache2.dll" LoadFile "C:/PHP/php5ts.dll"- 如果是使用 php 4.x,則設定如下:
LoadModule php4_module "C:/PHP/php4apache2.dll" LoadFile "C:/PHP/php4ts.dll" - 設定 index.php 為索引頁檔名之一
設定說明:
- 若有可能以 index.php 為首頁檔名,則需做此設定。
DirectoryIndex index.html index.xml index.php - 設定 php 類型檔案的 MIME Type
設定說明:
- 讓 Apache 使用正確的方式處理 php 副檔名的檔案。
AddType application/x-httpd-php .php
附錄 - PHP Extensions 說明
摘錄自 Installation of extensions on Windows。
| Extension | Description | Notes |
|---|---|---|
| php_bz2.dll | bzip2 compression functions | None |
| php_calendar.dll | Calendar conversion functions | Built in since PHP 4.0.3 |
| php_cpdf.dll | ClibPDF functions | None |
| php_crack.dll | Crack functions | None |
| php_ctype.dll | ctype family functions | Built in since PHP 4.3.0 |
| php_curl.dll | CURL, Client URL library functions | Requires: libeay32.dll, ssleay32.dll (bundled) |
| php_cybercash.dll | Cybercash payment functions | PHP <= 4.2.0 |
| php_db.dll | DBM functions | Deprecated. Use DBA instead (php_dba.dll) |
| php_dba.dll | DBA: DataBase (dbm-style) Abstraction layer functions | None |
| php_dbase.dll | dBase functions | None |
| php_dbx.dll | dbx functions | |
| php_domxml.dll | DOM XML functions | PHP <= 4.2.0 requires: libxml2.dll (bundled) PHP >= 4.3.0 requires: iconv.dll (bundled) |
| php_dotnet.dll | .NET functions | PHP <= 4.1.1 |
| php_exif.dll | EXIF functions | php_mbstring.dll. And, php_exif.dll must be loaded after php_mbstring.dll in php.ini. |
| php_fbsql.dll | FrontBase functions | PHP <= 4.2.0 |
| php_fdf.dll | FDF: Forms Data Format functions. | Requires: fdftk.dll (bundled) |
| php_filepro.dll | filePro functions | Read-only access |
| php_ftp.dll | FTP functions | Built-in since PHP 4.0.3 |
| php_gd.dll | GD library image functions | Removed in PHP 4.3.2. Also note that truecolor functions are not available in GD1, instead, use php_gd2.dll. |
| php_gd2.dll | GD library image functions | GD2 |
| php_gettext.dll | Gettext functions | PHP <= 4.2.0 requires gnu_gettext.dll (bundled), PHP >= 4.2.3 requires libintl-1.dll, iconv.dll (bundled). |
| php_hyperwave.dll | HyperWave functions | None |
| php_iconv.dll | ICONV characterset conversion | Requires: iconv-1.3.dll (bundled), PHP >=4.2.1 iconv.dll |
| php_ifx.dll | Informix functions | Requires: Informix libraries |
| php_iisfunc.dll | IIS management functions | None |
| php_imap.dll | IMAP POP3 and NNTP functions | None |
| php_ingres.dll | Ingres II functions | Requires: Ingres II libraries |
| php_interbase.dll | InterBase functions | Requires: gds32.dll (bundled) |
| php_java.dll | Java functions | PHP <= 4.0.6 requires: jvm.dll (bundled) |
| php_ldap.dll | LDAP functions | PHP <= 4.2.0 requires libsasl.dll (bundled), PHP >= 4.3.0 requires libeay32.dll, ssleay32.dll (bundled) |
| php_mbstring.dll | Multi-Byte String functions | None |
| php_mcrypt.dll | Mcrypt Encryption functions | Requires: libmcrypt.dll |
| php_mhash.dll | Mhash functions | PHP >= 4.3.0 requires: libmhash.dll (bundled) |
| php_mime_magic.dll | Mimetype functions | Requires: magic.mime (bundled) |
| php_ming.dll | Ming functions for Flash | None |
| php_msql.dll | mSQL functions | Requires: msql.dll (bundled) |
| php_mssql.dll | MSSQL functions | Requires: ntwdblib.dll (bundled) |
| php_mysql.dll | MySQL functions | PHP >= 5.0.0, requires libmysql.dll (bundled) |
| php_mysqli.dll | MySQLi functions | PHP >= 5.0.0, requires libmysql.dll (libmysqli.dll in PHP <= 5.0.2) (bundled) |
| php_oci8.dll | Oracle 8 functions | Requires: Oracle 8.1+ client libraries |
| php_openssl.dll | OpenSSL functions | Requires: libeay32.dll (bundled) |
| php_oracle.dll | Oracle functions | Requires: Oracle 7 client libraries |
| php_overload.dll | Object overloading functions | Built in since PHP 4.3.0 |
| php_pdf.dll | PDF functions | None |
| php_pgsql.dll | PostgreSQL functions | None |
| php_printer.dll | Printer functions | None |
| php_shmop.dll | Shared Memory functions | None |
| php_snmp.dll | SNMP get and walk functions | NT only! |
| php_soap.dll | SOAP functions | PHP >= 5.0.0 |
| php_sockets.dll | Socket functions | None |
| php_sybase_ct.dll | Sybase functions | Requires: Sybase client libraries |
| php_tidy.dll | Tidy functions | PHP >= 5.0.0 |
| php_tokenizer.dll | Tokenizer functions | Built in since PHP 4.3.0 |
| php_w32api.dll | W32api functions | None |
| php_xmlrpc.dll | XML-RPC functions | PHP >= 4.2.1 requires: iconv.dll (bundled) |
| php_xslt.dll | XSLT functions | PHP <= 4.2.0 requires sablot.dll, expat.dll (bundled). PHP >= 4.2.1 requires sablot.dll, expat.dll, iconv.dll (bundled). |
| php_yaz.dll | YAZ functions | Requires: yaz.dll (bundled) |
| php_zip.dll | Zip File functions | Read only access |
| php_zlib.dll | ZLib compression functions | Built in since PHP 4.3.0 |