# Deploying webmobic (Next.js main site) to the hosting — how it was done on 2026-09-17

Hosting: cPanel account `mobichosting` on panel.mobic-host.com (SSH port 48291, key in `..\ssh\`).
App root: `~/nemour-app` (Passenger/LiteSpeed via `~/public_html/.htaccess`, Node 22 from `~/nodevenv/nemour-app/22`).
The live server is the SOURCE OF TRUTH for editable state: `content/**`, `.env.local`, uploads in `public/images`.
Code (src, .next, node_modules, package.json) comes from this repo.

Steps:
1. Diff first: md5 inventories of content/, public/, src/ on both sides (script in session files/deploy-webmobic).
   On 09-17: 103 files differed (code), 17 hosted-only (5 content JSON, 11 uploads, favicon), 30 local-only (new features).
2. Backup on the server: `tar czf ~/backups/nemour-app-pre-deploy-<ts>.tar.gz nemour-app public_html/.htaccess`
   (exclude node_modules/.next.bak*) + a plain copy of content/.env.local/public/images under ~/backups/editable-<ts>.
3. Sync hosted editable state INTO the local tree before building (content JSON + uploads), so prerendered HTML
   matches production. Arabic-digit filenames: use Python tarfile, not Windows tar (mojibake).
4. Build: `npm ci; npm run build` (output: standalone). Copy `.next/static` into `.next/standalone/.next/static`.
   Pack `.next/standalone` with Python tarfile (PAX, utf-8), drop root junk. ~80 MB.
5. On the server: extract to `~/nemour-app.new`, overlay live `content/`, `.env.local`, `public/images` (cp -an),
   smoke-test on a private port, then `mv nemour-app nemour-app.bak-<ts>; mv nemour-app.new nemour-app`.
6. Point `.htaccess` PassengerAppRoot at the new dir, `pkill -f next-server`, warm up.

INCIDENT (09-17 13:50-14:17): after the swap the account hit its LVE limit (nproc 100/100) and every request hung;
SSH was refused ("Connection reset" right after auth). Cause: 12 `next-server` instances × 8 threads — LiteSpeed
spawned new instances while old ones from previous deploys (up to 48 days old, orphaned) stayed alive.
Recovery without a shell: UAPI Fileman (edit .htaccess / write files) + an Exim PIPE forwarder
(`unwedge@mobichosting.com -> |~/mobic-unwedge.sh`) which runs as the account OUTSIDE the LVE and can pkill.
Triggered by one SMTP mail. Removed afterwards. Copy of the script: ~/backups/emergency-20260917/.
Mitigation now in .htaccess: `SetEnv NODE_OPTIONS "--v8-pool-size=1"` (8 -> 5 threads per instance).
ALWAYS `pkill -u mobichosting -f next-server` after a deploy so stale instances do not accumulate.

Rollback: edit .htaccess PassengerAppRoot back to `~/nemour-app.bak-20260917-134057`, pkill next-server.
Locale fix shipped with this deploy: de/tr/ur `tabs_section.regions/countries` restored (were English/Arabic).