用Visual Studio Code Debug世界上最好的语言(Mac篇)
首先,你要有台Macbook Pro,接着才继续看这个教程.php
PS:Windows用户看这里用Visual Studio Code Debug世界上最好的语言html
brew 环境准备
见brew.sh,或者mysql
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
PHP7 + nginx + php-fpm + xdebug
PHP7
brew install php@7.1
安装完了以后看下安装路径:nginx
where php; ##➜ ~ where php ## /usr/local/opt/php@7.1/bin/php ## /usr/bin/php
通常php.ini在/usr/local/etc/php/7.1git
ls /usr/local/etc/php/7.1 #conf.d pear.conf php-fpm.conf php-fpm.d php.ini
待会咱们配置xdebug和php-fpm的时候会用到这个这些配置文件的,先跳过github
xdebug安装
原本其实一句brew install php71-xdebug --without-homebrew-php就完事的,谁知道homebrew-php最近被移除了,因此就尴尬了...redis
手动去下载xdebug而后配置吧.下载页面:https://xdebug.org/files/sql
选择本身要安装的版本,我这里选了2.6.macos
# 建立一个你喜欢的路径存放,我放在了~/tool/目录下; mkdir tool; wget https://xdebug.org/files/xdebug-2.6.0.tgz; # 解压 tar xvzf xdebug-2.6.0.tgz; cd xdebug-2.6.0; # 初始化php模块 phpize; # 生成对应的so文件 # ./configure --enable-xdebug --with-php-config=PHP安装路径/bin/php-config; ./configure --enable-xdebug --with-php-config=/usr/local/Cellar/php@7.1/7.1.17/bin/php-config; # 上一步正常执行完毕以后会在xdebug-2.6.0/modules/文件夹下生成xdebug.la和xdebug.so,待会咱们在php.ini中配置xdebug会用到这个文件
安装nginx
brew install nginx
配置nginx.conf
安装完成以后开始配置nginx,首先建立一堆须要用到的文件件.json
mkdir -p /usr/local/var/logs/nginx mkdir -p /usr/local/etc/nginx/sites-available mkdir -p /usr/local/etc/nginx/sites-enabled mkdir -p /usr/local/etc/nginx/conf.d mkdir -p /usr/local/etc/nginx/ssl sudo mkdir -p /var/www sudo chown :staff /var/www sudo chmod 777 /var/www #做者:GQ1994 #连接:https://www.jianshu.com/p/a642ee8eca9a #來源:简书 #著做权归做者全部。商业转载请联系做者得到受权,非商业转载请注明出处。
而后vim /usr/local/etc/nginx/nginx.conf 输入如下内容:
user root wheel; #默认的是nobody会致使403 worker_processes 1; error_log /usr/local/var/logs/nginx/error.log debug; pid /usr/local/var/run/nginx.pid; events { worker_connections 256; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /usr/local/var/logs/access.log main; sendfile on; keepalive_timeout 65; port_in_redirect off; include /usr/local/etc/nginx/sites-enabled/*; }
设置nginx php-fpm配置文件
vim /usr/local/etc/nginx/conf.d/php-fpm 修改成(没有则建立)
#proxy the php scripts to php-fpm location ~ \.php$ { try_files $uri = 404; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_intercept_errors on; include /usr/local/etc/nginx/fastcgi.conf; }
建立默认虚拟主机default
vim /usr/local/etc/nginx/sites-available/default输入:
server { listen 80;#若是80被用了能够换成别的,随你开心 server_name www.qilipet.com admin.qilipet.com; root /var/www/pet/public; access_log /usr/local/var/logs/nginx/default.access.log main; index index.php index.html index.htm; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ /index.php?$query_string; # Uncomment to enable naxsi on this location # include /etc/nginx/naxsi.rules } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
此部份内容基原本自GQ1994:mac下配置php、nginx、mysql、redis
配置php.ini
回到咱们的/usr/local/etc/php/7.1文件夹
在php.ini中加入xdebug配置
[xdebug] ;zend_extension="刚刚的xdebug路径/modules/xdebug.so" zend_extension="~/tool/xdebug-2.6.0/modules/xdebug.so" xdebug.remote_enable = 1 xdebug.remote_autostart = 1 xdebug.remote_connect_back = 1 ;默认的9000已经被php-fpm占用了,切记换一个端口 xdebug.remote_port = 9001 xdebug.scream = 0 xdebug.show_local_vars = 1
重启一下php-fpm和nginx,看一下php是否是都正常跑起来了.
VS Code配置
User Settings配置PHP目录
"php.executablePath": "/usr/local/opt/php@7.1/bin/php"
安装php debug插件
安装完成以后配置一下launch.json
{ // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Listen for XDebug", "type": "php", "request": "launch", "port": 9001 //默认是9000已经被php-fpm占用,上一步咱们配置远程端口是9001 }, { "name": "Launch currently open script", "type": "php", "request": "launch", "program": "${file}", "cwd": "${fileDirname}", "port": 9001 //默认是9000已经被php-fpm占用,上一步咱们配置远程端口是9001 } ] }
而后就愉快debug最好的语言吧!