LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-06-2024, 07:43 AM   #1
Garrett85
Member
 
Registered: Jan 2011
Posts: 332

Rep: Reputation: 6
Getting Xdebug, vsCode, and my container to play together


I've been working for weeks now, probably over a month to get vs code to stop on break points, but everytime I launch the web page it loads and vs code's debugger never stops. I'm doind this in a container and it took several weeks to get xdebug installing right (I only get to work on this stuff on the weekends) and several more weeks to work out two remaining xdebug erros that were appering when I would run echo xdebug_info(); in my php script. It's installed, and I'm no longer getting any errors, but I'm still completely stuck as vs code is not stopping when I load the page in the browser. Any help would be greatly appreciated as I have been unable to move forward with my php Udemy courses for over a month now. Thanks.

// direcotry structure

Code:
Garrett@ideaPad-3:newTest3$ ls -lR
.:
total 24
drwxrwxr-x 3 garrett garrett 4096 Mar 17 09:01 docker
-rw-rw-r-- 1 garrett garrett  796 Mar 24 09:32 docker-compose.yml
-rw-rw-r-- 1 garrett garrett  674 Mar 17 10:22 Dockerfile
-rw-rw-r-- 1 garrett garrett  238 Mar 17 09:01 httpd-vhost.conf
-rw-rw-r-- 1 garrett garrett   61 Mar 17 11:10 index.php
drwxrwxr-x 3 garrett garrett 4096 Mar 17 09:01 mariadb

./docker:
total 4
drwxrwxr-x 3 garrett garrett 4096 Mar 17 09:02 php

./docker/php:
total 4
drwxrwxr-x 2 garrett garrett 4096 Mar 17 09:01 conf.d

./docker/php/conf.d:
total 16
-rwxr-xr-x 1 garrett garrett 241 Mar 17 11:02 docker-php-ext-xdebug.ini
-rw-rw-r-- 1 garrett garrett  21 Mar 17 09:01 error_reporting.ini
-rw-rw-r-- 1 garrett garrett  91 Mar 17 10:37 php.ini
-rw-rw-r-- 1 garrett garrett 228 Mar 17 11:47 xdebug.ini
Note that docker-php-ext-xdebug.ini & xdebug.ini are identical.

// index.php
PHP Code:
<?php

phpinfo
();
echo 
"hello world";
echo 
xdebug_info();

?>
// docker-php-ext-xdebug.ini
Code:
zend_extension=xdebug
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20220829/xdebug.so

[xdebug]
xdebug.mode=debug
xdebug.client_host=127.0.0.53
xdebug.start_with_request=yes
xdebug.log=/tmp/xdebug.log
xdebug.remote_port=9003
// launch.json (note that I have tried ./ & ../ for localRoot, ../ seemed correct for my directory structure)
Code:
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for Xdebug",
            "type": "node",
            "request": "attach",
            "localRoot": "../",
            "remoteRoot": "/var/www/html",
            "port": 9003
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 0,
            "runtimeArgs": [
                "-dxdebug.start_with_request=yes"
            ],
            "env": {
                "XDEBUG_MODE": "debug",
                "XDEBUG_CONFIG": "client_port=${port}"
            }
        },
        {
            "name": "Launch Built-in web server",
            "type": "php",
            "request": "launch",
            "runtimeArgs": [
                "-dxdebug.mode=debug",
                "-dxdebug.start_with_request=yes",
                "-S",
                "localhost:0"
            ],
            "program": "",
            "cwd": "${workspaceRoot}",
            "port": 9003,
            "serverReadyAction": {
                "pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
                "uriFormat": "http://localhost:%s",
                "action": "openExternally"
            }
        }
    ]
}
// Dockerfile
Code:
FROM php:8.2-apache
COPY . /var/www/html
COPY ./httpd-vhost.conf /etc/apache/sites_available/
WORKDIR /var/www/html
RUN apt-get update && apt-get install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libpng-dev \
    && docker-php-ext-configure gd --with-freetype --with-jpeg \
    && docker-php-ext-install -j$(nproc) gd \
    && docker-php-ext-install pdo_mysql \
    && a2enmod rewrite \
    && pecl install xdebug-3.3.1 && docker-php-ext-enable xdebug
    # \
    # && sed -i '/LoadModule rewrite_module/s/^#//g' /usr/local/apache2/conf/httpd.conf \
    # && sed -i 's#AllowOverride [Nn]one#AllowOverride All#' /usr/local/apache2/conf/httpd.conf

// docker-compose
Code:
version: '3.1'

services:
  php:
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      [./:/var/www/html,
      ./docker/php/conf.d/php.ini:/usr/local/etc/php/php.ini,
      ./docker/php/conf.d/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini,
      ./docker/php/conf.d/error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini
      ]
    ports:
      ["8081:80"]
    stdin_open: true
    tty: true
  db:
    image: mariadb:10.6
    restart: always
    volumes:
      ["./mariadb/data:/var/lib/mysql"]
    environment:
      MYSQL_ROOT_PASSWORD: notSecureChangeMe
      MYSQL_USER: product_db_user
      MYSQL_PASSWORD: secret
  phpmyadmin:
    image: phpmyadmin
    restart: always
    ports:
      - 8001:80
    environment:
      - PMA_ARBITRARY=1
// php.ini
(this file is blank, it just was one line that's commented out)

Thanks.

Update, below or attached is my newest launch.json rendetion, VS Code is still not stopping on my breakpoints when I visit or refresh the stie in my browser but it running the script if I 'Launch currently opened script' in the top left debug Play button/dropdown, in that case it will start walking through the code. A very small victory I guess but not sufficient for web development. Any advice? I'm wanting vs code/xdebug to always be listening to my browsers interation with the site, the way php storm does at my normal dev job. Having a heck of a time getting this up and running at home with Vs Code.

Code:
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for Xdebug",
            "type": "node",
            "request": "attach",
            "localRoot": "../",
            "remoteRoot": "/var/www/html",
            "port": 9003
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9003,
            "runtimeArgs": [
                "-dxdebug.start_with_request=yes"
            ],
            "env": {
                "XDEBUG_MODE": "debug",
                "XDEBUG_CONFIG": "client_port=${port}"
            }
        },
        {
            "name": "Launch Built-in web server",
            "type": "php",
            "request": "launch",
            "runtimeArgs": [
                "-dxdebug.mode=debug",
                "-dxdebug.start_with_request=yes",
                "-S",
                "localhost:80"
            ],
            "program": "",
            "cwd": "${workspaceRoot}",
            "port": 9003,
            "serverReadyAction": {
                "pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
                "uriFormat": "http://localhost:%s",
                "action": "openExternally"
            }
        }
    ]
}
 
Old 04-13-2024, 11:24 AM   #2
Garrett85
Member
 
Registered: Jan 2011
Posts: 332

Original Poster
Rep: Reputation: 6
Solved myself. I use to be able to post here and get help, I heard nothing but crickets with this one.
 
  


Reply

Tags
containers, docker, php, vscode, xdebug



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Centos 6, PHP xdebug and profiler ... ehabcisco Linux - Server 1 07-22-2017 12:27 PM
linux mint 17 cinnamon with xampp and xdebug BobMoore Linux - Newbie 1 10-21-2014 02:23 PM
[SOLVED] Getting xdebug 2.0.5 switch text output to html output lhorace Linux - Server 1 11-01-2009 05:23 PM
LXer: How to Debug PHP with Vim and XDebug on Linux LXer Syndicated Linux News 0 03-04-2008 04:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration