Mac下安装配置PhpStorm开发环境

参考:# macOS下安装配置PhpStorm

下载PhpStorm:官方下载地址

PhpStorm的安装过程略

配置php开发环境

默认mac中都是自带php,apache,PHP在目录/usr/bin/php中


image.png

配置Apache

sudo apachectl start     //开启Apache
sudo apachectl restart   //重启Apache
sudo apachectl stop   //停止Apache

apache默认站点根目录为:/Library/WebServer/Documents
配置文件:/etc/apache2/httpd.conf

加载php

文本编辑器或者vim打开httpd.conf
搜索LoadModule php7_module libexec/apache2/libphp7.so,将前面#号去掉。


image.png

调整目录权限

sudo chmod -R 777 /Library/WebServer/Documents

配置PHP

略...
注意:xcdebug.so默认是在/usr/lib/php/extensions/目录下,但是no-debug-non-zts-20180731版本不尽相同,需要设置成自己系统里的。


image.png

保存后重启apache

sudo apachectl restart

使用Phpstorm

工程需要创建在/Library/WebServer/Documents/下面


image.png

可以将工程目录放在左侧的快捷导航中


image.png

配置Phpstorm

在Phpstorm的Preference->Build, Execution, Deployment->Deployment->点+新建, name自定义,我起名叫webroot。 type选择Local or mounted folder。


image.png

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


image.png

因为apache容器的根目录为/Library/WebServer/Documents/,所以在其中填入相对于/Library/WebServer/Documents/的目录名称,即HelloPHP保存。

配置Debug模式

配置安装Xdebug

cd /private/etc/
//默认没有php.ini,需要拷贝一下
sudo cp php.ini.default php.ini
//vi或者编辑器前往后编辑php.ini
sudo open -e /private/etc/php.ini
//底部增加Xdebug配置,用来使PhpStorm有断点调试等功能。
[Xdebug]
#注意:xcdebug.so默认是在/usr/lib/php/extensions/目录下,但是no-debug-non-zts-20180731版本不尽相同,需要设置成自己系统里的。
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设置

首先检查phpstorm的xdebug配置,这里的debug port要和php.ini里面的xdebug.remote_port相一致!默认是9000,如果9000端口被占用的话,可以改成其他端口。


image.png

进入Debug>DBGpProxy,IDE key填PHPSTORM,host填localhost,port 填80


image.png

设置localService


image.png

新建一个server


image.png

设置run、debug自动浏览器打开的开始页面


image.png

启动


image.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。