How to Enable ServBay's Built-in Xdebug Module
As a powerful integrated web development tool, ServBay comes with the Xdebug module, and its enabling process is quite simple. Xdebug is a PHP debugging and profiling tool that helps developers with code debugging, performance analysis, and code coverage detection, making it an essential tool for developing and maintaining PHP applications.
Introduction to the Xdebug Module
Xdebug is a powerful PHP extension used for debugging and profiling PHP code. It offers a wide array of debugging features such as breakpoints, stack tracing, and variable watching. Additionally, Xdebug supports performance profiling and code coverage detection, assisting developers in optimizing code performance and ensuring code quality.
Key Features
- Breakpoint Debugging: Xdebug allows setting breakpoints in the code to debug it line by line, making it easy to find and fix errors.
- Stack Tracing: Xdebug generates detailed stack trace information when an error occurs, helping developers quickly locate problems.
- Performance Profiling: Xdebug provides performance profiling capabilities, producing detailed performance reports to help developers optimize code performance.
- Code Coverage: Xdebug supports code coverage detection, aiding developers in ensuring that all code paths are tested.
- IDE Integration: Xdebug can be integrated 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, each pre-installed 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, e.g., PHP 7.2
's Xdebug port is 39072
, PHP 8.3
's Xdebug port is 39083
.
How to Enable the Xdebug Module
By default, the Xdebug module is disabled. Enabling the Xdebug module is straightforward, requiring only modifications to the configuration file of the respective PHP version. The detailed steps are as follows:
Step 1: Locate the Configuration File
First, find the conf.d
directory for the corresponding PHP version. For example, to enable the Xdebug module for PHP 8.3, we need to edit the following file:
/Applications/ServBay/etc/php/8.3/conf.d/xdebug.ini
Step 2: 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 3: Configure Xdebug Parameters
To fully leverage Xdebug's features, configure some commonly used parameters in the xdebug.ini
file. 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 4: Restart the PHP Service
In ServBay's service management panel, restart the corresponding PHP service, e.g., restart the PHP 8.3 service. Once restarted, the Xdebug module will be successfully loaded.
Verify if the Xdebug Module is Loaded Successfully
You can verify if the Xdebug module was successfully loaded by creating a simple PHP file. In the web server's root directory, create a phpinfo.php
file with the following content:
<?php
phpinfo();
?>
2
3
Access https://servbay.host/phpinfo.php
, and look for Xdebug information in the PHP info page. If Xdebug-related information is displayed, the module has been successfully loaded.
Configuring Xdebug in PHPStorm
To use Xdebug for debugging in PHPStorm, follow these steps:
Step 1: Open PHPStorm and Go to Settings
- Open PHPStorm.
- Click
File
in the menu bar and selectSettings
(Windows/Linux) orPreferences
(macOS).
Step 2: 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 popped-up window, click the
+
sign to add a new PHP interpreter and selectLocal
. - Set the PHP interpreter path to the corresponding PHP version path in ServBay, e.g.,
/Applications/ServBay/package/php/8.3/8.3.7/bin/php
. - Click
OK
to save the settings.
Step 3: Configure Xdebug Debugging
Note
Each PHP version's Xdebug port is independent and associated with the version number, e.g., PHP 7.2
's Xdebug port is 39072
, PHP 8.3
's Xdebug port is 39083
.
- In the settings window, navigate to
Languages & Frameworks
->PHP
->Debug
. - In the
Xdebug
section, set theDebug Port
to39083
, matching thexdebug.client_port
configuration. - Ensure the
Can accept external connections
option is checked. - Click
Apply
, then clickOK
to save the settings.
Step 4: Configure PHP Web Server
- In the settings window, navigate to
Languages & Frameworks
->PHP
->Servers
. - Click the
+
sign on the right to add a new server configuration. - Set the server name, e.g.,
ServBay Localhost
. - Set
Host
to the corresponding host in ServBay, e.g.,servbay.new
, and port to 443 (HTTPS). - Set
Debugger
toXdebug
. - Click
OK
to save the settings.
Step 5: Start a Debugging Session
- Open the PHP project you want to debug in PHPStorm.
- Set a breakpoint in the code (click on the left side of the line number).
- Click the
Start Listening for PHP Debug Connections
button (little bug icon) in the PHPStorm top toolbar. - In the browser, access your PHP application, Xdebug will automatically connect to PHPStorm and pause execution at the breakpoint.
Conclusion
ServBay offers a convenient way to manage and enable the Xdebug module. With simple configuration and restart operations, developers can quickly enable the Xdebug module in different PHP versions, fully leveraging its powerful debugging and profiling features to enhance PHP application development and maintenance efficiency. Xdebug's breakpoint debugging, performance profiling, and code coverage detection features make it an indispensable tool for PHP developers.