[Intellij IDEA] 建置PHP開發環境
開發環境:
Intellij IDEA 13.1.4 ⇒ http://www.jetbrains.com/?fromIDE
XAMPP 1.8.2 ⇒ https://www.apachefriends.org/zh_tw/index.html
看到這有人就會懷疑,為什麼不用 XAMPP 1.8.3?
因為目前使用的 Intellij IDEA 支援到的是 PHP 5.4 的版本
要建置 PHP 開發環境時,首先要確定您的 IDE 有沒有安裝支援
的 Plugin(如下圖),沒有的話請先下載完成再接著下一步。
然後確認您的 XAMPP 1.8.2 已經下載完畢,並且已安裝好。
1.8.2 的下載網址:http://goo.gl/kU6NPP
接著進到 File -> Settings → PHP 中
選擇 PHP language level 到 5.4
接著設定 Interpreter
Interpreter 設定畫面: 將PHP Home 指向 XAMPP 的 PHP 目錄
注意若要開啟Xdebug,需去 php 的安裝目錄中找尋 php.ini 的檔案,
並修改當中的配置(如下圖)
搜尋關鍵字: zend_extension
您應該會找到如下內容,將 ; 消除(表示開啟)
zend_extension = "C:\xampp\php\ext\php_xdebug.dll"
;xdebug.profiler_append = 0
;xdebug.profiler_enable = 1
;xdebug.profiler_enable_trigger = 0
;xdebug.profiler_output_dir = "C:\xampp\tmp"
;xdebug.profiler_output_name = "cachegrind.out.%t-%s"
xdebug.remote_enable = 1
xdebug.remote_handler = "dbgp"
xdebug.remote_host = "127.0.0.1"
;xdebug.trace_output_dir = "C:\xampp\tmp"
完成上述步驟之後,算是第一階段完成。
接著要做的是 Run/Debug Configurations
請新增一個 PHP Built-in Web Server
接著進入設定相關資訊:
筆者的測試環境在 localhost
目前的專案目錄是D:\TestProIntel\TestPHP_001
最後要是想要完成自動部屬作業的話,可以進入專案設定 Deployment
設定畫面(1)
設定畫面(2)
好了,接著隨便新增一個 php 的檔案,內容打
<?php
echo "Hollo world";
?>
點選瀏覽器預覽按鈕:
若是設定及安裝過程完全無誤,您應該會在瀏覽器看到
熟悉不過的 Hello World 字眼。
上面更正一下 直接點及瀏覽器的按鈕為使用Intellij Idea 的 php 環境去執行,非我們在 Run/Debug Configurations 所設定的地方,應該改成自己在瀏覽器輸入 localhost/PHP檔名 即可。
原文網址:http://kuoshenghsu.blogspot.tw/2014/09/intellij-idea-php.html
參考資料:
Getting Xdebug to work with Apache/XAMPP to debug PHP
How to Configure XDebug in XAMPP (1.7.2/Later) on Windows
Installing and configuring XAMPP
IntelliJ IDEA13 PHP開発環境設定メモ
第一支PHP網頁程式
http://php.adabo4.com/cls/s/17