1

I am making a Laravel/Reactjs app using using Docker. Coding in reactjs, I use console.log alot to debug, but I cannot find anything similar for debugging my PHP code. Suppose I in a PHP file want to check that my id variable is what I think it is, I would like to do the following (Auth::user() returns a user which has an id)

function somePHPfunction {
$user = Auth::user();
$id = $user->id;
console.log($id);
}

which of course doesn't work.

I am using vscode as my editor, and I have tried setting up the extension PHP Debug with Xdebug, but I can't get it to work, which I think might be due to how docker works. I have tried the following guide, but could not make that work either (and it's for mac, I'm using linux).

I have also tried running different scripts (some examples can be found here), but none of them works in code as mentioned earlier.

Below I am posting my docker file, my docker-compose.yaml file and my .env file (the project is made in Laravel).

dockerfile

FROM php:7.2-apache

RUN a2enmod rewrite

RUN rm /bin/sh && ln -s /bin/bash /bin/sh && \
apt-get update && apt-get install --no-install-recommends -y \
  libjpeg-dev \
  libpng-dev \
  libpq-dev \
  curl \
  wget \
  vim \
  git \
  unzip \
  mysql-client \
;

RUN docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr; \
docker-php-ext-install -j "$(nproc)" \
  gd \
  opcache \
  pdo_mysql \
  pdo_pgsql \
  zip \
;

RUN apt-get clean && rm -rf /var/lib/apt/lists/*

WORKDIR /var/www/html

RUN curl -sS https://getcomposer.org/installer | php && \
mv composer.phar /usr/local/bin/composer && \
ln -s /root/.composer/vendor/bin/drush /usr/local/bin/drush

COPY scan-apache.conf /etc/apache2/sites-enabled/scan-apache.conf

docker-compose.yaml version: '3.3'

services:

app:
image: image
build: .
container_name: container
env_file:
  - .env
ports:
  - "4321:80"
volumes:
  - .:/var/www/html
depends_on:
  - mysql

mysql:
image: mysql/mysql-server:5.7
# build: ./docker/mysql
hostname: mysql
container_name: scan-db
env_file:
  - .env
volumes:
  - mysql-data-scan-redcap:/var/lib/mysql

volumes:
mysql-data-scan-redcap:

networks:
default:
external:
  name: webproxy

I am hoping for a method which can do the same as console.log does in javascript, so I can see what's going on at runtime.

Richard Jensen
  • 176
  • 1
  • 14
  • If you can't get xdebug working, you can use `var_dump` to examine specific variables at specific times. xdebug will definitely be better if you can get it working, but I'm afraid I can't help much with troubleshooting that. – Don't Panic Jan 09 '19 at 17:20
  • 1
    you can't use `dd()` too – Ryuujo Mar 04 '19 at 08:49

0 Answers0