Read about OpenEMR's Response to the COVID-19 Pandemic at https://www.open-emr.org/covid19/

Openemr:flex add xdebug using Dockerfile

I apologize for my ignorance upfront. I’m fairly new to PHP and am trying to set up a local openemr
environment where I can debug openEMR using PhpStorm and xdebug to learn how it runs. I cloned the openemr/openemr-devops repository locally, modified the Dockerfile to install xdebug, modified the php.ini file with the xdebug directives, created a new image, but get an error at startup - file not found.

Portion of Dockerfile modified - added apk directive to install php7-xdebug

#Install dependencies
RUN apk --no-cache upgrade
RUN apk add --no-cache
apache2 apache2-ssl git php7 php7-tokenizer php7-ctype php7-session php7-apache2
php7-json php7-pdo php7-pdo_mysql php7-curl php7-ldap php7-openssl php7-iconv
php7-xml php7-xsl php7-gd php7-zip php7-soap php7-mbstring php7-zlib
php7-mysqli php7-sockets php7-xmlreader php7-redis perl php7-simplexml php7-xmlwriter php7-
phar php7-fileinfo
php7-sodium php7-calendar
php7-xdebug
mysql-client tar curl imagemagick npm
python3 openssl git libffi-dev py-pip python3-dev build-base openssl-dev dcron
rsync shadow jq

php.ini modifications - the lines I added to end of [PHP] section …

zend_extension=/usr/lib/php7/modules/xdebug.so
xdebug.coverage_enable=0
xdebug.remote_enable=1
xdebug.remote_connect_back=1
xdebug.remote_log=/tmp/xdebug.log
xdebug.remote_autostart=true

I’ll keep looking and experimenting, but if anyone has some recommendations for getting debugging to work with flex I would appreciate it.

Thanks,

Nick

I solved my issue. I just used docker exec to get into the openemr container, followed the xdebug.org wizard recommendations, used docker commit to write out the new image, and now have a openemr container running xdebug. Next step, get it working with PHPStorm.

Well, that was somewhat painful, but I got it working.

add to php.ini file in /etc/php7
;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;
zend_extension=/usr/lib/php7/modules/xdebug.so
xdebug.remote_enable=1
xdebug.remote_autostart=true
xdebug.remote_host=192.168.1.x
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.idekey=PHPSTORM

PHPStorm / Settings / Languages & Frameworks / PHP / Debug / DBGp Proxy :
IDE key: PHPSTORM
Host: localhost
Port: 9000

PHPStorm / Settings / Languages & Frameworks / PHP / Debug :
Follow directions in PHPStorm Zero-configuration Debugging Tutorial including install of Xdebug Helper extension for Chrome

PHPStorm / Settings / Languages & Frameworks / PHP / Servers :
Setup localhost server with path mappings

hi @Nicholas_Steblay ,

Did you need to open up port 9000 on the docker-compose.yml? Would be really nice to support this via a docker composer environment setting (so would install everything in real time when start up the docker rather than build it into the Dockerfile) and I plan to make an issue for this.

So, to confirm, from above, need this package:

apk --no-cache upgrade
apk add --no-cache php7-xdebug

then add to php.ini

;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;
zend_extension=/usr/lib/php7/modules/xdebug.so
xdebug.remote_enable=1
xdebug.remote_autostart=true
xdebug.remote_host=192.168.1.x
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.idekey=PHPSTORM

Do you still need to make the edits to php.ini from your first post?

Hello @Nicholas_Steblay @brady.miller I am greatly interested in this, Many PHP devs I know mention the wonders of PHPStorm especially with remote debugging via xdebug, I have been frustrated with the complexities of setting that up,plus PHPStorm being a little more heavy than my VScode, Would be very happy to see how it works. I already have an activated version of the PHPStorm IDE .

I have a working xdebug with docker flex up on GitHub if anyone has questions. I think I also had a guide on how to set it up too.

[openemr-devops/docker/openemr/flex-3.10-Xdebug at Xdebug · boxlady/openemr-devops · GitHub]

I need to rebase it with the new changes that were recently made, but you can see how stuff is set up.

I have it setup for both linux and windows now…

2 Likes

Yes, I needed to add port 9000 to the docker-compose.yml

version: ‘3.1’
services:
mysql:
restart: always
image: mariadb:10.4
command: [‘mysqld’,’–character-set-server=utf8’]
ports:
- 3306:3306
volumes:
- databasevolume:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
XDEBUG_CONFIG: remote_host=localhost
openemr:
restart: always
# use an image if you’re not changing the build steps:
image: nsteblay/openemr:2.4
# if editing the Dockerfile, clone the devops repo and point to the path:
# build: …/openemr-devops/docker/openemr/flex-edge/
ports:
- 80:80
- 443:443
- 9000:9000
volumes:
- .:/openemr:ro
- .:/var/www/localhost/htdocs/openemr:rw
- publicvolume:/var/www/localhost/htdocs/openemr/public:rw
- sitesvolume:/var/www/localhost/htdocs/openemr/sites/default:rw
- nodemodules:/var/www/localhost/htdocs/openemr/node_modules:rw
- vendordir:/var/www/localhost/htdocs/openemr/vendor:rw
- ccdamodule:/var/www/localhost/htdocs/openemr/ccdaservice:rw
- logvolume:/var/log
environment:
MYSQL_HOST: mysql
MYSQL_ROOT_PASS: root
MYSQL_USER: openemr
MYSQL_PASS: openemr
OE_USER: admin
OE_PASS: pass
EASY_DEV_MODE: “yes”
EASY_DEV_MODE_NEW: “yes”
DEVELOPER_TOOLS: “yes”
ACTIVATE_API: “yes”
GITHUB_COMPOSER_TOKEN: xxx
depends_on:
- mysql
phpmyadmin:
restart: always
image: phpmyadmin/phpmyadmin
ports:
- 8080:80
environment:
PMA_HOSTS: mysql
volumes:
databasevolume: {}
publicvolume: {}
sitesvolume: {}
nodemodules: {}
vendordir: {}
ccdamodule: {}
logvolume: {}

Ya, I was having problems with VS Code. PHPStorm appears to have better capabilities for debugging, especially when using Docker. Julie’s guide looks good for configuring PHPStorm. I used the DBGp proxy on port 9000 and added the IDE key into the php.ini file. I tried doing all the modifications to the docker image using the Dockerfile provided in openemr-devops but wasn’t successful - I’ll try that again. Instead I exec’d into the running flex container and added xdebug as specified by the xdebug.org wizard and wrote out the image using the docker commit command. I’m also using the Xdebug helper extension for Chrome

Brad, I had problems with setting up the flex Dockerfile provided in openemr-devops. I ended up using the docker exec command to start a bash shell in the running flex docker container. I then manually installed xdebug per the recommendations provided by the xdebug.org wizard. It did require a compile using GCC. I then ran the docker commit command to write out the updated image. I tried for hours to get it to work through configuring the Dockerfile but wasn’t successful. I’ll probably try again as some point but am more focused at this time in learning how the PHP code is working for Openemr. If I have time I’ll try again to use the Dockerfile approach.

Hi,
Just added support for xdebug and profiling in the easy development docker environment. Instructions for use are in step 10 of openemr/CONTRIBUTING.md at master · openemr/openemr · GitHub

4 Likes

Thanks for all the hard work setting that up.

1 Like