New Tools for Creating Portable and Customizable Distributions of OpenEMR for FreeBSD using QEMU on MacOS

Hey folks,

I've been working on a project to create self-contained, portable OpenEMR binaries and just added FreeBSD support. Thought the community might find it useful (or have feedback).

**What is it?**

OpenEMR is an open-source electronic health records system which I am a contributor to.

This project packages it into a portable distribution - PHP binary + PHAR archive + bundled shared libraries - that runs without needing to install PHP, Composer, npm, or any runtime dependencies.

**FreeBSD-specific approach:**

Unlike the Linux builds which use Docker, the FreeBSD build:

- Compiles PHP 8.5 directly from source with 35+ extensions
- Bundles required .so files (libiconv, libxml2, libssl, libicu*, etc.)
in a lib/ directory
- Sets LD_LIBRARY_PATH at runtime for true portability
- No containers, no jails - just native binaries

I went with bundled shared libs rather than fully static linking because the bundled approach seems cleaner for deployment anyway.

**Build environment:**

The build script uses QEMU to run a FreeBSD 15.0 VM - this lets anyone with a Mac build FreeBSD binaries without needing dedicated FreeBSD hardware. The entire process is automated via expect scripting (no manual VM interaction).

That said, the embedded build script can also run directly on a native FreeBSD system if you prefer.

The build script allows you to specify a FreeBSD version, an OpenEMR release tag and a PHP version as build arguments and it will auto-detect the CPU architecture you're currently running on to prepare a distribution specifically for that architecture. This should allow us to prepare portable distributions of OpenEMR for many different types of different FreeBSD installations.

**Links:**

- GitHub: https://github.com/Jmevorach/openemr-static-binary-forge/tree/main/freebsd
- FreeBSD build guide: https://github.com/Jmevorach/openemr-static-binary-forge/blob/main/freebsd/README.md
 
Here's a version of the static distribution I compiled using PHP 8.5 and FreeBSD 15 for ARM for OpenEMR version 7.0.3.4.


Now you can use FreeBSD to natively run the world's most popular open-source medical record

Right now I have binaries for aarch64 but in theory we should be able to compile the distro for both tier 1 FreeBSD platforms.

I'd be really curious if anyone had any success compiling it for RISCV!
 
Also wanted to say I've been really impressed with the performance of FreeBSD 15. The build for FreeBSD 15 generally completes faster than the macOS one even though it's running in QEMU on macOS and the build is being orchestrated by an Expect script written in TCL being run inside a Bash script.

I think we should be able to extend the core idea I implemented here to make pretty flexible build tools that could statically compile PHP applications on MacOS for usage on FreeBSD or on FreeBSD for FreeBSD.

I think ...

FreeBSD + Apache (PHP-FPM where we used these binaries as the PHP interpreter or mod_php where this binary was the PHP interpreter) + a PHP application compiled statically in this manner

Would allow one to serve an inordinate amount of traffic using a given hardware.

In the case of OpenEMR the ability to effectively serve the application well and affordably could have an impact on the health of many millions of people either directly through medical providers or indirectly through researchers who use OpenEMR to drive medical research.
 
Is there a port?
Untill there is, I think "porting new software" is a good home. And let's hole to see a port some day. And Jmevorach - welcome aboard.
 
Last edited:
Crivens Happy to be here!

I have a static distribution for FreeBSD I released here:

This will run on aarch64 FreeBSD 15. The build tools allow for us to make static binaries for aarch64, x86 and multiple versions of PHP and FreeBSD.

The method I created for packaging OpenEMR (a PHP application) could be applied to any PHP application.
 
Back
Top