Verification: a143cc29221c9be0

Netbeans php xdebug php ini

Netbeans php xdebug php ini

Daniel Opitz

03 Dec 2020

Requirements

  • XAMPP for Windows: https://www.apachefriends.org/download.html
  • Microsoft Visual C++ Redistributable for Visual Studio 2015-2019

Setup

  • Download Xdebug for the specific PHP version:
    • PHP 8.0 (64-Bit): https://xdebug.org/files/php_xdebug-3.0.0-8.0-vs16-x86_64.dll
  • Move the downloaded dll file to: C:\xampp\php\ext
  • Rename the dll file to: php_xdebug.dll
  • Open the file C:\xampp\php\php.ini with Notepad++
  • Disable output buffering: output_buffering = Off
  • Scroll down to the [XDebug] section (or create it) and copy/paste these lines:
[XDebug]
zend_extension=xdebug
xdebug.mode=debug
xdebug.start_with_request=yes
  • Restart Apache

PhpStorm

  • Enable the Xdebug option: “Can accept external connections” and “Additionally listen on Xdebug 3 default port 9003”. Screenshot
  • Use the PhpStorm bookmarklets generator to activate Xdebug from the browser side.

Netbeans

  • Change the Netbeans debugging options: Screenshot

Visual Studio Code

  • Installing XDebug on anything for VSCode in 5 minutes
  • Install the PHP Debug Adapter for Visual Studio Code.
  • Debug PHP In VSCode With XDebug

Postman

Add XDEBUG_SESSION_START=PHPSTORM as query parameter to the url, e.g.

  • http://localhost?XDEBUG_SESSION_START=PHPSTORM

Start debugger from the console

Enter cmd:

set XDEBUG_CONFIG="idekey=xdebug"
php test.php

Download & installation

Download & installation of Xdebug is done by the following command:

pecl install xdebug

Configuration

To "tell" your Apache web server about it, append to /etc/php5/apache2/php.ini file (this location may vary under other distributions) the following lines:

zend_extension="/etc/php5/xdebug/xdebug.so" ; make sure this path exists in your filesystem. If not, find xdebug.so file and put its path here
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.idekey="netbeans-xdebug"

Open Netbeans and navigate to Tools --> Options --> PHP --> Debugging. Make sure the "Debugger port" & "Session ID" configuration values match the values of "xdebug.remote_port" and "xdebug.idekey" from the Apache php.ini file, respectively. In our example we set them to "9000" & "netbeans-xdebug".

Also, in your project properties select "Run Configurations" And make sure your project url is set in the right field.

Set some breakpoint at an interest point in your code by clicking on the line number in NetBeans.

Restart the Apache web server:

 sudo service apache2 restart

If you wish to be able to debug your project via the command line, add to /etc/php5/cli/php.ini file the same lines you added to /etc/php5/apache2/php.ini, and run the following commands:

sh -c "echo 'export XDEBUG_CONFIG=\"idekey=netbeans-xdebug\"' >> /etc/profile"
source /etc/profile

All that's left on NetBeans is to navigate to Debug --> Debug Project. Now you can go to your project by surfing to it using the browser or by running the specific php file in the command line. Notice your breakpoint should then hit.

1. Remote server configuration

1.1, install xdebug

1.1.1, download

[[email protected] ~]

1.1.2, unzipped

[[email protected] ~]

1.1.3, installation

[[email protected] ~]
[[email protected] xdebug-2.9.7]
[[email protected] xdebug-2.9.7]
[[email protected] xdebug-2.9.7]

1.2, configure pHP.ini

[[email protected] ~]
  • The file is not tail plus the following code
[XDebug]
zend_extension = /usr/local/webserver/php/lib/php/extensions/no-debug-zts-20180731/xdebug.so

;Allows remote to be ON or 1  Both express, OFF and 0  Referring to close closing
xdebug.remote_enable=1

;IP of the remote host We are filled in, fixed 127.0.0.1 
xdebug.remote_host = 192.168.31.232

;Remember this port after debugging the connection port and will be used. This configuration item defaults to 9000  Usually 9000  The port is occupied by FPM, so the port is replaced.
;Also, please open this port in your server's control panel and server firewall.
;If you are a pagoda panel, please release this port.
xdebug.remote_port = 9079

;The next value is optional, but I recommend you to use
;Key to connect IDE, remember him, you can customize yourself, mainly used to filter the request.
xdebug.idekey=PHPSTORM

;Whether to open remote debugging automatic start
xdebug.remote_autostart=1

1.3, set environment variables

[[email protected] ~]
  • The file is not tail plus the following code:
export XDEBUG_CONFIG="idekey=PHPSTORM"
export PHP_IDE_CONFIG="serverName=temp.topjz.com"

2, PHPSTORM IDE configuration

2.1、File->Settings->Languages & Frameworks > PHP

2.1.1 Configuring CLI Interpreters



2.1.2, code mapping

2.2、File->Settings->Languages & Frameworks > PHP > Debug

Note: The configured configuration in the Debug Port and the remote server here

2.3、File->Settings->Languages & Frameworks > PHP > Server

2.4、Add Run/Debug Configuration