How to Enable the Built-in Xdebug Module in ServBay
As a powerful integrated web development tool, ServBay comes with the Xdebug module, which is very easy to enable. Xdebug is a PHP debugging and profiling tool that helps developers debug code, perform performance analysis, and conduct code coverage testing. It is an invaluable tool for the development and maintenance of PHP applications.
Overview of the Xdebug Module
Xdebug is a powerful PHP extension used for debugging and analyzing PHP code. It provides a wealth of debugging features, including breakpoint debugging, stack tracing, and variable monitoring, among others. Moreover, Xdebug supports performance analysis and code coverage testing, helping developers optimize code performance and ensure code quality.
Key Features
- Breakpoint Debugging: Xdebug supports setting breakpoints in code, allowing line-by-line debugging to easily find and fix errors.
- Stack Tracing: In the event of an error, Xdebug can generate detailed stack trace information, helping developers quickly pinpoint issues.
- Performance Analysis: Xdebug offers performance analysis capabilities, generating detailed performance reports to help developers optimize code performance.
- Code Coverage: Xdebug supports code coverage testing, ensuring that all code paths are covered during testing.
- Integration with Development Environments: Xdebug can integrate with various Integrated Development Environments (IDEs) like PHPStorm and Visual Studio Code, providing a convenient debugging experience.
Xdebug Module Versions in ServBay
ServBay supports multiple PHP versions, and each version comes preinstalled with the corresponding Xdebug module. The specific versions are as follows:
- PHP 5.6, 7.0, 7.1: Xdebug 2.5.5
- PHP 7.2, 7.3, 7.4: Xdebug 3.1.6
- PHP 8.0, 8.1, 8.2, 8.3: Xdebug 3.3.1
- PHP 8.4: Xdebug 3.4.0-dev
Note
Each PHP version's Xdebug port is independent and associated with the version number. For instance, the Xdebug port for PHP 7.2
is 39072
, while for PHP 8.3
, it is 39083
.
How to Enable the Xdebug Module
By default, the Xdebug module is disabled. The steps to enable it are straightforward. Simply navigate to Language
- PHP
, select the PHP version you want to enable, such as PHP 8.4
, click Extensions
on the right, then toggle the switch next to the Xdebug
module and save.
Users can also manually open or modify the module configuration. Below are the detailed steps:
Step One: Locate the Configuration File
First, locate the conf.d
directory for the respective PHP version. For example, to enable the Xdebug module for PHP 8.3, you need to edit the following file:
/Applications/ServBay/etc/php/8.3/conf.d/xdebug.ini
Step Two: Edit the Configuration File
Open the xdebug.ini
file and uncomment the following line:
[Xdebug]
; Uncomment the following line to enable XDebug
zend_extension = xdebug.so
2
3
Step Three: Configure Xdebug Parameters
To fully leverage Xdebug's features, you can configure some common parameters in xdebug.ini
. For example:
xdebug.mode=debug,develop
xdebug.start_with_request=yes
xdebug.client_host=localhost
xdebug.client_port=39083
xdebug.log=/Applications/ServBay/logs/xdebug/8.3/xdebug.log
2
3
4
5
Step Four: Restart the PHP Service
In the ServBay service management panel, restart the relevant PHP service, e.g., PHP 8.3. After restarting, the Xdebug module will be successfully loaded.
Verify if the Xdebug Module is Successfully Loaded
You can verify if the Xdebug module is successfully loaded by creating a simple PHP file. In the root directory of your web server, create a phpinfo.php
file with the following content:
<?php
phpinfo();
?>
2
3
Access https://servbay.host/phpinfo.php
, and check for the Xdebug-related information on the PHP info page. If you see Xdebug information, the module has been successfully loaded.
Configuring Xdebug in PHPStorm
To use Xdebug for debugging in PHPStorm, follow these configuration steps:
Step One: Open PHPStorm and Access Settings
- Open PHPStorm.
- Click on
File
in the menu bar, then selectSettings
(Windows/Linux) orPreferences
(macOS).
Step Two: Configure PHP Interpreter
- In the settings window, navigate to
Languages & Frameworks
->PHP
. - In the
CLI Interpreter
section, click the...
button on the right. - In the popup window, click the
+
to add a new PHP interpreter, selectLocal
. - Set the PHP interpreter path to the path of the corresponding PHP version in ServBay, e.g.,
/Applications/ServBay/package/php/8.3/8.3.7/bin/php
. - Click
OK
to save the settings.
Step Three: Configure Xdebug Debugging
Note
Each PHP version's Xdebug port is independent and associated with the version number. For instance, the Xdebug port for PHP 7.2
is 39072
, while for PHP 8.3
, it is 39083
.
- In the settings window, navigate to
Languages & Frameworks
->PHP
->Debug
. - In the
Xdebug
section, set theDebug Port
to39083
, consistent with thexdebug.client_port
configuration. - Ensure the
Can accept external connections
option is checked. - Click
Apply
and then clickOK
to save the settings.
Step Four: Configure PHP Web Application Server
- In the settings window, navigate to
Languages & Frameworks
->PHP
->Servers
. - Click the
+
on the right to add a new server configuration. - Set the server name, e.g.,
ServBay Localhost
. - Set the
Host
to the corresponding host in ServBay, e.g.,servbay.new
, and the port to 443 (HTTPS). - Set the
Debugger
toXdebug
. - Click
OK
to save the settings.
Step Five: Start a Debug Session
- Open the PHP project you want to debug in PHPStorm.
- Set breakpoints in the code (click the empty area to the left of the line number).
- Click the
Start Listening for PHP Debug Connections
button (bug icon) in the top toolbar of PHPStorm. - Access your PHP application in the browser, and Xdebug will automatically connect to PHPStorm and pause execution at the breakpoint.
Conclusion
ServBay provides a convenient way to manage and enable the Xdebug module. Through simple configuration and restart operations, developers can quickly enable the Xdebug module across different PHP versions, fully utilizing its powerful debugging and analysis features to enhance PHP application development and maintenance efficiency. Xdebug’s capabilities in breakpoint debugging, performance analysis, and code coverage testing make it an indispensable tool for PHP developers.