# Canonical production PHP identity

Applies to #3614 (NUHET-BACKEND-61), #3483 (NUHET-BACKEND-5Y), and the
earlier cache-directory incident #2470. Production root: /var/www/html.

## Required operating rule

Run **every production Artisan, Tinker and ad-hoc PHP command as www-data**.
This includes schedule:list, view rendering, diagnostic PHP, release
verification and scripts piped through stdin. Read-only application
diagnostics can create mutex directories or compiled views. The SSH login
nuhetftp is a deployment account; neither it nor root is a runtime account.

Apache uses PHP 8.3 FPM with pool user/group www-data. The production
scheduler runs from the www-data crontab. No required non-www-data runtime
writer was found. Existing www-data-owned directories/files at 0755/0644
are writable by the canonical owner; they do not need a mass repair.
Do not broaden bootstrap umask, cache permissions or shared FPM settings
to accommodate an operator's ad-hoc PHP.

Use the approved Nuhet SSH sudo transport. With ssh_run sudo=true, the
outer command runs as root; still switch the PHP child to www-data:

    cd /var/www/html
    sudo -u www-data -- php8.3 artisan <approved-command>
    sudo -u www-data -- php8.3 artisan tinker <approved-options>
    sudo -u www-data -- php8.3 < /path/to/reviewed-script.php

For a reviewed stdin stream, pipe into sudo -u www-data -- php8.3.
For example, this copy-paste stdin diagnostic only prints the PHP version:

    printf '%s\n' '<?php echo PHP_VERSION, PHP_EOL;' | sudo -u www-data -- php8.3

Check the selected Unix identity with sudo -u www-data -- id, and inspect
runtime ownership using the find/stat preflight below.
Keep Git/bundle deployment separate from runtime PHP. Do not run
php artisan config:cache.

## Evidence and attribution

Read-only production inspection on 2026-10-13 confirmed FPM/scheduler
identity www-data, SSH identity nuhetftp with primary group nuhetftp and
supplementary www-data, FPM umask 0022 and SSH shell umask 0002.

The October 8 failure has a documented operator cause:

- docs/ops/automatic-replies-3416-production-release.json records that
  php artisan schedule:list as nuhetftp created a forward-lock directory
  at 15:26:35 CEST (13:26:35 UTC), preventing the runtime from creating its
  lock. docs/ops/automatic-replies-3416-root-recovery.md names cache/83/9e,
  its exact narrow repair at 13:39:44 UTC, and clean 15:40-15:42 CEST cron.
- #3483's exact warning recurred each minute from 13:27 through 13:39 UTC
  on 2026-10-08, matching that operator-created directory incident. Its leaf
  cache file has expired; current stat cannot recover its historical owner.
- #3614's 2026-10-12 13:05:49 UTC live stack ends with
  Standard input code(11): View->render(). Its current compiled file is
  www-data:www-data 0644, unwritable by nuhetftp. The stack proves a stdin
  render, but does not record the historical effective Unix UID.

The five remaining wrong-group nodes below predate today's sibling sessions:
the two directory mtime/ctime values are October 8 13:40:13 UTC; one file
is August 26 and two are September 4. None of the nuhetftp-owned framework
nodes was newly modified on October 13 at inspection. Today's sessions
did not create these five nodes; their individual earlier creators cannot
all be attributed. This session created no live nodes. Existing tracked
.gitignore ownership is not part of the runtime repair.

The two directories repaired under #2470 already have group www-data and
remain runtime-writable. Preserve every existing cache value, especially
callback idempotency claims.

## Proposed five-node repair: supervising root only

These are production writes for root approval/execution at release time.
Freshly inspect these exact nodes first. Directories must be real
non-symlink directories at 0775 nuhetftp:nuhetftp; files must be real
non-symlink files at 0664 nuhetftp:nuhetftp. If a node expired, disappeared
or changed ownership, reassess the exact target; do not recreate it or
widen the repair. Obtain a fresh readback rather than trusting old output.

Read-only preflight:

    cd /var/www/html
    find storage/framework/cache storage/framework/views -xdev \
      -user nuhetftp -group nuhetftp -printf '%y %m %u:%g %p\n'
    TZ=UTC stat -c '%a %U:%G %y %n' \
      storage/framework/cache/dc/f9 \
      storage/framework/cache/cb/ff \
      storage/framework/cache/ee/2f/ee2f842aa7bb1f53edf3a2ed2c09a1807ffa6c90 \
      storage/framework/cache/c2/4f/c24f92750673b2169c8cb7bfbc999cfa8457dc7c \
      storage/framework/cache/44/d1/44d142505dd1a3b497197e2f459d2aec779e9ed6

Proposed exact nonrecursive mutation block, as root after preflight approval:

    set -eu
    cd /var/www/html
    chown www-data:www-data \
      storage/framework/cache/dc/f9 \
      storage/framework/cache/cb/ff \
      storage/framework/cache/ee/2f/ee2f842aa7bb1f53edf3a2ed2c09a1807ffa6c90 \
      storage/framework/cache/c2/4f/c24f92750673b2169c8cb7bfbc999cfa8457dc7c \
      storage/framework/cache/44/d1/44d142505dd1a3b497197e2f459d2aec779e9ed6
    chmod 0775 storage/framework/cache/dc/f9 storage/framework/cache/cb/ff
    chmod 0664 \
      storage/framework/cache/ee/2f/ee2f842aa7bb1f53edf3a2ed2c09a1807ffa6c90 \
      storage/framework/cache/c2/4f/c24f92750673b2169c8cb7bfbc999cfa8457dc7c \
      storage/framework/cache/44/d1/44d142505dd1a3b497197e2f459d2aec779e9ed6

Ownership of only these five nodes becomes www-data:www-data, matching the
runtime user/group; values and existing modes remain unchanged. Repeat the
exact stat preflight: modes must still be 0775/0664. Test -w/-x on these
exact nodes as www-data. Do not recursively chown/chmod storage, flush cache,
delete existing keys, or set file-cache permission to 0664 (the installed
Laravel applies the same option to hash directories, removing traversal).

## Proposed Nuhet SSH host-note addition

The supervising root obtains Jonathan's approval and appends this exact
block, preserving all existing notes. This session must not change notes.

Also replace deployment step 5 with this exact canonical-user form:

    5. Migrations only if the diff has them: sudo -u www-data -- php8.3 artisan migrate --force.

    PHP RUNTIME IDENTITY (mandatory; #3614/#3483): Every production Artisan,
    Tinker, diagnostic and ad-hoc PHP invocation, including schedule:list,
    view rendering and stdin-piped scripts, must run as www-data, matching
    Nuhet FPM and cron. The SSH login nuhetftp and sudo root must not run
    Laravel runtime PHP directly: even read-only diagnostics create cache
    mutex directories or compiled views. In /var/www/html use
    sudo -u www-data -- php8.3 artisan <approved-command>, or
    sudo -u www-data -- php8.3 < /path/to/reviewed-script.php; for a reviewed
    stdin stream, pipe into sudo -u www-data -- php8.3. With ssh_run sudo=true,
    still switch the PHP child explicitly to www-data. Keep Git/bundle
    deployment separate. Never run config:cache or flush/delete cache to
    repair ownership. Permission repairs require separate root approval and
    exact scoped targets; see docs/ops/storage-permissions.md.

## Live acceptance

After root reports the release/ops UTC boundary and approved note update:

1. Verify the five repaired node groups/modes and saved canonical-user note
   from fresh state. Inspect new cache/view files and their canonical owner.
2. Run reviewed PHP diagnostics/probes only as www-data. Coordinate a unique
   disposable cache/view fixture with root. Verify fresh cache/compiled-view
   writes, updates and atomic-add idempotency; clean up only that exact
   fixture. Never use real keys or a noncanonical identity for a write test.
3. Verify an ordinary application HTTP request and a naturally occurring
   scheduler run, including their files/logs. A CLI probe alone does not
   prove those paths. Use fresh files as evidence; an idle FPM process's
   request-time umask need not persist.
4. Inspect sudo-readable storage/logs/laravel-<date>.log for the exact cache/
   view Permission denied signatures since the UTC boundary. Logs use
   Stockholm local time; convert the boundary and read every date spanning
   the window.

Report immediate, VERIFY CHECK and FINAL CHECK results to root. Require
48 hours with zero recurrences after the approved operating rule and narrow
repair take effect. Report RECURRENCE #3614: immediately and resume
investigation on recurrence. Then record paired acceptance evidence/limits
and time calibration on both cards, and move them to Ready for Test; root
performs final completion. Sentry API access is unavailable; production
Laravel logs are the recurrence source of truth.

This PR changes documentation only: no runtime code, migrations,
configuration refresh or application tests are required.

The optional runtime-user warning guard is not added: the canonical-user
rule addresses the observed operator source without changing production
PHP behavior or warning/reporting paths.
