1

How can the php.ini setting be set conditionally depending on local operating system?

The .env file contains two variables:

XDEBUG_ENABLE=true
PHP_INI=./docker/runner/php.ini-development

Docker-compose.yml looks like this:

...
build:
  context: .
  dockerfile: ./docker/runner/Dockerfile
  args:
    - XDEBUG_ENABLE=${XDEBUG_ENABLE}
    - PHP_INI=${PHP_INI}
...

The Dockerfile contains the following code:

...
ARG PHP_INI=./docker/runner/php.ini-local
COPY $PHP_INI /usr/local/etc/php/php.ini

ARG XDEBUG_ENABLE=false
RUN if [ $XDEBUG_ENABLE = true ]; then pecl install xdebug-2.6.0 && docker-php-ext-enable xdebug; fi;
...

The interesting thing is within the php.ini-development:

...
xdebug.default_enable = 1
xdebug.remote_connect_back = 0
xdebug.remote_host = docker.for.mac.host.internal
...

At this point there should be different setting for Apple and Linux machines, because Linux supports "xdebug.remote_connect_back = 1" and Apple doesn't.

I guess "uname" can be used and in case of response "Darwin" the settings can be used, otherwise they should be overwritten by "xdebug.remote_connect_back = 1".

How can I solve it?

EDIT: Currently I use an additional variable in the .env file like APPLE_OS_X=true. The Users have to adjust it to false when using Linux or Windows machines. Depending on this variable the value of xdebug.remote_connect_back will be overwritten with 1.

The question is still how I could react on the shell command 'uname' to automatically set the value of APPLE_OS_X in the .env file or xdebug.remote_connect_back in the Dockerfile.

naptoon
  • 1,203
  • 2
  • 8
  • 11
  • *"because Linux supports "xdebug.remote_connect_back = 1" and Apple doesn't."* WHAT? That's wrong. Maybe Docker for Mac has some issues that lead to detecting the wrong IP or something .. but the functionality itself is working just fine... – LazyOne Feb 15 '18 at 23:54
  • Yeah, I mean in this configuration with Docker running on Mac OS X Xdebug can't recognize the IP where the container was requested from, so remote_connect_back doesn't work. You need to specify the remote_host value and on the Mac OS X side you need to create a alias (10.254.254.254 for example). – naptoon Feb 16 '18 at 08:22
  • From some [PhpStorm ticket](https://youtrack.jetbrains.com/issue/WI-38060#comment=27-2423727): *"Found that docker has introduced a variable that will resolve the Mac's IP through the use of `docker.for.mac.localhost`."* https://docs.docker.com/docker-for-mac/networking/#known-limitations-use-cases-and-workarounds I see no mention of that setting on that page -- maybe it's now called `docker.for.mac.host.internal` -- not sure. try it anyway.... – LazyOne Feb 16 '18 at 09:22
  • Thank you for that, but there is still the same problem in the end of the day. I have to decide by OS which setting should be used. We have some guys with linux machines, the most are using macs and one uses windows. When I distribute the files, the settings should be done automatically by recognizing the OS. So still I would have to determine if for example uname is responding with Darwin (means you are on a Mac system), or other, then you can use the remote_connect_back = 1 setting. – naptoon Feb 16 '18 at 10:21
  • Addition: If `xdebug.remote_connect_back` is enabled, `xdebug.remote_host` is ignored, so I could set the remote host to `docker.for.mac.host.internal` and just have to make sure, that `xdebug.remote_connect_back` is 0 an macs and 1 on all other systems. – naptoon Feb 16 '18 at 11:05

0 Answers0