Help to get PHP8 w/ xdebug in Docker on OSX running for local dev (phpunit) via PhpStorm in a checkout project
php - Installing XDebug in Docker - Stack Overflow
Getting xdebug to work with my container
xdebug not installed on php 8.3 docker container - Stack Overflow
Videos
SOLVED
See https://www.reddit.com/r/PHPhelp/comments/jti8i2/help_to_get_php8_w_xdebug_in_docker_on_osx/gc7g8j5/?utm_source=reddit&utm_medium=web2x&context=3 for the summary
Thanks everyone!
I've never really used docker before and I'm hitting so many walls that I stopped counting, I think today (Friday 13th) is my lucky day.
What I currently have:
-
Host OSX
-
PHP 7.4 installed via brew
-
git clone of my project
-
phpunit tests are running, also inside PhpStorm
-
I can also debug, I've xdebug installed via pecl
What I'm trying to achieve:
-
same as above but with PHP 8 without replacing my brew PHP 7.4; this is intended only for local dev
-
I don't need webserver etc., just CLI
-
PHP 8.0 (e.g. the php:8.0.0RC4-cli image I guess?)
-
being able to install the composer dependencies via PHP within docker, important for package version resolving (this project will install different version on different PHP version to be compatible)
-
run phpunit (ideally also via PhpStorm)
-
super bonus: also get xdebug working in the docker image (probably need to add further install steps with pecl in
Dockerfile?) so it also works via PhpStorm
In fact, I don't know how, I got it working that I can run phpunit and it runs it in the docker image; but I'm too stupid to figure out how to also run composer inside the image. I don't even know of composer is available in this image 🤷♀️
Dockerfile I have (don't laugh):
FROM php:8.0.0RC4-cli ADD ./ /app WORKDIR /app
Docker composer (because no idea, tutorials and stuff):
version: '3'
services:
php:
build: .
volumes:
- ./:/app
working_dir: '/app'
I then did docker-compose build and the resulting image I selected in PhpStorm (remote interpreter) and managed to get phpunit running.
It "works" but the vendor files are still from my local host PHP composer installation and they contain incompatible code with PHP8 (e.g. classes like Match 💥), thus I need fix that but no idea (aka run composer in Docker with PHP 8).
Is anyone willing / has the energy and time to help me moving forward? Would be much appreciated :)
Thanks
I solved this by adding the following lines into my Docker file:
# "xdebug-2.9.0" for PHP<=7.4 — "xdebug" (3) for PHP>=8
ARG XDEBUG_VERSION="xdebug-2.9.0"
FROM php:7.0-apache
RUN a2enmod rewrite
RUN docker-php-ext-install pdo pdo_mysql
RUN yes | pecl install ${XDEBUG_VERSION} \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini
COPY php.ini /usr/local/etc/php/
COPY . /var/www/html/
try this:
RUN pecl install xdebug && docker-php-ext-enable xdebug