Building MAC PHP + Xdebug + vscode development environment



I don’t know PHP, but because I need to know PHP code, I learn to build an environment and record it

System: MacOS High Sierra (10.13.6) comes with PHP 7.1 (use PHP – V to view the version)

Company PHP version 5.6, other versions may also apply

Install php5.6

brew install [email protected]

Modify ~ /. Bash after successful installation_ Profile file to make the modification effective (you can also choose to restart the terminal)

export PATH="/usr/local/opt/[email protected]/bin:/usr/local/opt/[email protected]/sbin:$PATH"


Install nginx (installed but omitted)

brew install nginx

Start project

Start nginx and use / usr / local / etc / nginx / nginx.conf

sudo nginx  

Start PHP FPM, – D means running in the background

sudo php-fpm -D 

So the PHP project is running

4. Debugging: Xdebug installation, the focus of this article

Originally, the code can run, but in order to better understand the logic, you need to debug the code. You can install Xdebug by brew install and PECL install to query data, but they are not easy to use. So download it and install it yourself

4.1 download and install Xdebug

Download address:…(choose the right version. My side is PHP 5.6, and the selected version is xdebug-2.5.5

The installation command can also be made manually, but it is troublesome

pecl install xdebug-2.5.5.tgz

Building MAC PHP + Xdebug + vscode development environment

4.2. Modify php.ini

From the screenshot, we can see that php.ini has been updated. Let’s look at the php.ini file (you can know its path through PHP code:<?php echo phpinfo()?>)There is indeed one more:


But at this time, Xdebug did not work. Looking up the data, it said that it must be an absolute path, so it was modified to:

end_extension=/usr/local/Cellar/[email protected]/5.6.37/pecl/20131226/

And add the following configuration:

xdebug.remote_ port=9001 ; Remember that you can't use the default 9000 port to be occupied by FPM

xdebug.profiler_enable = on

xdebug.trace_ output_ dir = "/Users/xxx/work/xdebug" ; Path customization

xdebug.profile_ output_ dir = "/Users/xxx/work/xdebug" ; Path customization

xdebug.remote_enable = 1

xdebug.remote_autostart = 1

xdebug.remote_host = "localhost"

Start PHP execution<?php echo phpinfo()?>See that Xdebug has been added successfully

Building MAC PHP + Xdebug + vscode development environment

4.3vscode configure Xdebug plug in

Search php debug, install and restart, select debug interface to configure, and start listen for Xdebug to listen
Building MAC PHP + Xdebug + vscode development environment