下載PhpStorm:官方下載地址
PhpStorm的安裝過程略
配置php開發(fā)環(huán)境
默認(rèn)mac中都是自帶php,apache,PHP在目錄/usr/bin/php中

配置Apache
sudo apachectl start //開啟Apache
sudo apachectl restart //重啟Apache
sudo apachectl stop //停止Apache
apache默認(rèn)站點(diǎn)根目錄為:/Library/WebServer/Documents
配置文件:/etc/apache2/httpd.conf
加載php
文本編輯器或者vim打開httpd.conf
搜索LoadModule php7_module libexec/apache2/libphp7.so,將前面#號去掉。

調(diào)整目錄權(quán)限
sudo chmod -R 777 /Library/WebServer/Documents
配置PHP
略...
注意:xcdebug.so默認(rèn)是在/usr/lib/php/extensions/目錄下,但是no-debug-non-zts-20180731版本不盡相同,需要設(shè)置成自己系統(tǒng)里的。

保存后重啟apache
sudo apachectl restart
使用Phpstorm
工程需要創(chuàng)建在/Library/WebServer/Documents/下面

可以將工程目錄放在左側(cè)的快捷導(dǎo)航中

配置Phpstorm
在Phpstorm的Preference->Build, Execution, Deployment->Deployment->點(diǎn)+新建, name自定義,我起名叫webroot。 type選擇Local or mounted folder。

Mappings中,我們看到local path為我們新建的php目錄地址,web path on server 'webroot' (relative to folder).

因?yàn)閍pache容器的根目錄為/Library/WebServer/Documents/,所以在其中填入相對于/Library/WebServer/Documents/的目錄名稱,即HelloPHP保存。
配置Debug模式
配置安裝Xdebug
cd /private/etc/
//默認(rèn)沒有php.ini,需要拷貝一下
sudo cp php.ini.default php.ini
//vi或者編輯器前往后編輯php.ini
sudo open -e /private/etc/php.ini
//底部增加Xdebug配置,用來使PhpStorm有斷點(diǎn)調(diào)試等功能。
[Xdebug]
#注意:xcdebug.so默認(rèn)是在/usr/lib/php/extensions/目錄下,但是no-debug-non-zts-20180731版本不盡相同,需要設(shè)置成自己系統(tǒng)里的。
zend_extension="/usr/lib/php/extensions/no-debug-non-zts-201807316/xdebug.so"
xdebug.remote_enable = on
;xdebug.remote_handler=dbgp
xdebug.remote_host="127.0.0.1"
xdebug.remote_port=9000
xdebug.profiler_enable = 1
xdebug.profiler_enable_trigger = off
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.remote_autostart = on
PHPSTORM設(shè)置
首先檢查phpstorm的xdebug配置,這里的debug port要和php.ini里面的xdebug.remote_port相一致!默認(rèn)是9000,如果9000端口被占用的話,可以改成其他端口。

進(jìn)入Debug>DBGpProxy,IDE key填PHPSTORM,host填localhost,port 填80

設(shè)置localService

新建一個server

設(shè)置run、debug自動瀏覽器打開的開始頁面

啟動
