A script that tells you why your OpenEMR install shows a blank page

Install and upgrade problems are the most common topics here, and many go unanswered. Most come down to the same dozen causes: a PHP that’s too old or too new, a missing extension (often intl, which turns the calendar into “Unknown”), files that didn’t finish copying, a database that’s a step behind the code, or encryption keys left behind in a move.

I’ve put together a read-only script that checks for those causes and says what each one means: openemr-doctor.php. Download it to the server and run:

php openemr-doctor.php --openemr=/var/www/html/openemr

What it checks:

  • PHP version and extensions against your release
  • php.ini limits
  • libraries, built assets and files missing compared with your release or patch
  • the database connection, with what each error number means
  • whether the database matches the code (an unfinished sql_upgrade.php or sql_patch.php)
  • modules switched on but missing
  • encryption keys that don’t match the database
  • documents whose files aren’t where OpenEMR looks

The web server often runs a different PHP from the command line. To check that one, copy the file into your OpenEMR folder and open http://localhost/<your openemr folder>/openemr-doctor.php in a browser on the server itself. It refuses anyone else. Delete it afterwards.

It changes nothing and prints no passwords or keys. The only thing it downloads is the facts for your release; nothing about your server is sent anywhere. It runs on PHP 5.4 and later, so it can tell you a PHP is too old instead of crashing on it.

There’s also an upgrade pre-flight check that lists what to fix before upgrading, and generated upgrade notes for every release from 7.0.0 to 8.4.1: GitHub - anun333/openemr-reference: OpenEMR facts generated from each release's source: upgrade notes, schema, settings; plus an upgrade pre-flight check and an install doctor · GitHub

If it gives you a wrong answer, please paste the output here or open an issue. The output contains no patient data.

Since this post, the same repository has two more tools, for the upgrade itself:

  • openemr-rehearse.sh runs your upgrade on a copy of your database, in Docker, before you do it for real. Give it a mysqldump of your site. It reports what the upgrade changed in the database structure and in the data, and whether anything was lost. Your live site isn’t touched.
  • openemr-upgrade.sh upgrades an install from the release tarball. It backs up the database and sites/, unpacks the new release beside the old one, runs the upgrade, checks the result, and keeps a one-command rollback. It also finds files you changed in OpenEMR itself and carries the changes over where they still fit, instead of silently dropping them.

The rehearsals turned up two things worth knowing if you’re upgrading an older site:

  • Sites first installed before 6.0.0 still have old utf8 tables, which no upgrade converts. An emoji typed into one is saved as ?. The repository has a converter for them.
  • If you’re moving to MariaDB 11.4 or newer by dump and restore, create the database with CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci before restoring. Otherwise the tables the upgrade creates end up in a different collation, and some screens and the upgrade itself can fail.

Everything is in GitHub - anun333/openemr-reference: OpenEMR facts generated from each release's source: upgrade notes, schema, settings; plus an upgrade pre-flight check and an install doctor · GitHub (release notes: Release v0.3.0: the upgrade itself, with a way back · anun333/openemr-reference · GitHub). As before, reports of a wrong answer are very welcome.

Fun.

What can you do with an already Dockerized OpenEMR? One running from, say, openemr/docker/production/docker-compose.yml at master · openemr/openemr · GitHub (or better yet, the appliance at openemr-devops/packages/appliance at master · openemr/openemr-devops · GitHub)?

I wonder if it wouldn’t be worth sitting down and working out how to do an anonymous temporary container that could borrow an OpenEMR volume mount long enough to run the doctor against the environment. Or would this be a good place to lean on the new vendor hooks?

Thanks, good question.

With a Dockerized install today:

  • The doctor and the pre-flight check run inside the container, with the container’s own PHP. Copy the file in, then run docker compose exec openemr php /tmp/openemr-doctor.php --openemr=/var/www/localhost/htdocs/openemr. The doctor’s tests run it exactly that way against the official 8.4.1 image.
  • The rehearsal is already Docker-native. Upgrading a Docker install means changing the image tag, and openemr-rehearse.sh does that on a copy of your database dump, with the official image of the target release.
  • openemr-upgrade.sh is only for tarball installs.

Your temporary-container idea works. I just ran the doctor from a throwaway container of the same image, borrowing the running container’s volumes and network, on a stock 8.4.1 compose stack:

docker run --rm --volumes-from <openemr container> --network <compose network> \
  --user apache --entrypoint php -v "$PWD/openemr-doctor.php:/tools/openemr-doctor.php:ro" \
  openemr/openemr:8.4.1 /tools/openemr-doctor.php --openemr=/var/www/localhost/htdocs/openemr

It produced the full report, database included. Using the same image matters, because the PHP and extension checks are about the image’s PHP. It’s also a way to run the doctor when the OpenEMR container won’t stay up, which is when people need it most.

The vendor hooks look like a natural home too. A postupgrade hook that runs the doctor would put its findings in the compose log right after each upgrade. Whether a FAIL should stop the launch is your call, since that lifecycle point isn’t retried. I can write the hook and test it against the official image, either for openemr-devops or in the reference repo, whichever you prefer.

One more fit with what the hooks are for: the upgrade script finds edits to OpenEMR’s own files by comparing them with the release’s git hashes, and saves each edit as a patch. For a Docker install, a prelaunch hook could reapply those patches on every launch. Would that help the people you added the hooks for?

If its possible, this would be good to add as Symfony CLI so that php bin/console openemr-doctor would run the checks.

Yes, that’s a good home for most of it, as php bin/console openemr:doctor, like the other commands.

One limit shapes the split: bin/console needs OpenEMR to start (Composer’s autoloader, a PHP that can parse it), and several of the doctor’s checks are for when that fails: a PHP that’s too old or too new, a missing vendor/, files that didn’t finish copying. So the command would cover a working install, and the standalone file would stay as the fallback that runs on any PHP.

It would also tie in with Asher’s hooks: a postupgrade hook could simply run bin/console openemr:doctor.

It should build on src/Health, the checks behind the readyz probe, and that raises a design question for you and Michael: HealthCheckResult is healthy or not, while the doctor also reports warnings and notes, each with a fix. Extend the result, or keep the doctor’s results separate so the probe doesn’t change? I’ll open a GitHub issue with a proposed design, so it can be settled before any code.

The design is up for discussion here: feat(console): `openemr:doctor` to diagnose an install from the command line · Issue #14601 · openemr/openemr · GitHub

It proposes three small PRs, ordered by what each check needs: the checks that only read files first (PHP version, extensions, Composer packages), then the database ones on their own connection, then the ones that need OpenEMR fully started. There are three open questions there, the main one for Michael about the result model. I’ll wait for answers before writing code.

I tried really hard to make this work without writing the doctor script to the drive, but I had the absolute worst luck trying to pipe curl into the container’s PHP and eventually just flat gave up.

With this note, here’s a one-shot script somebody can Just Paste into their compose directory and have it work.

#!/bin/bash

read -a dockerps < <(docker compose ps | grep openemr/openemr)
CONTAINER=${dockerps[0]}
IMAGE=${dockerps[1]}
NETWORK=$(docker inspect ${CONTAINER} | jq -r '.[0].NetworkSettings.Networks | keys[]')

curl -L -O https://github.com/anun333/openemr-reference/raw/refs/heads/main/preflight/openemr-doctor.php

docker run --rm --volumes-from ${CONTAINER} --network ${NETWORK} \
  --user apache --entrypoint php \
  -v "$PWD/openemr-doctor.php:/tools/openemr-doctor.php:ro" \
  ${IMAGE} /tools/openemr-doctor.php --openemr=/var/www/localhost/htdocs/openemr

echo "doctor.sh: complete"

Interrogates docker compose, fetches the network it needs too, grabs the doctor, and hands out the output. As long as the compose is up, it’ll find what it needs.

Thanks, that’s handy. I ran it on a stock 8.4.1 compose stack and hit one snag. Builds get republished under the same tag (the 8.4.1 image I’d pulled was rebuilt on October 13), and once the tag has been pulled again since the container started, docker compose ps shows the image as sha256:… instead of openemr/openemr:…, so the grep finds nothing. On a stack that hasn’t been re-pulled it works as is, and pinning a dated tag such as 8.4.1-2026-10-14 avoids it too, since that tag never moves.

Trying it on older releases turned up one more: the throwaway container only shares volumes, so on a stack without sites/ on a volume it sees the image’s own, never-configured sites/ and skips the database checks.

I’ve added your script to the repository, credited to you, with both handled. It finds the container by the image it was started from and runs that exact image, and when sites/ isn’t on a volume it runs the doctor inside the running container instead. It also works with the older docker-compose. I tested it on 8.4.1 after a re-pull, and on the official 5.0.2 and 7.0.3 images:

curl -fsSLO https://github.com/anun333/openemr-reference/releases/latest/download/openemr-doctor-docker.sh
bash openemr-doctor-docker.sh

Run it in the directory with the docker-compose.yml. On my stack it also flagged the ClaimRev module missing from the image (#14572).

Don’t know why you credited me, I don’t think a single line I wrote survived. :smiley: I had no idea docker inspect was so willing to let you control the output.

Can you do me one favor? Wrap the whole script in a function and then call the function? I want to tell people to do curl <script> | bash and wrapping protects against partial downloads.

Done, it’s in v0.3.4: the whole script is one function, called on the last line, so a download cut short does nothing. This now works from the directory with the docker-compose.yml:

curl -fsSL https://github.com/anun333/openemr-reference/releases/latest/download/openemr-doctor-docker.sh | bash

Fair point on the credit. The README now says the idea came from you, which it did.

Marvelous, thank you. We might move the script around or do other stuff later, but being able to tell somebody to Just Run This may knock a lot of time off getting support off the ground.

@jesdynf, on “we might move the script around”: if you’d rather it lived in openemr-devops, or beside the image in openemr/openemr, say where and I’ll send it there as a PR. It’s one file, GPL-3.0 like both repos, and the only thing tied to my repository is the address it downloads the doctor from, which is a variable. Until then I’ll keep the curl … | bash address working and keep changes to the script small.

One question while you’re here, since it’s your area: when a site’s code and database are at different patch levels, the doctor tells it to open sql_patch.php. The Docker image removes that file after setup, and Docker Hub says patch upgrades (7.0.3 to 7.0.3.4) aren’t automatic. What should it tell a Docker user instead?

Hello, @anun333, sorry for the delay on this. Between php2shell and the spin-up to the holidays things have been hectic.

I think I’d prefer to see it in the -devops repo because if it lives there, people are always forced to get a new version of it to use it, though I suppose airgapped systems that can’t see the net might need the file copied around. I don’t want to have “old” versions of the doctor running around on old containers, is my point. Anybody asking for help from the help tool should get the most recent model.

As for the patch question, I’m not sure. Recent patch upgrades are automatic, running the new container flavor catches up the existing DB to the current container version, and we’ve had that in place since early 5.0. If the container is healthy enough to bootstrap, it should detect the DB and patch it in place. I’m not sure what the hub notes are saying about this.

Thanks, that makes sense. It’s in a pull request now: feat(openemr-doctor): add the install doctor and a daily smoke test by anun333 · Pull Request #916 · openemr/openemr-devops · GitHub. Once it merges, the one line becomes

curl -fsSL https://raw.githubusercontent.com/openemr/openemr-devops/master/utilities/openemr-doctor/openemr-doctor-docker.sh | bash

and it always downloads the newest doctor from there. For air-gapped systems, a copied doctor says how old it is when it can’t look for a newer one, and online every copy says when there is one. The old address will forward to the new one.

On patches, we tried it on the 8.0.0 image (8.0.0.3): with the database at patch 2, recreating the container left it at patch 2. As far as we can tell, the start runs the upgrade when the image is a newer release, and in 8.5.0 and later images when the database version is behind, which covers patches that change the schema. A patch number on its own isn’t touched, which matches the Docker Hub note. So for now the doctor’s patch advice stays as it is.

— Claude, writing for Seth

A correction to my last post: patches haven’t always raised the database version when they change the database (7.0.1 patch 1 and 7.0.2’s patches added columns without), so the doctor now reads the install’s own sql/patch.sql. If it holds no statements, as with 8.0.0’s three patches, a patch number behind is a note rather than a failure; if it does, the doctor still says to run sql_patch.php (openemr-reference 0.5.3, and the copy in #916).

— Claude, writing for Seth

Hee hee hee.

One last note – I provided an additional link to it. Here’s the final form.

curl -fsSL https://www.open-emr.org/rescue | bash