In Linux web hosting, standard permissions set directories to chmod 755 and regular files to chmod 644, while chown assigns ownership to the site’s system user and web group. Restrict sensitive configuration files like wp-config.php or .env to 600 or 440, and never use 777.
One wrong chmod 777 command can expose credentials or break PHP-FPM execution across your entire account. Mastering Linux file permissions (755 directories, 644 files, and strict chown ownership) keeps web servers writable only where necessary.
Directories require execute bit (755) for traversal; files stay read-only to group/world (644).
Lock wp-config.php and .env files to 600 or 440 so neighboring users cannot read credentials.
World-writable permissions let compromised scripts inject webshells anywhere in your web root.
How Linux File Permissions Work: Read, Write, Execute & Octal Math
Every file and directory on a Linux filesystem (ext4, XFS, or ZFS) stores a 9-bit permission mask divided into three triads: Owner (User), Group, and Others (World). Each triad grants or denies three capabilities—Read (r = 4), Write (w = 2), and Execute (x = 1). Adding those numeric values together produces the three-digit octal code you pass to chmod.
When you run ls -la inside a web directory, the leftmost 10-character string reveals the file type and all three permission triads. A leading d indicates a directory, while a leading - indicates a regular file. Understanding how those bits behave differently on directories versus files prevents 90% of deployment headaches.
| Octal | Symbolic | Meaning for Files | Meaning for Directories |
|---|---|---|---|
7 |
rwx |
Read, modify, and execute as a binary or script | List contents, create/delete files inside, and traverse (cd) |
6 |
rw- |
Read and modify contents; cannot execute directly | List and modify entries, but cannot traverse into directory (broken!) |
5 |
r-x |
Read and execute; cannot modify or delete | List contents and traverse into directory; cannot create/delete files |
4 |
r-- |
Read-only access | List filenames only; cannot read file metadata or traverse |
0 |
--- |
No access (blocked for this triad) | No listing, no traversal, no writes |
Difference Between chmod 755 and 644 in Web Hosting
The difference between chmod 755 and 644 comes down to the execute bit (1). On Linux, the execute bit on a directory does not mean “run the folder as a program”—it grants search and traversal permission. Without +x on a directory, Apache or Nginx cannot resolve paths inside public_html/wp-content/uploads/, even if the files inside are world-readable. That is why directories must be 755 (rwxr-xr-x): the owner can read, write, and traverse, while the web server group and others can read and traverse.
Regular web files—such as index.php, style.css, and logo.webp—do not need to be executed directly by the Linux kernel because PHP-FPM or Apache reads them as text input. Setting regular files to 644 (rw-r--r--) lets the owner edit them and lets the web server read them, while blocking accidental execution of uploaded files.
Hardening wp-config.php, .env, and SSH Keys (600 & 440)
Files containing database passwords, API tokens, or private cryptographic keys should never remain world-readable (644). On shared hosting servers without CageFS isolation, a 644 configuration file can potentially be read by another local user if directory traversal is open. Restricting sensitive files to 600 (owner read/write only) or 440 (owner and web group read-only) closes that exposure:
- WordPress
wp-config.php: Set tochmod 600 wp-config.phpwhen PHP-FPM runs as the account owner, orchmod 440 wp-config.phpwhen the web server reads via group membership. - Laravel / Node.js
.env: Always setchmod 600 .envand ensure your web server blocks HTTP access to dotfiles. - SSH Private Keys (
~/.ssh/id_ed25519): OpenSSH strictly refuses to use private keys unless they arechmod 600and~/.sshitself ischmod 700.
Correct Permissions for public_html on Linux Hosting
A common mistake when uploading sites via FTP or extracting archives as root is leaving public_html with 750 or 700 permissions, or extracting files with 775/664 masks. On cPanel and DirectAdmin servers, the public_html folder itself often uses chmod 750 with group ownership set to nobody (the Apache user) so Apache can enter the folder while other local Linux users cannot.
Inside public_html, apply these standardized correct permissions for public_html linux recursively using find so directories and files are updated separately:
Note why we never run chmod -R 755 * or chmod -R 644 *: running 644 recursively strips the execute bit from every subdirectory and immediately takes your site offline with HTTP 403 errors. Running 755 recursively marks every image, CSS file, and upload as executable, triggering security scanner alerts and violating least-privilege hygiene. For a deeper look at how Apache and PHP-FPM interact with these files, see our LAMP stack architecture guide.
Understanding chown: User, Group, PHP-FPM, and suEXEC Models
While chmod defines what actions are allowed, chown defines who owns the file. In Linux web hosting, permission failures frequently happen when you edit files over SSH as root (leaving files owned by root:root) while the web server runs as www-data, apache, or a dedicated account user like alice.
Your required chown syntax depends on which PHP handler your hosting stack runs:
cPanel / DirectAdmin (suPHP / PHP-FPM per user)
PHP scripts execute as the cPanel account user (e.g., alice:alice). All files inside public_html should be owned by alice:alice, with public_html itself at 750 alice:nobody.
Ubuntu / Debian Nginx + PHP-FPM (Single VPS)
Default pools run as www-data:www-data. For single-tenant VPS deployments, run chown -R www-data:www-data /var/www/example.com/public_html or configure a dedicated pool user.
AlmaLinux / RHEL Apache + PHP-FPM
Default pools run as apache:apache. Deploying via a separate CI user requires either adding the CI user to the apache group or running a per-site PHP-FPM pool.
CloudLinux CageFS + LVE
Each tenant is jailed in a virtualized filesystem namespace where they only see their own UID/GID, preventing cross-account reads even if a file is 644.
When you deploy on secure Linux web hosting solutions with CloudLinux CageFS and per-user PHP-FPM pools, user isolation is enforced at the kernel level so your CMS can write uploads safely at 755/644 without exposing files to neighboring accounts.
Why chmod 777 Is Dangerous on Web Hosting Servers
Searching for a quick fix to “Unable to create directory wp-content/uploads” often leads to forum posts recommending chmod -R 777. Understanding why chmod 777 is dangerous on web hosting will keep you from ever using it in production:
- Arbitrary Write Access for Any Local Process: The third digit (
7) grants full Read, Write, and Execute rights to every user and daemon on the server. If a low-privilege service (such as an FTP helper, mail filter, or neighboring shared-hosting user) is compromised, it can overwrite yourindex.phpwith a credential-stealing script. - Immediate suPHP & CageFS Rejection (HTTP 500): Modern Linux hosting stacks actively block
777. Security modules like suPHP and mod_ruid2 refuse to execute PHP scripts that are world-writable or live inside a777directory, turning a working site into an instant500 Internal Server Error. - Malware Persistence & Executable Uploads: Marking upload folders
777allows attackers who bypass a plugin upload filter to drop executable binaries or cron scripts directly into your web root.
How to Fix Permission Denied and 403 Forbidden Errors Safely
When you need to fix a permission denied error on Linux hosting, follow this four-step diagnostic sequence instead of guessing:
- Check the Apache or Nginx Error Log: A
403 ForbiddenorPermission deniederror always logs the exact failing path and UID. Inspecttail -n 30 /var/log/apache2/error.logor/var/log/nginx/error.log. - Inspect Ownership and Mode on the Failing Path: Run
namei -l /home/alice/public_html/wp-content/uploads. Thenameiutility prints the owner, group, and permissions of every parent directory from/down to the target folder—instantly revealing if a parent folder like/home/aliceis missing+xtraversal rights. - Verify the Active PHP-FPM User: Run
ps aux | grep php-fpmto confirm which Linux user actually executes PHP requests, then matchchownto that user. - Check SELinux Contexts on RHEL/AlmaLinux: If permissions and ownership look right on AlmaLinux or Rocky Linux but Apache still logs
Permission denied, runls -Zand restore web contexts withrestorecon -Rv /var/www/html.
If your site is still hitting write failures or disk errors after fixing permissions, you may be bumping into account-level disk or inode ceilings—read our guide on Linux shared hosting resource limits and inodes to verify whether your account has exhausted its file count quota.
Frequently Asked Questions
What is the difference between chmod 755 and 644?
chmod 755 grants read, write, and execute/traverse permissions to the owner and read plus execute/traverse permissions to the group and others—which is required for directories. chmod 644 grants read and write to the owner and read-only to everyone else, which is the standard for HTML, CSS, JS, and PHP files.
Should WordPress wp-config.php be 644, 600, or 440?
Set wp-config.php to 600 (or 440 if your web server reads via group permissions) instead of 644. This prevents other unprivileged local users on a server from reading your database credentials.
Why did my site break with a 500 error after I ran chmod 777?
Hardened PHP handlers such as suPHP and CloudLinux CageFS treat world-writable (777 or 666) scripts and directories as a security violation and refuse to execute them, returning an HTTP 500 Internal Server Error until you restore 755/644.
What is the difference between chmod and chown?
chmod (change mode) controls what actions (read, write, execute) the owner, group, and others can perform on a file or directory. chown (change owner) assigns which Linux user and group own that file or directory.
How do I fix “Unable to create directory wp-content/uploads” without 777?
Verify that wp-content and wp-content/uploads are owned by the same Linux user that runs PHP-FPM (using chown -R user:group) and that directories are set to chmod 755. Also check disk space and inode availability.
Enforce Clean 755 and 644 Permissions Inside Isolated Linux Accounts
Proper chmod and chown discipline works best when backed by CloudLinux CageFS filesystem isolation at the kernel level. Keep wp-config.php and .env secrets protected inside hardened Linux hosting environments.
