← Back to list

Mastering Live PHP Debugging with Xdebug and VS Code (Perfect for OSWE Prep)

Setting up a reliable PHP debugging environment is essential for deep code analysis — especially if you’re preparing for the OSWE exam…

Anekant Singhai Jain · 2025-11-13 03:09 · 2 claps · 2.5 min read
#php #php-developers #php-development #oswe #cybersecurity
Open on Medium ↗
Wiki topics: 💻 · Programming 🔒 · Cybersecurity

Mastering Live PHP Debugging with Xdebug and VS Code (Perfect for OSWE Prep)

Setting up a reliable PHP debugging environment is essential for deep code analysis — especially if you’re preparing for the OSWE exam like me or doing vulnerability research in PHP web apps like ATutor, DVWA, or custom CMS platforms.

This guide walks you through setting up Xdebug with VS Code, configuring PHP 7.4, fixing permission issues, and enabling MySQL query logging — everything you need to efficiently debug and trace PHP applications.

All Screenshots at last

1. Install Xdebug for PHP

You can install Xdebug directly via APT:

sudo apt update
sudo apt install php-xdebug
# or for a specific PHP version
sudo apt install php7.4-xdebug

⚙ 2. Configure Xdebug in php.ini

Locate your php.ini (usually in /etc/php/7.x/apache2/php.ini) and add or update the following lines:

xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.discover_client_host=1
xdebug.client_port=9003
xdebug.client_host=127.0.0.1
xdebug.log="/tmp/xdebug.log"
sudo systemctl restart apache2

3. VS Code Launch Configuration

In VS Code, open Run and Debug (Ctrl+Shift+D), click “create a launch.json”, and choose PHP as the environment.

NOTE: If you have the code in /var/www/html/ , Change Ownership to Your User (Recommended for Local Dev)

sudo chown -R yourusername:www-data /var/www/html/atutor
sudo chmod -R 775 /var/www/html/atutor

Example configuration (for an ATutor setup):

change the /atutor to any folder you want , or if there’s no folder , leave it after /html

sudo mkdir -p /var/www/html/atutor/.vscode
sudo nano /var/www/html/atutor/.vscode/launch.json
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Listen for Xdebug (ATutor)",
      "type": "php",
      "request": "launch",
      "port": 9003,
      "pathMappings": {
        "/var/www/html/atutor": "${workspaceFolder}"
      },
      "hostname": "127.0.0.1",
      "log": true
    }
  ]
}

Save this file as .vscode/launch.json in your project directory.

4. Optional: Trace or Log Without a Full Debugger

If you only want to see variable assignments or function traces without stepping through line by line, enable Xdebug’s trace mode:

xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.discover_client_host=1
xdebug.client_port=9003
xdebug.client_host=127.0.0.1
xdebug.log="/tmp/xdebug.log"

You can then inspect /tmp/xdebug.log for request traces and variable changes.

5. Install Xdebug Browser Extension

Install the Xdebug helper extension for Chrome or Firefox. Then, in its settings, set the IDE key to VSCODE (case-sensitive).

6. Enable Xdebug via mods-available

Open /etc/php/<your-php-version>/mods-available/xdebug.ini and ensure it contains:

zend_extension=xdebug

; Enable debugging
xdebug.mode=debug
xdebug.start_with_request=yes

; IDE connection
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
xdebug.idekey=VSCODE

; Optional discovery for Docker setups
xdebug.discover_client_host=1

; Log for troubleshooting
xdebug.log=/tmp/xdebug.log
xdebug.log_level=7
sudo phpenmod xdebug
sudo systemctl restart apache2

Verify via:

php -v

Expected output:

PHP 7.4.33 (cli) (built: Jul  3 2025 16:41:49) ( NTS )
Zend Engine v3.4.0, Copyright (c)
    with Xdebug v3.1.6, by Derick Rethans

🗃7. Enable MySQL Query Logging (Optional)

If you need to monitor SQL queries during testing, edit:

/etc/mysql/mysql.conf.d/mysqld.cnf

uncomment and add:

general_log = 1
general_log_file = /var/log/mysql/mysql.log
sudo systemctl restart mysql

If you like what I write: I am actively looking for a job , hope you may help My researches: Here

Twitter: Here

Linkedin: Here


메타데이터
post_id
58eeb7ab4b9c
slug
mastering-live-php-debugging-with-xdebug-and-vs-code-perfect-for-oswe-prep-58eeb7ab4b9c
url
https://medium.com/@anekantsinghai/mastering-live-php-debugging-with-xdebug-and-vs-code-perfect-for-oswe-prep-58eeb7ab4b9c
canonical_url
https://medium.com/@anekantsinghai/mastering-live-php-debugging-with-xdebug-and-vs-code-perfect-for-oswe-prep-58eeb7ab4b9c
author_url
https://medium.com/@anekantsinghai
status
ok
fetched_at
2026-06-26 03:39:16