I’ve struggled to get a dev environment setup and running with a persistent database and with xdebug installed. I finally managed to get my container going with a persistent database and I did finally manage to get xdebug installed with my container. But I am still not getting xdebug to work with vs code and my php_info() line is still showing that although xdebug is installed there are two error present. Any help would be greatly appreciated as I am stuck and can not move forward in my courses. Thanks.
Here are the two erros, google this issue hasn’t helped me.
|[Step Debug] Creating socket for 'host.docker.internal:9003', getaddrinfo: No such file or directory.|[⊕](https://xdebug.org/docs/errors#DBG-W-SOCK1)|
&
[Step Debug] Could not connect to debugging client. Tried: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port).
This is at the bottom of my output:
<small>/var/www/html/index.php:5:</small><small>string</small> '/usr/local/etc/php/php.ini' *(length=26)*
<small>/var/www/html/index.php:5:</small><small>string</small> '/usr/local/etc/php/conf.d/99-xdebug.ini, /usr/local/etc/php/conf.d/docker-php-ext-gd.ini, /usr/local/etc/php/conf.d/docker-php-ext-pdo_mysql.ini, /usr/local/etc/php/conf.d/docker-php-ext-sodium.ini, /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini, /usr/local/etc/php/conf.d/error_reporting.ini ' *(length=298)*
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20220829/xdebug.so
docker-compose.yml:
version: '3.1'
services:
php:
build:
context: .
dockerfile: Dockerfile
volumes:
["./:/var/www/html",
"./docker/php/conf.d/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini",
"./docker/php/conf.d/xdebug.ini:/usr/local/etc/php/conf.d/99-xdebug.ini",
"./docker/php/conf.d/error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini",
"./docker/php/conf.d/php.ini:/usr/local/etc/php/php.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
Dockerfile:
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 && docker-php-ext-enable xdebug \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/99-xdebug.ini \
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/99-xdebug.ini \
&& echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/99-xdebug.ini
# \
# && 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/php/conf.d/docker-php-ext-xdebug.ini:
zend_extension=xdebug
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20220829/xdebug.so
[xdebug]
xdebug.mode=develop,debug
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes
xdebug.log=/tmp/xdebug.log
docker/php/conf.d/php.ini:
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20220829/xdebug.so
docker/php/conf.dxdebug.ini:
zend_extension=xdebug
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20220829/xdebug.so
[xdebug]
xdebug.mode=develop,debug
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes
xdebug.log=/tmp/xdebug.log
index.php:
<?php
phpinfo();
var_dump(php_ini_loaded_file(), php_ini_scanned_files());
xdebug_info();
$fileContent = file_get_contents('/usr/local/etc/php/php.ini', true);
echo $fileContent . "<br><br>";
$hostFile = file_get_contents('/etc/hosts', true);
echo $hostFile;