[PHP] php, apache, VS Code安裝與配置
1. 下載
?? | ?? |
---|---|
VS Code | https://go.microsoft.com/fwlink/?Linkid=852157 |
apache2.4.33 | https://www.apachelounge.com/download/VC14/binaries/httpd-2.4.33-win32-VC14.zip |
php7.1.19 | https://windows.php.net/downloads/releases/php-7.1.19-Win32-VC14-x86.zip |
vc_redist.x86 | https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x86.exe |
可以下載不同的apache和php版本,註意Win32和VC14這兩部分要一致
https://www.apachelounge.com/download/
https://windows.php.net/download/
2. 安裝
2.1 php
將php-7.1.19-Win32-VC14-x86.zip
解壓到C盤(其他盤也可以),並改文件夾名為php
將C:\php;C:\Apache24\bin;
添加到環境變量
打開C:\php
, 將php.ini-development
或php.ini-production
重命名為php.ini
2.2 apache
將httpd-2.4.33-win32-VC14.zip
修改配置文件
"C:\Apache24\conf\httpd.conf"
"C:\Apache24\conf\httpd.conf"
取消ServerName www.example.com:80
的註釋,並改成ServerName localhost:80
確保以下配置的路徑正確
DocumentRoot "c:/Apache24/htdocs" <Directory "c:/Apache24/htdocs"> ScriptAlias /cgi-bin/ "c:/Apache24/cgi-bin/" <Directory "c:/Apache24/cgi-bin">
添加
LoadModule php7_module C:\php\php7apache2_4.dll
PHPIniDir "C:\php\php.ini"
AddType application/x-httpd-php .php .pap .phtml
雙擊httpd.exe
瀏覽器打開127.0.0.1
,出現it works!
說明apache正常運行
安裝服務
C:\Apache24\bin> httpd -k install -n "Apache"
- 刪除服務(管理員模式,兩種方方法)
sc delete service_name
httpd -k uninstall -n "Apache"
- 啟動和關閉服務
net start Apache
net stop Apache
2.3 VS Code
1.安裝插件PHP Debug
, PHP IntelliSense
2.File->Preference->Settings
修改這三項, php的路徑修改為自己的路徑
"php.executablePath": "c:/php/php.exe",
"php.validate.executablePath": "c:/php/php.exe",
"php.suggest.basic": false,
3.安裝XDebug
https://xdebug.org/files/php_xdebug-2.6.0-7.1-vc14.dll
將下載下來的dll扔到c:/php/ext
中
修改php.ini
[xdebug]
zend_extension = "C:\php\ext\php_xdebug-2.6.0-7.1-vc14.dll"
xdebug.remote_enable = On
;啟用性能檢測分析
;xdebug.profiler_enable = On
;啟用代碼自動跟蹤
xdebug.auto_trace=On
xdebug.profiler_enable_trigger = On
xdebug.profiler_output_name = cachegrind.out.%t.%p
;指定性能分析文件的存放目錄
;xdebug.profiler_output_dir ="C:/wamp64/tmp"
xdebug.show_local_vars=0
;配置端口和監聽的域名
xdebug.remote_port=9000
xdebug.remote_host="localhost"
第一次運行項目的時候選擇PHP
會出現Listen for XDebug
,
Launch currently open script
兩種運行方式,選擇Listen for XDebug
就可以進行調試了
調試的時候如果無法命中斷點,應該想想此斷點處的代碼是否會被執行到
[PHP] php, apache, VS Code安裝與配置