首先,你要有臺Macbook Pro,接着才繼續看這個教程.php
PS:Windows用戶看這裏用Visual Studio Code Debug世界上最好的語言html
見brew.sh,或者mysql
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
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
原本其實一句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會用到這個文件
brew install nginx
安裝完成以後開始配置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/*; }
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; }
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
回到咱們的/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是否是都正常跑起來了.
"php.executablePath": "/usr/local/opt/php@7.1/bin/php"
安裝完成以後配置一下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最好的語言吧!