編碼的世界 / 優質文選 / 文明

intellij idea12 搭建php開發環境


2021年10月04日
-   

1.安裝php
   這裏選擇php5.4 ts版本,官網源:VC9 x86 Thread Safe (2013-Oct-17 00:26:18)
   原因有兩點:
好像只有ts版本的才有apache的php擴展php5apache2_2.dll,這樣才能讓apache認識php腳本。
沒有用5.5版本的原因是xDebug(php調試)需要和php版本對應,但它的最高版本只支持到5.4。
  解壓至:D:phpphp-5.4.21-Win32-VC9-x86
  將其目錄下的php.ini-development文件複制成php.ini
2.安裝,配置apache
  官網源: httpd-2.2.25-win32-x86-no_ssl.msi
  安裝時注意選擇custom模式,目錄設置為:D:phpApache2.2,安裝內容在根結點上右鍵->this feature and all subfeatures, will be installed on local hard drive.我是怕出錯才全部安裝的,估計默認就好。另外若80端口沖突修改之。
  打開apache2.2目錄下的conf下的httpd.conf,將如下內容粘貼進去保存
Include conf/extra/httpd-vhosts.conf
AddType application/x-httpd-php .php
LoadModule php5_module "D:/php/php-5.4.21-Win32-VC9-x86/php5apache2_2.dll"
PHPIniDir "D:/php/php-5.4.21-Win32-VC9-x86/php.ini"

第一行是包含虛擬主機目錄,可以理解為一個虛擬主機對應一個項目
後三行都為apache添加php支持的
再打開conf下的extra下的httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin txl@ysjjovo.com
DocumentRoot F:/php/demo
ServerName ysjjovo.com
ErrorLog logs/demo-error.log
CustomLog logs/demo-access.log common
DirectoryIndex index.php index.html
</VirtualHost>

  第一行隨便填,第二行是你的php項目目錄,第三行是你的項目對應的域名,四五行是日志,最後一行是配置首頁 index.php
  打開apache2.2目錄下的bin目錄裏的ApacheMonitor.exe,在右下角可以看到apche的小圖標,單擊->apache2.2->Restart,重啟生效!
  打開hosts(%SystemRoot%system32driversetchosts)文件添加IP域名映射
127.0.0.1 ysjjovo.com
  打開intellij idea的設置->plugins->browse repositories輸入php
  file->new project->web module,選擇項目目錄為F:/php,名稱為demo,完成。(好像是沒有php的項目)
  在stackOverFlow裏有說明:http://stackoverflow.com/questions/3784007/how-to-create-a-php-project-with-intellij-idea-9
  在項目根目錄下建立一個index.php,內容如下
<?php phpinfo();?>

  保存,此時瀏覽器鍵入ysjjovo.com已經可以看到到php的配置,若看不到則php配置不正常,請解決後進入下一步
3.xdebug調試器配置
  官網源:PHP 5.4 VC9 TS (32 bit)
  本來想用64位的,但是php官網好像只提供了windows32位的,然後apache好像是也>_<
  下載後放在:D:phpphp_xdebug-2.2.3-5.4-vc9.dll
  編輯php.ini添加xdebug模塊的配置,將如下內容粘貼進去
;xdebug模塊路徑
zend_extension="d:/php/php_xdebug-2.2.3-5.4-vc9.dll"
[xdebug]
xdebug.remote_enable=on
xdebug.remote_host=localhost
xdebug.remote_port=9000
;下面兩項和Intellij idea裏的對應
xdebug.idekey=idekey
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
;下面這句很關鍵,不設置intellij idea無法調試
xdebug.remote_autostart=1
;調試配置,詳細的可以參考phpinfo頁面進行配置
xdebug.auto_trace=on
xdebug.collect_params=on
xdebug.collect_return=on
xdebug.trace_output_dir="../xdebug"
xdebug.profiler_enable=on
xdebug.profiler_output_dir="../xdebug"
xdebug.collect_vars=on
xdebug.cli_color=on

  在D:php下建立xdebug文件夾用於存儲調試信息
  重啟apache生效
  打開intellij idea的設置->php
  php language level->5.4
  添加php interpreters指向php的主目錄,點擊這邊的show info按鈕,在Loaded extensions裏應該可以看到xDebug,
  若沒看到xdebug模塊說明沒配置成功,請檢查php.ini的xdebug的配置,可能是中文的引號之類導致的。
  php->servers
  添加name為:ysjjovo.com port為:80 Debugger為XDebug的服務器。
  點擊intellij idea工具欄裏的 start listen php debug connections.開啟調試模式。
  點擊工具欄裏向下的小三角->edit configuration->add new configuartion->php web Application Server裏選ysjjovo.com
  點擊工具欄裏的綠色向右三角運行配置好的默認頁面,點擊右邊的的debug按鈕調試默認頁面(只有加斷點的情況才會暫停程序)。
  此時頁面的地址如:http://ysjjovo.com/index.php?XDEBUG_SESSION_START=17181
  後面的參數是授權的終端ID,每次調試隨機產生。其實去掉後面的參數也可以訪問。因為默認的配置是允許的。

熱門文章