From 3b4014b5e40af42e2b7fa2a3bdd703cfc5682dc5 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 22 Mar 2026 14:10:19 +0100 Subject: [PATCH] basic frankenphp support fixes #17 --- nix/image/bootstrap.sh | 7 +++ nix/image/configs/supervisor/frankenphp.conf | 3 ++ nix/image/configs/supervisor/nginx.conf | 2 + nix/image/configs/supervisor/php-fpm.conf | 2 + nix/image/configs/supervisor/supervisord.conf | 7 --- nix/image/haze.nix | 7 +++ nix/image/php-ext.nix | 44 +++++++++++++++++++ nix/image/php.nix | 35 +-------------- src/service.rs | 17 +++++++ 9 files changed, 83 insertions(+), 41 deletions(-) create mode 100644 nix/image/configs/supervisor/frankenphp.conf create mode 100644 nix/image/configs/supervisor/nginx.conf create mode 100644 nix/image/configs/supervisor/php-fpm.conf create mode 100644 nix/image/php-ext.nix diff --git a/nix/image/bootstrap.sh b/nix/image/bootstrap.sh index 51bfa68..ce3d0e3 100755 --- a/nix/image/bootstrap.sh +++ b/nix/image/bootstrap.sh @@ -84,4 +84,11 @@ if [ -n "${PROXY_BASE:-}" ]; then cp /etc/supervisor/dnsmasq.conf /etc/supervisor/enabled/ fi +if [ -n "${FRANKENPHP:-}" ]; then + cp /etc/supervisor/frankenphp.conf /etc/supervisor/enabled/ +else + cp /etc/supervisor/php-fpm.conf /etc/supervisor/enabled/ + cp /etc/supervisor/nginx.conf /etc/supervisor/enabled/ +fi + exec supervisord -c /etc/supervisor/supervisord.conf \ No newline at end of file diff --git a/nix/image/configs/supervisor/frankenphp.conf b/nix/image/configs/supervisor/frankenphp.conf new file mode 100644 index 0000000..8c1b1e5 --- /dev/null +++ b/nix/image/configs/supervisor/frankenphp.conf @@ -0,0 +1,3 @@ +[program:frankenphp] +command = /bin/frankenphp php-server +directory = /var/www/html \ No newline at end of file diff --git a/nix/image/configs/supervisor/nginx.conf b/nix/image/configs/supervisor/nginx.conf new file mode 100644 index 0000000..957e4b3 --- /dev/null +++ b/nix/image/configs/supervisor/nginx.conf @@ -0,0 +1,2 @@ +[program:nginx] +command = /bin/nginx -c /etc/nginx.conf diff --git a/nix/image/configs/supervisor/php-fpm.conf b/nix/image/configs/supervisor/php-fpm.conf new file mode 100644 index 0000000..69418c7 --- /dev/null +++ b/nix/image/configs/supervisor/php-fpm.conf @@ -0,0 +1,2 @@ +[program:php-fpm] +command = /bin/php-fpm --fpm-config /etc/php-fpm.conf diff --git a/nix/image/configs/supervisor/supervisord.conf b/nix/image/configs/supervisor/supervisord.conf index dee3c56..2fedc90 100644 --- a/nix/image/configs/supervisor/supervisord.conf +++ b/nix/image/configs/supervisor/supervisord.conf @@ -8,18 +8,11 @@ pidfile = /var/run/supervisord.pid file = /var/run/supervisor.sock chmod = 0777 - [rpcinterface:supervisor] supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [supervisorctl] serverurl = unix:///var/run/supervisor.sock -[program:nginx] -command = /bin/nginx -c /etc/nginx.conf - -[program:php-fpm] -command = /bin/php-fpm --fpm-config /etc/php-fpm.conf - [include] files = enabled/* diff --git a/nix/image/haze.nix b/nix/image/haze.nix index 8751e42..b78ec51 100644 --- a/nix/image/haze.nix +++ b/nix/image/haze.nix @@ -35,6 +35,7 @@ helix, python3Packages, dnsmasq, + frankenphp, }: let inherit (builtins) toString; inherit (lib) readFile getExe concatStringsSep splitString take; @@ -163,6 +164,12 @@ phpEnv phpEnv.packages.composer phpunit + (frankenphp.override { + php = php.withExtensions (import ./php-ext.nix { + inherit lib php; + enableBlackfire = false; + }); + }) ]; }; in diff --git a/nix/image/php-ext.nix b/nix/image/php-ext.nix new file mode 100644 index 0000000..2715cf2 --- /dev/null +++ b/nix/image/php-ext.nix @@ -0,0 +1,44 @@ +{ + lib, + php, + debug ? false, + enableBlackfire ? true, +}: let + inherit (builtins) compareVersions; + inherit (lib) optionals; + withBlackfire = enableBlackfire && !debug && ((compareVersions php.version "8.1.0") == 1); +in + { + enabled, + all, + }: + enabled + ++ (with all; + [ + xdebug + excimer + inotify + redis + oci8 + zip + pdo + pdo_pgsql + pdo_sqlite + pdo_mysql + pgsql + intl + curl + mbstring + pcntl + ldap + exif + gmp + apcu + ffi + ] + ++ optionals (!debug) [ + smbclient # this breaks the build for no apparent reason + ] + ++ optionals withBlackfire [ + blackfire + ]) diff --git a/nix/image/php.nix b/nix/image/php.nix index 4fa7ff6..4922655 100644 --- a/nix/image/php.nix +++ b/nix/image/php.nix @@ -8,40 +8,7 @@ withBlackfire = !debug && ((compareVersions php.version "8.1.0") == 1); in php.buildEnv { - extensions = { - enabled, - all, - }: - enabled - ++ (with all; - [ - xdebug - excimer - inotify - redis - oci8 - zip - pdo - pdo_pgsql - pdo_sqlite - pdo_mysql - pgsql - intl - curl - mbstring - pcntl - ldap - exif - gmp - apcu - ffi - ] - ++ optionals (!debug) [ - smbclient # this breaks the build for no apparent reason - ] - ++ optionals withBlackfire [ - blackfire - ]); + extensions = import ./php-ext.nix {inherit lib php debug;}; extraConfig = '' xdebug.mode=debug,trace,profile xdebug.start_with_request=trigger diff --git a/src/service.rs b/src/service.rs index 67325c3..49bb636 100644 --- a/src/service.rs +++ b/src/service.rs @@ -207,6 +207,19 @@ impl ServiceTrait for RedisTls { } } +#[derive(Clone, Eq, PartialEq, Debug)] +pub struct FrankenPhp; + +impl ServiceTrait for FrankenPhp { + fn name(&self) -> &str { + "franken-php" + } + + fn env(&self) -> &[&str] { + &["FRANKENPHP=1"] + } +} + #[derive( Copy, Clone, Debug, PartialEq, EnumString, EnumMessage, EnumIter, IntoStaticStr, Display, )] @@ -281,6 +294,8 @@ pub enum ServiceType { Redis, /// External redis instance with TLS RedisTls, + /// Use FrankenPHP instead of PHP-FPM + FrankenPhp, } #[enum_dispatch] @@ -310,6 +325,7 @@ pub enum Service { Mail(Mail), Redis(Redis), RedisTls(RedisTls), + FrankenPhp(FrankenPhp), Preset(PresetService), } @@ -352,6 +368,7 @@ impl Service { ServiceType::Mail => Some(vec![Service::Mail(Mail)]), ServiceType::Redis => Some(vec![Service::Redis(Redis)]), ServiceType::RedisTls => Some(vec![Service::RedisTls(RedisTls)]), + ServiceType::FrankenPhp => Some(vec![Service::FrankenPhp(FrankenPhp)]), } } else { presets