macOS 配置 PHP 开发环境
基于 macOS Catalina Version 10.15.3
使用 brew 安装 PHP、composer 和 php-code-sniffer
brew install php
brew install php-code-sniffer
brew install composer
安装 mongodb 扩展
pecl install mongodb
PhpStorm 基本配置
自动添加文末空白行
PhpStorm --> Preferences --> Editor --> General --> Ensure line feed at file end on Save
PhpStorm 字体修改
PhpStorm --> Preferences --> Editor --> Font --> JetBrains Mono
PhpStorm 显示空格和 tab
PhpStorm --> Preferences --> Editor --> General --> Appearance --> Show whitespaces
PhpStorm 配置 Code Sniffer
PhpStorm --> Preferences --> Languages & Frameworks --> PHP --> Quality Tools --> PHP_CodeSniffer
phpcs 路径为:/usr/local/Cellar/php-code-sniffer/3.5.4/bin/phpcs
phpcbf 路径为:/usr/local/Cellar/php-code-sniffer/3.5.4/bin/phpcbf
PhpStorm --> Preferences --> Editor --> Inspections --> Quality Tools --> PHP_CodeSniffer validation
PhpStorm 配置 xdebug
安装 xdebug
pecl install xdebug
配置 PhpStorm
PhpStorm --> Preferences --> Language & Frameworks --> PHP --> CLI Interpreter --> path_to_php
点击 Open in Editor
去除
zend_extension=<path_to_zend_debugger>
zend_extension=<path_to_zend_optimizer>
添加
[xdebug]
zend_extension = "<path to xdebug extension>"
xdebug.remote_enable = 1
xdebug.remote_port = "<the port for Xdebug to listen to>" (the default port is 9000)
xdebug.remote_host = localhost
xdebug.remote_mode = "req"
xdebug.remote_handler = "dbgp"
xdebug.idekey = "PHPSTORM"
xdebug.remote_autostart = 1
确保有且仅有一个 zend_extension = "<path to xdebug extension>"
php --version
看到 Xdebug 信息则说明 Xdebug 安装成功
配置 PhpStorm 中的 Xdebug
PhpStorm --> Preferences --> Language & Frameworks --> PHP --> Debug
配置相关信息,其中 Debug port 应与 php.ini 中一致
配置 PhpStorm 中的 DBGp Proxy
PhpStorm --> Preferences --> Language & Frameworks --> PHP --> Debug --> DBGp Proxy 填写与项目监听相同的 Host 和 Port, IDE key 应与 php.ini 中一致
添加 Run/Debug Configurations
选择 PHP Built-in Web Server
设置端口后启动即可
根据 Listening for PHP Debug Connections 的启动状态即可启动调试功能
Address already in use
lsof -i:PORT
kill -9 pid