Understanding Linux File Permissions
Every file on Linux and macOS has three sets of permissions: for its owner, for its group and for everyone else. The chmod command changes them, and it accepts either a three-digit octal number or a symbolic string. This calculator translates between the two so you do not have to do the binary math in your head.
Recommended permissions for web servers
Files: 644. Directories: 755. Private keys and .env files: 600, so only the owner can read them. Executable scripts: 755. WordPress wp-config.php: 640 or 600.
find /var/www -type d -exec chmod 755 {} \;
find /var/www -type f -exec chmod 644 {} \;Symbolic mode
Instead of numbers you can add or remove single permissions: u (user), g (group), o (others), a (all) combined with + or - and r, w, x. For example chmod u+x deploy.sh makes a script executable for its owner only, and chmod go-w file removes write access for group and others.
Special bits
A fourth leading digit sets setuid (4), setgid (2) and the sticky bit (1). /tmp uses 1777 so users can only delete their own files. These bits are powerful and should be applied deliberately.
Fixing 'Permission denied'
Check the current mode with ls -l. If a script will not run, it probably lacks the execute bit. If a web server returns 403, the directory may be missing execute permission for 'others', or the file is owned by a different user; chown may be the real fix rather than chmod.