Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to add Xdebug to macOS PHP7

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to increase Xdebug in macOS PHP7". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to add Xdebug to macOS PHP7"!

MacOS system PHP7 adds Xdebug

After Apple released macOS High Sierra, the system finally came with php v7.1, which is much more convenient than before if you want to use php7, you have to think of something else (Homebrew or php-osx).

However, the system comes with PHP only basic configuration, if you want to do PHP development, Xdebug is still necessary, here is a summary of how to add Xdebug modules to the system's own PHP in macOS High Sierra. [recommended: PHP7 tutorial]

Underlying environment (macOS and PHP information)

MacOS High Sierra: v10.13.3

PHP: v7.1.7

Install Xdebug

The installation document of Xdebug official website has the method recommended by MAC. In view of the fact that the system comes with PHP v7.1.7, you need to choose php71-xdebug as the installation package.

In addition, because the php71-xdebug in brew depends on php71, it is recommended to add the parameter-- without-homebrew-php, so that brew will ignore the installation of php71.

Brew install php71-xdebug-without-homebrew-php

But at this time, you may encounter an error like this:

Phpizegrep: / usr/include/php/main/php.h: No such file or directorygrep: / usr/include/php/Zend/zend_modules.h: No such file or directorygrep: / usr/include/php/Zend/zend_extensions.h: No such file or directoryConfiguring for:PHP Api Version:Zend Module Api No:Zend Extension Api No:

It is suggested that phpize cannot work properly because of the lack of dependencies. Phpize is used to prepare the compilation environment of the PHP extension library. Theoretically, the PHP that comes with the system should have phpize, but the module it needs is not found in / usr/include/php/*, and when searching / usr/include, it is found that this directory does not exist at all.

After a circle of Google, to solve the problem, you need to complete the relevant content in / usr/include. Before OSX v10.10, the system needs to manually do soft chain to solve the problem:

Sudo ln-s / Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include / usr/include

However, systems after v10.11 rewrite the security policy, so they will encounter permission issues (not even sudo):

Ln: / usr/include: Operation not permitted

Fortunately, Apple has prepared Xcode for developers, which is a very powerful tool, but it is also very large (download and installation is a bit slow). Generally speaking, we only need the Command Line Tools provided by it. In fact, the above problems can be solved by installing Command Line Tools:

Xcode-select-install

Next, follow the prompts to install and agree to the agreement.

Wait until the installation is complete, then use brew to install php71-xdebug:

Brew install php71-xdebug-without-homebrew-php

When it's over, brew will give you a hint:

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!

Open the Xdebug of PHP

After the above steps, there is Xdebug in the system, but not necessarily in the php.ini configuration file, so you need to manually add the configuration items for Xdebug:

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

Then restart php-fpm:

# close php-fpmsudo killall php-fpm# and start php-fpmsudo php-fpm

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

Xdebug...xdebug.remote_autostart = > On = > Onxdebug.remote_connect_back = > On = > Onxdebug.remote_cookie_expire_time = > Onxdebug.remote_cookie_expire_time = > 3600xdebug.remote_enable = > On = > Onxdebug.remote_handler = > dbgp = > dbgpxdebug.remote_host = > localhost = > localhostxdebug.remote_log = > no value = > no valuexdebug.remote_mode = > req = > reqxdebug.remote_port = > 9000 = > 9000xdebug.remote_timeout = > 200xdebug.scream = > Off = > Off...

Visual Studio Code-PHP Debug

VSCode is one of the most popular development tools at present, although it is lightweight, it is not inferior to all kinds of IDE. Microsoft works of conscience, it can expand its capabilities by installing different plug-ins, including a plug-in for PHP Debug, which can be used as a bridge for Xdebug to debug 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:

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 (64amp 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 zend_extension=path/to/xdebug to your php.ini.

The path of your php.ini is shown in your phpinfo () output under "Loaded Configuration File".

Enable remote debugging in your php.ini:

[XDebug] xdebug.remote_enable = 1xdebug.remote_autostart = 1

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.

If you are doing web development, don't forget to restart your webserver to reload the settings

Verify your installation by checking your phpinfo () output for an XDebug section.

It should be noted here that it is recommended to enable remote_autostart in the Xdebug configuration item.

Well, after the above operation, you should be able to debug PHP in VSCode as in Demo.

At this point, I believe you have a deeper understanding of "macOS PHP7 how to increase Xdebug". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report