Linux File System Hierarchy
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
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
15 Mar 2026
Edited
22 Mar 2026
Views
23
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 0
No pings yet today
No pings yesterday
Amazonbot 6
Perplexity 4
Unknown AI 3
Ahrefs 2
Google 2
SEMrush 1
Also referenced
How they use it
crawler 16
crawler_json 1
pre-tracking 1
Related categories
⚡
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