Home Backend Development PHP7 How to add Xdebug to macOS PHP7

How to add Xdebug to macOS PHP7

Dec 21, 2021 pm 04:53 PM
macos php7

MacOS system PHP7 adds Xdebug

After Apple released macOS High Sierra, the system finally came with php v7.1. Compared with before, if you want to use For php7, you have to find an additional way (Homebrew or php-osx), which is really convenient.

However, the PHP that comes with the system only has basic configurations. If you want to develop PHP, Xdebug is still necessary. Here is a summary of how to add the Xdebug module to the PHP that comes with the system in macOS High Sierra. [Recommended: PHP7 tutorial]

Basic environment (macOS and PHP information)

    ##macOS High Sierra: v10.13.3
  • PHP: v7.1.7

Installing Xdebug

Xdebug official website installation documentation has MAC recommended methods, since the system comes with PHP It is

v7.1.7, so when selecting, you need to select the installation package php71-xdebug.

How to add Xdebug to macOS PHP7

In addition, since

php71-xdebug in brew depends on php71, it is recommended to add --without -homebrew-phpThis parameter, brew will ignore the installation of php71.

brew install php71-xdebug --without-homebrew-php
Copy after login
Copy after login
But at this time, you may encounter the following error:

phpize
grep: /usr/include/php/main/php.h: No such file or directory
grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:
Copy after login
prompts that dependencies are missing, causing

phpize to not work properly, phpize is used to prepare the compilation environment of the PHP extension library. In theory, the PHP that comes with the system should have phpize, but it is not in /usr/include/php/* The module it needs is found inside, and when searching /usr/include, it is found that this directory does not exist at all.

Googling around, to solve the problem, you need to complete the relevant content in

/usr/include. In systems before OSX v10.10, you need to manually create a soft link to solve the problem:

sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include /usr/include
Copy after login
But the system after v10.11 has rewritten the security policy, so you will encounter permission problems (

sudo will not work):

ln: /usr/include: Operation not permitted
Copy after login
But fortunately, Apple has Developers have prepared Xcode, which is a very powerful tool, but it is also very large (downloading and installation is a bit slow), and generally we only need the

Command Line Tools it provides. The above problems , in fact, it can be solved as long as you install Command Line Tools:

xcode-select --install
Copy after login
Next, follow the prompts, install and agree to the agreement...


How to add Xdebug to macOS PHP7

After the installation is completed, use

brew to install php71-xdebug:

brew install php71-xdebug --without-homebrew-php
Copy after login
Copy after login
After everything is completed, brew will give a prompt:

To finish installing xdebug for PHP 7.1:
  * /usr/local/etc/php/7.1/conf.d/ext-xdebug.ini was created,
    do not forget to remove it upon extension removal.
  * Validate installation via one of the following methods:
  *
  * Using PHP from a webserver:
  * - Restart your webserver.
  * - Write a PHP page that calls "phpinfo();"
  * - Load it in a browser and look for the info on the xdebug module.
  * - If you see it, you have been successful!
  *
  * Using PHP from the command line:
  * - Run `php -i "(command-line 'phpinfo()')"`
  * - Look for the info on the xdebug module.
  * - If you see it, you have been successful!
Copy after login

Enable Xdebug for PHP

After the above steps, there is Xdebug in the system, but it may not be in the

php.ini configuration file, so Xdebug needs to be added manually Configuration items:

[xdebug]
zend_extension="/usr/local/opt/php71-xdebug/xdebug.so"
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 1
xdebug.remote_port = 9000
xdebug.scream = 0
xdebug.show_local_vars = 1
Copy after login
Then restart

php-fpm:

# 关闭php-fpm
sudo killall php-fpm

# 启动php-fpm
sudo php-fpm
Copy after login
Run

php -i "(command-line 'phpinfo()')" | grep xdebug, you can see the configuration content of Xdebug:

xdebug
...
xdebug.remote_autostart => On => On
xdebug.remote_connect_back => On => On
xdebug.remote_cookie_expire_time => 3600 => 3600
xdebug.remote_enable => On => On
xdebug.remote_handler => dbgp => dbgp
xdebug.remote_host => localhost => localhost
xdebug.remote_log => no value => no value
xdebug.remote_mode => req => req
xdebug.remote_port => 9000 => 9000
xdebug.remote_timeout => 200 => 200
xdebug.scream => Off => Off
...
Copy after login

Visual Studio Code - PHP Debug

VSCode is currently the most popular One of the development tools, although lightweight, it is not inferior to all kinds of IDEs. It is Microsoft's conscience work. Its capabilities can be expanded by installing different plug-ins. Among them is the

PHP Debug plug-in. It can be used as a bridge to Xdebug to facilitate debugging PHP directly through Xdebug. The official description is very appropriate:

PHP Debug Adapter for Visual Studio Code
The guidance on the official website is also quite good:

  1. Install XDebug


    I highly recommend you make a simple test.php file, put a phpinfo(); statement in there, then copy the output and paste it into the XDebug installation wizard. It will analyze it and give you tailored installation instructions for your environment.In short:

      On Windows: Download the appropiate precompiled DLL for your PHP version, architecture (64/32 Bit), thread safety (TS/NTS) and Visual Studio compiler version and place it in your PHP extension folder.
    • On Linux: Either download the source code as a tarball or clone it with git, then compile it.
    ##Configure PHP to use XDebug by adding
  2. zend_extension=path/ to/xdebug
  3. to your php.ini.The path of your php.ini is shown in your phpinfo()
    output under "Loaded Configuration File".
  4. Enable remote debugging in your php.ini:
  5. [XDebug]
    xdebug.remote_enable = 1
    xdebug.remote_autostart = 1
    Copy after login

    There are other ways to tell XDebug to connect to a remote debugger than remote_autostart, like cookies, query parameters or browser extensions. I recommend remote_autostart because it "just works". There are also a variety of other options, like the port (by default 9000), please see the XDebug documentation on remote debugging for more information.

  6. If you are doing web development, don't forget to restart your webserver to reload the settings
  7. Verify your installation by checking your phpinfo() output for an XDebug section.

这里需要注意的是它推荐开启Xdebug配置项中的remote_autostart这一项。

好了,经过上面的操作,你应该可以跟Demo里面一样在VSCode中调试PHP了。
How to add Xdebug to macOS PHP7

The above is the detailed content of How to add Xdebug to macOS PHP7. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

How to restart the apache server How to restart the apache server Apr 13, 2025 pm 01:12 PM

To restart the Apache server, follow these steps: Linux/macOS: Run sudo systemctl restart apache2. Windows: Run net stop Apache2.4 and then net start Apache2.4. Run netstat -a | findstr 80 to check the server status.

vscode terminal usage tutorial vscode terminal usage tutorial Apr 15, 2025 pm 10:09 PM

vscode built-in terminal is a development tool that allows running commands and scripts within the editor to simplify the development process. How to use vscode terminal: Open the terminal with the shortcut key (Ctrl/Cmd). Enter a command or run the script. Use hotkeys (such as Ctrl L to clear the terminal). Change the working directory (such as the cd command). Advanced features include debug mode, automatic code snippet completion, and interactive command history.

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

Where to write code in vscode Where to write code in vscode Apr 15, 2025 pm 09:54 PM

Writing code in Visual Studio Code (VSCode) is simple and easy to use. Just install VSCode, create a project, select a language, create a file, write code, save and run it. The advantages of VSCode include cross-platform, free and open source, powerful features, rich extensions, and lightweight and fast.

Can vscode be used for mac Can vscode be used for mac Apr 15, 2025 pm 07:36 PM

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

vscode terminal command cannot be used vscode terminal command cannot be used Apr 15, 2025 pm 10:03 PM

Causes and solutions for the VS Code terminal commands not available: The necessary tools are not installed (Windows: WSL; macOS: Xcode command line tools) Path configuration is wrong (add executable files to PATH environment variables) Permission issues (run VS Code as administrator) Firewall or proxy restrictions (check settings, unrestrictions) Terminal settings are incorrect (enable use of external terminals) VS Code installation is corrupt (reinstall or update) Terminal configuration is incompatible (try different terminal types or commands) Specific environment variables are missing (set necessary environment variables)

See all articles