Linux file permissions are an important security boundary for PHP applications. A web process should be able to read the application files it needs and write only to explicitly designated runtime locations. Giving the web server ownership of the entire project makes deployment convenient but increases the damage an attacker can cause after compromising the application.
Separate code from writable data
Keep application source, Composer dependencies and configuration templates read-only to the web process. Create dedicated writable directories for uploads, cache, generated files and logs. Where possible, place private storage outside the public document root.
Choose ownership deliberately
A deployment user can own application files while the PHP-FPM pool runs under a separate account or group with read access. Grant write access only to runtime directories. Avoid recursively setting every file to 777; broad permissions hide ownership problems instead of solving them.
Protect sensitive configuration
Restrict database credentials, API tokens and private keys so only the required operating-system account can read them. Check parent directory permissions too: a protected file inside a world-readable directory may still be exposed through an unintended path or backup.
Verify the effective access
Test permissions as the actual PHP-FPM user, not only as root. Review symbolic links, upload directories, temporary files and deployment scripts. Re-check permissions after releases so extraction tools do not silently make files writable.
Checklist
- Keep source code read-only to the web process.
- Make only specific runtime directories writable.
- Keep secrets outside the public document root.
- Avoid world-writable permissions.
- Verify access using the real PHP-FPM account.