首先是安裝JRE或者JDK,網上大把方法,敬請搜尋。我偷懶。
其次,裝XAMPP,安裝方法連結如下:這裡假設XAMPP的安裝路徑為:/opt/lampp
http://unixfans.blogbus.com/logs/34373510.html
再次,裝eclipse,安裝PDT整合版本的eclipse,如下,選擇ALL IN ONE版本的PDT
http://www.eclipse.org/pdt/downloads/
這個最簡單,下好後直接解壓到你希望的目錄位址就算安裝完成了,我這裡假設安裝在:/home/yourname/eclipse
eclipse運行前的一些配置步驟,看這裡的第2部分:http://unixfans.blogbus.com/logs/33942617.html
第一次運行eclipse時,需要指定workspace的地址,如果你只是為了開發php,那麼可以把工作區地址指定到:/opt/lampp/htdocs ,因為這裡是XAMPP中apache的docs地址,添加的php檔案可以直接在瀏覽器中運行。但壞處是刪除檔案時要小心,不然把XAMPP中htdocs檔案夾裡原有的檔案刪除了。也可以不這樣做,將工作區用ln命令連結到htdocs檔案夾下即可。
以上兩樣的安裝都比較簡單,直接解壓就搞定了。下面開始裝Xdebug,在這裡下載已經編譯好的Xdebug remote檔案,注意你的版本和系統類別型。
http://aspn.activestate.com/ASPN/Downloads/Komodo/RemoteDebugging
下載好後j將xdebug.so檔案,拷貝到你的LAMPP檔案夾內,本文中路徑如下:/opt/lampp/lib/php/extensions/
然後開啟php.ini進行編輯,路徑如下/opt/lampp/etc/php.ini
在此檔案倒數第二行加入如下程式碼片段,注意zend_extension和xdebug.profiler_output_dir要對應你的lampp的安裝地址,我這裡紅色高亮。
[XDebug]
zend_extension="/opt/lampp/lib/php/extensions/xdebug.so"
xdebug.remote_enable=true
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.profiler_enable=1
xdebug.profiler_output_dir="/opt/lampp/tmp"
儲存,退出。好,到此,xdebug安裝完成,如果已經開啟xampp了,請重啟。
登入http://localhost/xampp ,點左側邊欄的phpinfo() ,尋找“xdebug”關鍵字,如果有xdebug的詳細資料,說明安裝成功。
這裡有個小問題:官站說明文檔中介紹:http://www.xdebug.org/docs/install#configure-php
add the following line to php.ini: zend_extension="/wherever/you/put/it/xdebug.so" (for non-threaded use of PHP, for example the CLI, CGI or Apache 1.3 module)
or: zend_extension_ts="/wherever/you/put/it/xdebug.so" (for threaded usage of PHP, for example the Apache 2 work MPM or the the ISAPI module).
雖然我的XAMPP中的apache版本是2.2.11,但是使用zend_extension_ts語句是無法載入xdebug的,請讀者自行測試,如果zend_extension_ts不能載入,那麼和我一樣請用zend_extension。
開啟Eclipse,在裡面設定xdebug,
window->preferences->PHP->Debug,
PHP Debugger 選擇 Xdebug
Server 選擇 php Default Web Server,
php Executalbe 點進去之後按Add, 在Executable Path按Browse,選擇/opt/lampp/bin/php-5.2.8 ,php ini檔案路徑在/opt/lampp/etc/php.ini ,名字嘛,隨便給個就好,叫php吧,php debuger選擇XDebug ,點ok
同樣是在preferences裡,點general,web browser ,點new ,指定下外部的Firefox瀏覽器地址:/usr/bin/firefox
下面添加一個php檔案測試下是否成功。建立一個名為first的php project,在此project裡建立一個php file,名字也叫first.php,點next,試用而已,所以選擇new simple php file ,
填入下列代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>Basic PHP Page</title>
</head>
<body>
<p>This is standard HTML.</p>
</body>
</html>
儲存,然後右擊first.php, properties ,Run/Debug Settings ,點new ,選擇php web server。
名稱:first
server debugger :XDebug
PHP Server :Default。。。。。。
File一欄輸入建立的PHP項目的相對路徑,如果項目的絕對路徑是/opt/lampp/htdocs/first/first.php,那麼此欄只輸入/first/first.php
URL勾選auto generate就是。
點apply應用。
OK,右擊first.php,run as PHP Web Page 看看成果。正常情況下應該是自動開啟一個Firefox視窗,地址是http://localhost/first/first.php ,頁面內容是:This is standard HTML. 想試試debug也一樣,debug as PHP Web Page ,此時會提醒你是否切換到debug視角,點yes ,進入debug模式,用過別的IDE的應該很熟悉。想再換回PHP編輯視角,點右上方的PHP 表徵圖的perspective就回來了。
以下作者和網站對本文完成有協助:
http://blog.sina.com.cn/s/blog_4dda073c0100bikk.html
http://www.ibm.com/developerworks/cn/linux/l-xampp/
http://www.latenightpc.com/blog/archives/2008/05/24/a-complete-lamp-development-environment-xampp-eclipse-pdt-and-xdebug