← Home ← Codex ← DEBT
Browse by Category
+ added · updated 7d
← Back to glossary

Linux File System Hierarchy

Linux Beginner
debt(d7/e5/b7/t7)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7). The detection_hints list lynis, namei, and ls-la — these are specialist audit/inspection tools that a developer must deliberately invoke; they won't catch wrong file placements during development or CI automatically. Wrong paths typically surface at runtime (session not writable, uploads lost on reboot, log rotation broken) rather than at compile or lint time, placing this firmly at d7 rather than d9 (which would be silent in production until users hit it — here, symptoms do appear relatively quickly in staging/testing).

e5 Effort Remediation debt — work required to fix once spotted

Closest to 'touches multiple files / significant refactor in one component' (e5). The quick_fix notes ownership/permission corrections for PHP-FPM, but the common_mistakes reveal that misplaced files span multiple concerns: upload directories, log paths, temp file usage, and hardcoded home paths. Correcting these requires updating configuration files (php.ini, FPM pool configs), application code that references paths, deployment scripts, and potentially log rotation configs — well beyond a one-liner but not a full architectural rework.

b7 Burden Structural debt — long-term weight of choosing wrong

Closest to 'strong gravitational pull' (b7). The misconception confirms that non-standard file locations break package managers, backup scripts, log rotation configs, and security policies. The applies_to covers both web and CLI contexts, meaning every deployment decision, every sysadmin script, and every tool integration is shaped by whether FHS conventions are followed. Violations create persistent cross-cutting debt where every new feature (logging, uploads, sessions) must work around the wrong baseline.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap — contradicts how a similar concept works elsewhere' (t7). The misconception is explicit: 'Files can go anywhere as long as they work.' This is a deeply intuitive belief for developers coming from Windows or containerised environments where paths are more flexible. The trap is that code works perfectly in development (local machine, single user, no log rotation, no backup scripts) but breaks in production in multiple subtle ways. This contradicts the developer's reasonable mental model that 'if it runs, it's fine,' making it a t7 rather than t9 (the obvious path isn't always wrong — it just fails in specific production contexts).

About DEBT scoring →

Also Known As

FHS directory structure filesystem hierarchy

TL;DR

The standard directory structure of Linux — /etc for config, /var for variable data, /tmp for temporary files, /usr for user programs — knowing it prevents misplacing files.

Explanation

FHS (Filesystem Hierarchy Standard) defines where things go: /etc (config files), /var (variable data — logs, spool, databases), /var/log (logs), /var/www (web content), /tmp (temp files, cleared on reboot), /usr/local (locally installed software), /home (user home dirs), /root (root home), /proc (virtual — kernel and process info), /sys (virtual — hardware info), /run (runtime data, cleared on reboot), /opt (optional/third-party software). PHP apps live in /var/www; logs go to /var/log; runtime files (PID, sockets) go to /run.

Common Misconception

Files can go anywhere as long as they work — non-standard file locations break package managers, backup scripts, log rotation configs, and security policies that assume standard paths.

Why It Matters

Placing PHP logs in /tmp (cleared on reboot) or PID files in /home (wrong permissions) causes hard-to-diagnose failures; FHS conventions exist so tools can find files reliably.

Common Mistakes

  • Writing temporary files to the app directory — use sys_get_temp_dir() or /tmp; app directory may not be writable.
  • Storing uploaded files in /tmp — /tmp is cleared on reboot; use /var/www/uploads or object storage.
  • Log files in the application root — they should go to /var/log/appname/ for log rotation and access control.
  • Hardcoding /home/username paths — breaks when deployed as a different user or on a different server.

Code Examples

✗ Vulnerable
// Files in wrong locations:
define('LOG_FILE',    '/tmp/app.log');         // Cleared on reboot!
define('UPLOAD_DIR',  '/tmp/uploads/');         // Cleared on reboot!
define('CONFIG_FILE', '/home/paul/app.conf');   // User-specific path
define('PID_FILE',    '/var/www/html/app.pid'); // Wrong — should be /run/
✓ Fixed
// Correct FHS locations:
define('LOG_FILE',    '/var/log/myapp/app.log');
define('UPLOAD_DIR',  '/var/www/myapp/uploads/');  // Persistent
define('CONFIG_FILE', '/etc/myapp/config.php');     // Standard config location
define('PID_FILE',    '/run/myapp/app.pid');        // Standard runtime location
define('CACHE_DIR',   sys_get_temp_dir() . '/myapp_cache/'); // Portable temp

Added 15 Mar 2026
Edited 22 Mar 2026
Views 52
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 2 pings W 1 ping T 2 pings F 1 ping S 0 pings S 5 pings M 1 ping T 0 pings W 1 ping T 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Scrapy 8 Amazonbot 7 Ahrefs 4 Perplexity 4 Unknown AI 3 Google 3 SEMrush 2 Claude 2 ChatGPT 2 Meta AI 1 Sogou 1 Majestic 1 Common Crawl 1 PetalBot 1
crawler 35 crawler_json 4 pre-tracking 1
DEV INTEL Tools & Severity
🟠 High ⚙ Fix effort: Medium
⚡ Quick Fix
PHP-FPM runs as www-data — ensure web-served files are owned by www-data or readable by it; never make the entire /var/www writable by www-data as a quick fix
📦 Applies To
any web cli
🔗 Prerequisites
🔍 Detection Hints
chmod 777 on webroot as 'fix'; PHP-FPM cannot read files due to wrong ownership; session files not writable; upload directory not writable
Auto-detectable: ✓ Yes lynis namei ls-la
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Medium ✗ Manual fix Fix: Medium Context: File
CWE-732


✓ schema.org compliant