Skip to content

Reference

Architecture

The root worker, customer isolation, network exposure, DNS, mail and backups.

Updated 2026-11-20 Edit this page on GitHub ↗

The stack#

Component Role Why this one
FrankenPHP Front web server for every site and the panel (TLS, HTTP/2, HTTP/3 on :2083, routing) + the panel's own PHP Caddy-based, automatic HTTPS built in
PHP-FPM The customer sites' PHP: one master per PHP version, one pool per hosting account, as that account's own Linux user Process-level isolation between accounts, and between accounts and the panel
nginx (jinnpanel-static@<account>) Each account's static files, served as that account, with a per-domain compressed response cache Caddy (running as frankenphp) never reads customer file contents
MariaDB Database (panel's own state + every customer database) Standard, well-understood, MySQL-wire-compatible
Stalwart Mail SMTP, IMAP, POP3, JMAP, ManageSieve; DKIM signing, spam filtering Single Rust binary combining what used to be Postfix+Dovecot+OpenDKIM+Rspamd, with a structured management API instead of flat config files
SFTPGo SFTP/SCP server Virtual users managed via REST API; each login writes as its account's Linux user
Knot DNS Authoritative DNS Fast, scriptable via knotc, used for every zone this panel serves
Valkey Object cache (Redis-compatible) One ACL login per account, limited to its key prefix
Cypht Webmail at mail.<domain> PHP, runs in its own FrankenPHP as user webmail
phpMyAdmin Database admin for customers Its own FrankenPHP on loopback, reached through the panel's single sign-on
fail2ban SSH brute-force protection sshd + recidive jails, firewalld actions

All of them run as systemd services on one AlmaLinux box. JinnPanel itself is a plain-PHP application (no framework, no Composer) deployed to /var/www/hostpanel (root-owned, readable by frankenphp only), served by FrankenPHP as its own vhost (panel.<hostname>, and <domain>:2083).

The one architectural decision that shapes everything else#

FrankenPHP's process is deliberately sandboxed, and that sandbox blocks things a hosting panel normally needs to do. Two separate, verified restrictions:

  1. ProtectSystem=full in FrankenPHP's systemd unit makes /etc read-only for the whole process tree (including anything it forks). It genuinely cannot write php.ini, my.cnf, or any other /etc config file itself. 2. SELinux denies httpd_t (FrankenPHP's domain) from talking to systemd over D-Bus at all - systemctl restart, journalctl -u, even systemctl is-active for other units all come back "Access denied." This is intentional confinement, not a misconfiguration to route around.
  2. A third, narrower one, verified by direct testing: forking a child process from FrankenPHP that then connect()s to a Unix domain socket reliably fails with EPERM - specifically that combination. The identical command succeeds via plain php-cli, via nsenter into the exact same mount/PID namespaces, and whether run in the foreground or backgrounded. Only an actual fork() from FrankenPHP's own process hits it. (SELinux was ruled out directly - the failure persists with SELinux in fully permissive mode.) This is very likely a FrankenPHP/Go-runtime quirk around forking children from a multi-threaded Go process with an embedded PHP SAPI, not anything specific to this deployment. It's why Knot DNS's knotc (Unix socket) can't be called directly from the app, while curl calls to Stalwart/SFTPGo (plain HTTP/TCP, no forking) work fine as normal PHP code.

The fix, consistently applied everywhere it's needed: a small PHP script (app/worker/hostpanel-worker.php) that a systemd timer runs every 5 seconds - as root, spawned by PID 1, completely outside FrankenPHP's process tree. The web app never does privileged work itself; it drops a small JSON "job" file into storage/config-queue/, and the worker picks it up, applies it, and deletes the job file. Every "Save & restart X" button, every DNS zone, every account/site change goes through this queue.

The worker trusts job files as little as possible: each is signed (HMAC with a key derived from APP_KEY, SystemWorkerService::enqueue), must be a regular file owned by frankenphp or root (never a link), and each job type validates its own input - settings jobs accept only a fixed list of keys with a value shape each (INI_KEYS, MYCNF_KEYS, SFTPGO_KEYS); account jobs carry only an id and the worker reads everything else from the database.

This also solves the read side: since FrankenPHP can't read the systemd journal either, the same worker snapshots each service's last 200 journal lines into /var/lib/jinnpanel/worker/live-<service>.log every cycle, which the WHM dashboard just reads as a plain file. Everything root writes for the panel (job logs, snapshots, the PHP extension list) goes to that root-owned folder - never into storage/, which frankenphp can write (a link planted there would aim root's writes anywhere).

Customer isolation#

Every hosting account is a Linux user, jp_<username> (UID 20000+, no shell, locked password), created and kept in line by the worker's accountSync (job account_sync, run on every account/domain change and by install.sh):

  • Files. /var/www/<domain> belongs to the account, mode 0750, plus an ACL letting frankenphp in (Caddy checks which files exist; it doesn't serve them - see Static files) - other accounts can't even list it. A folder the panel or a migration created is handed over (chown -R -P -h, no world-writable bits). /var/www itself is root:frankenphp 1775: the panel may create new site folders, the sticky bit stops it from renaming anyone else's.
  • PHP. Each PHP version is one PHP-FPM master (jinnpanel-php-fpm@default, @82, ...; template unit from install.sh, config in /etc/jinnpanel/php-fpm/<tag>/), with one pool per account: user = jp_<name>, socket /run/jinnpanel-php/<tag>/<name>.sock that only frankenphp can open, open_basedir = the account's site folders, its page-cache folders, its private home (/var/lib/jinnpanel/php/<name>: sessions, temp files) and the panel's per-site settings, plus disable_functions for exec/proc_open & co. unless an admin allows them per account (WHM > Accounts, users.php_exec). OPcache is shared per master, with opcache.validate_permission and opcache.restrict_api. The FPM binary is labelled httpd_exec_t, so it runs as httpd_t like FrankenPHP and EL's own php-fpm.
  • Static files. Caddy never sends a customer file itself: every non-PHP request goes to the account's own static server, jinnpanel-static@<name> - nginx running as jp_<name>, config from staticServerSync in /etc/jinnpanel/static/<name>.conf, sockets in /run/jinnpanel-static/<name>/ (only frankenphp may connect). It reads files with the account's rights only, so a link in a site folder pointing at another account's files or the panel's gets nothing, and it refuses links to files the account doesn't own (disable_symlinks if_not_owner). Caddy passes the effective document root (X-JP-Root, checked against the account's own site folders) and the domain's cache lifetime (X-JP-TTL). In front of the files sits a per-domain response cache of gzip-compressed copies (/var/lib/jinnpanel-static-cache/<name>/<domain>, 32 MB each; cPanel > Cache > Static file cache: on/off, lifetime, clear; File Manager changes clear it). Caddy still opens files to see whether they exist (try_files, file matchers), hence its read ACL - but it never serves their contents.
  • Vhosts. VhostService renders php_fastcgi <pool socket> + a reverse_proxy to the static server where sites used to say php_server/file_server; routing rules translated from .htaccess still say php_server (the editor's language) and are rewritten on render (VhostService::fpmRules; handle_errors pages keep their status through copy_response <code>). A suspended account's sites answer 503, one over its monthly bandwidth 509.
  • The panel acting on customer files. The panel can only read into site folders, so file work (File Manager, Exposed files, Routes' .htaccess scan, clearing OPcache) runs inside the account's own pool: PoolClient sends a FastCGI request (FastCgi) to the pool's socket for runtime/pool-agent.php (installed root-owned in /usr/local/lib/jinnpanel/pool/ with the classes it uses). The agent refuses anything without the JINNPANEL_AGENT FastCGI parameter, which a web request can't carry. Files it writes belong to the account.
  • SFTP. Logins are SFTPGo virtual users whose uid/gid are the account's; SFTPGo holds CAP_CHOWN/CAP_FOWNER/CAP_DAC_OVERRIDE (unit drop-in) to write as them. Account-wide logins see each site as /<domain> (SFTPGo virtual folders). - Cron. jinnpanel-cron runs as root and starts each PHP job as the account's user with the pool's limits (CronService::phpCommand).
  • Elsewhere. Caddy's admin API is a Unix socket (/run/frankenphp/admin.sock, frankenphp only) - on 127.0.0.1:2019 any local process could load a new config. Config.php is root:frankenphp 0640. Valkey logins are per account (key prefix); MySQL users per account.

Deleting an account removes its pools and Linux user and moves its site folders to /var/lib/jinnpanel/removed/ (root-only) - left in place they'd belong to a bare UID the next account could be given.

Network exposure#

Only the service ports customers need are open in firewalld (web 80/443, the customer panel 2083, DNS 53, mail 25/465/587/993/995/4190, SFTP 2022, SSH 22). Every admin or internal interface listens on loopback or a Unix socket only: MariaDB, Stalwart's HTTP/JMAP admin API (127.0.0.1:8080 and :8443), SFTPGo's web admin/REST API (127.0.0.1:8090 - SFTPGo can write as any account, so its API is close to root on files), Valkey, the webmail and phpMyAdmin FrankenPHPs, and Caddy's admin API (/run/frankenphp/admin.sock). The installer binds and firewalls them that way on every run.

The customer panel on every domain#

Customers reach the panel at https://<their domain>:2083 (and <domain>/jpanel redirects there), served by the same FrankenPHP with each domain's own certificate. Because cookies aren't scoped by port, site blocks strip the panel's session cookie from requests to the site itself, so a customer's PHP never sees a panel session. WHM and /setup are only served on panel.<hostname>.

Multiple PHP versions#

Each additional PHP version (8.2/8.3/8.4 alongside the default 8.5) is its own PHP-FPM master, jinnpanel-php-fpm@<82|83|84>. install_php_version (run by the worker, not the web app):

  1. Resolves the exact RPM URLs for that version's php-zts-fpm, php-zts-cli and common extension packages from the upstream static-php repo via dnf repoquery --disable-modular-filtering (bypassing dnf module, which is exclusive-per-stream and would replace the default version's packages).
  2. Extracts them (rpm2cpio/cpio, not rpm -i) into /opt/php-versions/<version>/ (php-fpm, php, modules/, conf.d/, its own php.ini), labels php-fpm httpd_exec_t, and checks it runs.
  3. Starts its master with a unit drop-in pointing at that binary and ini.

A domain on that version gets its account's pool in that master (accountSync writes one pool file per version the account uses); its cron jobs use that version's CLI.

AutoSSL#

Each domain has an ssl_mode: self_signed (Caddy's local dev CA - works immediately, browsers warn once) or letsencrypt (the vhost simply omits the tls internal line, handing the domain to Caddy's own automatic HTTPS engine). There's no custom ACME code here - Caddy's automatic HTTPS is mature and does the whole thing itself once a domain block exists without an explicit tls directive. The only real-world requirement, which no panel can shortcut: the domain has to actually resolve to this server publicly, with ports 80/443 reachable, for Let's Encrypt's HTTP-01 challenge to succeed.

DNS#

The panel database is the source of truth (dns_zones, dns_records, panel_settings); zone files are rendered from it. Every change goes through DnsService::publish(): bump the serial, queue a dns_write job with the full zone text. The root worker writes /var/lib/knot/<zone>.zone, registers the zone in Knot if needed, runs knotc -b zone-reload, and restores the previous file if Knot rejects the new one. After any registration it writes the live zone list to /etc/knot/zones.conf (included from knot.conf), so zones survive a restart.

SOA, apex NS and glue for ns1/ns2 come from the nameserver settings and are never stored as records. Records the panel maintains itself carry a managed tag (mail: MX/SPF/DKIM/DMARC/autoconfig/SRV; ipv6: AAAA next to each A pointing here; site: subdomain sites as records in their parent zone) and are re-synced as a set; a customer record with the same name wins. The server zone (the hostname's parent) holds ns1/ns2, the hostname and panel.<hostname>, and can't be deleted.

Mail#

Stalwart holds the mailboxes; the panel drives it over JMAP on loopback (MailService, StalwartAdminService). Notes that shape the code:

  • Stalwart 0.16 takes no credentials in an account create: the panel creates the account, then patches credentials/0 (one password per account). Hashes imported from cPanel ($6$, $1$, bcrypt) are accepted as they are.
  • The panel acts on a mailbox through Stalwart's master login (<address>%<admin>). Forwarders are mailing lists (for addresses with no mailbox) or the mailbox's single panel-managed Sieve script, which also holds the autoresponder (Stalwart runs one active script per mailbox).
  • Each mail domain gets DKIM keys (RSA + Ed25519) and its DNS records (managed = 'mail'). The hourly jinnpanel-mail-dns.timer re-syncs them, serves autoconfig/autodiscover/MTA-STS through Caddy (zz-mail-services.caddyfile: MTA-STS proxied to Stalwart on loopback, autoconfig/autodiscover answered by the panel's AutoconfigController with mail.<domain>), copies Caddy's certificates to Stalwart (the hostname's as the default, each mail.<domain>'s picked by SNI), and keeps the 587 listener.
  • Suspension removes the authenticate permission from the account's mailboxes.

Backups#

BackupService, run by the worker as transient units (jinnpanel-backup-all daily at the configured hour, jinnpanel-backup-<id> on demand): per account, site files (tar), each database (dump) and mail (read over IMAP) as separate parts; for the server, the panel database and the services' configuration. Kept in /var/backups/jinnpanel for N days, optionally copied to S3-compatible storage (signed requests, credentials encrypted with APP_KEY). Restores are per part; restored files are given back to the account's Linux user.

Usage, quotas and suspension#

UsageService runs hourly (and at boot via jinnpanel-usage-boot): it measures files, databases and mail per account and the month's bandwidth from the access log (read by StatsCollector, below), stores them in account_usage and each day's disk use in stat_account_daily, and:

  • over the disk quota: the panel refuses uploads and new databases, mailboxes and domains;
  • with XFS user quotas on (rootflags=uquota, installer option JINNPANEL_XFS_QUOTA=1): sets the package's disk quota as a hard limit on the account's Linux user (files only; databases and mail are counted but limited softly);
  • over bandwidth: re-renders the account's vhosts to answer 509.

Statistics#

StatsCollector runs in the root worker and fills the stat_* tables (migration 026) that the dashboards and each domain's Stats tab read:

What When Table Kept
Load, CPU, memory, disk, network of the server every minute stat_server 32 days Whether each service's port answers, and how fast every minute stat_service_checks 32 days Requests, bytes, pages, visitors, status classes, page time per domain every 5 minutes, per hour stat_domain_hourly 95 days Top pages and referring sites per domain every 5 minutes, per day stat_domain_top 95 days (50 per day) Disk use, bytes served and requests per account hourly / every 5 minutes, per day stat_account_daily 400 days

The access log is read in one place, StatsCollector::ingest with the parser AccessLogStats: from where it stopped (following a rotation into the rolled file, compressed or not), for at most 20 seconds a run, under a lock. The bytes it counts are handed to UsageService for the month's bandwidth. On a laptop the parser reads about 50,000 lines (35 MB) a second (dev/stats/bench.php), so a server serving 100 requests a second needs well under a second every 5 minutes.

No IP address is stored. A visitor is the first 8 bytes of SHA-256(salt, address, browser), with a random salt per day kept only in root's /var/lib/jinnpanel/stats-salt and deleted the next night, along with that day's hashes (stat_visitors): visitors can be counted per day but not recognised again, and a hash can't be turned back into an address. Requests from bots (by their browser name) count as requests but not as visitors.

SuspensionService turns an account off everywhere at once: sites answer 503 and its PHP pools stop, mail logins are refused, SFTP logins disabled, MySQL users locked, the Valkey login disabled, cron jobs skipped and its panel sessions ended. Unsuspending reverses each step.

Server Config / Stalwart settings#

Stalwart has no fixed REST API for its system settings objects (thread pool size, cache sizing, spam thresholds, TLS reporting, ...) - the same structured system its own setup wizard uses is exposed at /api/schema (a JMAP session + a generic {ObjectName}/get and {ObjectName}/set per object). StalwartAdminService talks that protocol directly and ServerConfigController's mail settings pages render a form generated from the live schema - one code path covers every object rather than hand-building forms for each. WHM shows the 27 objects listed in StalwartAdminService::SETTINGS_GROUPS (server, web & API, mail protocols, security & spam, storage, reporting); adding another is one line, no form code. Simple field types (string/number/ boolean/enum) get real inputs; structural types (object/list/set/map) fall back to a raw-JSON textarea, still fully editable.

cPanel migrations#

WHM > cPanel Migration (full guide: docs/MIGRATION.md) follows the same "privileged or long-running work never happens inside a FrankenPHP request" rule as everything else, one step further. MigrationController only validates input and records a migrations row plus one migration_items row per account; MigrationService queues a migration_start job; hostpanel-worker.php turns that into a transient systemd unit (jinnpanel-migration-<id>) running app/worker/migration-runner.php as frankenphp - not root, because everything it unpacks came from another server, and not a FrankenPHP child, because a single account can take hours. It creates the new site folders itself; at the end it asks for an account_sync, which hands the files to the account's Linux user and starts its PHP pool, and only then creates the account's SFTP logins (they write as that user).

MigrationRunner then, per account: asks the source for a full backup through CpanelApiClient (WHM API 1 / UAPI, with uapi_cpanel proxying UAPI calls for reseller and root logins), receives it by download (pull) or via a single-use SFTPGo user (push), extracts it, and restores it through CpanelBackupReader (which validates every name and path in the backup) using the same services the panel already uses - VhostService, DnsService, ProvisioningService, MailService - plus MailImportService for stored mail over JMAP. Progress is written to the item rows and a per-migration log, a heartbeat detects a dead runner, and AccountCleanupService (shared with WHM > Accounts > Delete) rolls back a half-restored account. Source credentials are encrypted with Crypto (AES-256-GCM, key Config::APP_KEY) and wiped when no longer needed.

Data model#

MariaDB hostpanel database: users (role: admin/reseller/user, with parent_id scoping a user to the reseller who created them), packages (quotas; owner_id NULL = global, else a reseller's own custom package), domains (+ php_version, php_port, ssl_mode), db_instances, email_accounts, ftp_accounts, php_versions (installed alt PHP versions), activity_log (the audit trail), login_attempts (sign-in throttling), account_usage (measured disk/bandwidth), backups, plus migrations / migration_items (cPanel migrations and their per-account progress and reports) and db_user_accounts (extra MySQL users an account owns - a migrated cPanel account can have several users per database and several databases per user, so db_instances.db_user isn't unique).

Two separate MariaDB accounts back the app: hostpanel_app (least privilege, scoped only to the hostpanel database itself) and hostpanel_prov (a narrower, explicitly-scoped set of privileges - NOT ALL PRIVILEGES - used only by ProvisioningService to create/drop per-customer databases and users; it can only re-grant privileges it itself holds, which is why customer databases get a specific privilege list rather than GRANT ALL).

Security posture#

  • Customer code runs as its own account's Linux user in its own PHP-FPM pool - see Customer isolation above.
  • Every mutating request goes through Csrf::requireValid(); logout is a POST too.
  • Sign-in: bcrypt (password_hash); throttled (LoginThrottle: 5 failures per username and address, or 20 per address, in 15 minutes); optional TOTP two-factor (Totp, RFC 6238, codes single-use) for every role; sessions end after 2 hours idle / 12 hours, on password or two-factor changes (users.session_version) and when the account is suspended. Roles are read from the database on every request, never trusted from the session. New passwords need 10+ characters and aren't common ones.
  • /setup (creating the first admin) needs the one-time token install.sh prints.
  • The panel is HTTPS only (http://panel.<host> redirects) with HSTS, CSP, X-Frame-Options: DENY, nosniff, Referrer-Policy; session cookies are always Secure, HttpOnly, SameSite=Lax.
  • Usernames that would collide with the panel's own identities (Linux users, hostpanel_* MySQL users, ...) are refused (Usernames); domain names that belong to the server, to another account (or sit above/below one), or are public suffixes are refused (DomainPolicy). - Role checks are server-side on every controller action (Auth::requireRole), plus row-level scoping (a reseller only sees rows where parent_id matches them; a user only sees their own domains/databases/etc).
  • File work on customer files happens as the customer (pool agent), and FileManagerService still resolves every path and keeps it inside the site folder, never following links out of it.
  • SQL is parameterized everywhere except a handful of identifiers (database/table/user names) that MySQL doesn't allow to be bound parameters at all - those go through a strict ^[a-zA-Z][a-zA-Z0-9_]{1,62}$ allow-list first. - hostpanel_prov's grant to customer accounts deliberately excludes CREATE ROUTINE/TRIGGER/VIEW/etc - it hands out exactly the privileges it itself has, nothing broader.
  • Every panel action and sign-in is in the audit trail (WHM > Activity Log): who, what, which account, from which address.
  • SSH brute force: fail2ban (sshd + recidive jails).
  • Admin APIs are never on a public port (see Network exposure).
  • Customer routing rules (translated .htaccess) are validated before they're written: no import, no root outside the docroot, no reverse_proxy and the like; the worker runs frankenphp validate and restores the previous rules on failure.
Esc