Why file ownership and permissions matter for Magento Open Source
File ownership and permissions decide which operating system user owns the Magento Open Source code, which user the web server runs as, and which directories that web server user can write to. Done well, the store can write only where it must (generated code, cache, sessions, media and logs) and everything else stays read-only to the web process. Done badly, an attacker who finds a single upload or code execution flaw inherits the write access of the web server and can alter storefront code, admin files or payment logic. Adobe's security best practices name weak file system permissions alongside unpatched vulnerabilities and weak passwords as the causes behind most compromises, so this is a control you set once and then verify on every release.
Plan this work at four points: the first install, a move to a new host, the build of a multi-node layout where several servers must agree on who writes what, and PCI DSS scoping, where your assessor will ask how the payment-handling code is protected from change. At each point, confirm three things with your own team and your hosting provider: which account owns the code directory, which account the PHP-FPM pool and web server run under, and which paths are writable at runtime. The Adobe security best practices guidance is the natural starting point for that review, and your auditors will expect to see the decisions written down.
Expect the effort to depend on how the store is deployed. A single host built with a standard Composer install is simpler to lock down than a pipeline that builds on one server and deploys to others, because each stage may need different ownership and write rights. Ask any partner quoting the work to state which environments, deployment stages and hosts are in scope, how permission checks will be repeated after each release, and who approves changes to the owner or group settings.
How ownership and write access fit together
The diagram starts with the deploy user, which installs the code and owns it, so the code stays out of reach of the web server. The PHP-FPM pool user reads that code and writes only to the paths the store needs, such as generated, var, pub/media and pub/static. Admin and cron actions run as PHP processes under the same pool user, so they inherit the same narrow write rights. Uploads sit on the write side of a trust boundary, and nothing in them should ever be executed. Check that every write path in your setup is listed and that no code path is writable by the web user.
Who owns the code, who writes where, and where the trust boundary sits.
Permission models and when each fits
This table compares three file ownership layouts for a self-hosted Magento Open Source store: a single owner, separate deploy and runtime users, and read-only code with writable mounts. Read each column for the fit, the hardening gain and the operational cost, then match the layout to how many nodes you run and how releases reach production.
| Layout | Best fit | Hardening gain | Operational cost |
|---|---|---|---|
| Single user owns code and runs PHP-FPM | One server, small team, few deployments, limited staff with shell access | Lowest gain: PHP can write to the code tree, so a compromised upload path can alter application files | Simplest to run, but any admin-triggered process can leave root-owned or mixed-owner files that break later runs |
| Separate deploy and runtime users with group write | Single or small multi-server setups where a release user builds code and PHP-FPM writes only to var, generated, pub/media and similar directories | Moderate gain: code is owned by the deploy user and the web user holds write access only where Magento needs it | Requires careful group settings and a documented deploy step; cron and CLI commands must run as the same user as PHP-FPM |
| Read-only code with writable mounts | Multi-node layouts and pipeline builds where code ships as an immutable artifact | Highest gain: the code tree cannot be modified at runtime, and writable paths are limited to mounts for media, sessions and logs | Highest setup effort: shared storage, mount options and build-time compilation must be designed and tested, and some CLI tasks need a planned write window |
| Cron ownership | Any layout with scheduled Magento jobs | Keeps cron writes inside the same paths PHP-FPM uses, avoiding a second writer | Cron run as root or another user often creates files the web user cannot later overwrite; confirm the crontab owner in every environment |
| Deployment friction | Teams that release often or run a pipeline | Strong layouts reduce accidental writes but make each release a permission check | Each release must set ownership and modes again; confirm the procedure with your platform team before the first production push |
| Multi-node consistency | Two or more web nodes behind a load balancer | Consistent ownership across nodes stops one node from drifting into a different write profile | Owner IDs must match on every node, and shared media or sessions need the same writable paths everywhere |
How to set ownership and permissions on a new install
This sequence gives a new Magento Open Source install one deploy user that owns the code, a web server user that can write only to the directories the store needs, and a PHP-FPM pool that runs as that web user. The result is a store that can generate its own cache, logs and media without being able to rewrite its application code.
Create the deploy and web server users
Create a dedicated deploy user that will own the code and a separate web server user that PHP-FPM and nginx run as. Keep the web server user out of sudo and give it no login shell. Confirm the accounts exist and that the web server user cannot switch to the deploy user. Use the user names your server build standard defines, and check the exact commands against the install guide for the version you are installing.
Install Magento as the deploy user
Run the Composer install as the deploy user so every file lands owned by that account, not by root or the web server user. Keep the auth.json file with repository access keys readable only by the deploy user. Confirm that the project directory and vendor tree show the deploy user as owner after the install finishes, and that no files were created by root during the run.
Set ownership and group on the project
Assign the deploy user as owner of the whole project tree and set the group to the web server user's group. This lets the web server read the code while the deploy user remains the only account that can change it. Confirm with a recursive listing that the owner and group match across app, vendor, pub and generated directories, and that no stray files remain owned by another account.
Grant write access only to writable directories
Set the base permissions so that files are read-only for the web server user, then add group write access only to the directories Magento needs at runtime: var, generated, pub/media, pub/static and app/etc where setup writes configuration. Remove write access from app/code, vendor and the rest of the code tree. Confirm the write list against the current install guide for your version, then check that the directory modes match that list and nothing more.
Point the PHP-FPM pool at the web server user
In the PHP-FPM pool file, set the user and group directives to the web server user so PHP processes run under the account that has the narrow write rights. Confirm the pool is listening and that a phpinfo or equivalent check reports the expected user. Make sure nginx runs as the same group so it can read static files. Restart the service and check the pool logs for permission errors.
Test writes from the web server user
As the web server user, attempt to write a test file in var and in pub/media, which should succeed, and to write into app/code and vendor, which should fail. Delete the test files afterward. Load the storefront and admin once to confirm that cache and log writes work. Record the results so a later change can be checked against the same baseline.
Confirm code files are not writable by the web user
Run a final check that code files under app, vendor and the generated PHP files you do not expect to change are not writable by the web server user. Confirm that the deploy user is the only account able to change code, and that the admin area cannot write PHP into the codebase. Keep this output with the install record so the permission model can be audited and repeated after upgrades.
Security risks that weak permissions create
Permissions on a Magento Open Source store decide what an attacker can do after a single foothold, such as a vulnerable extension or a stolen credential. The risks below connect because each one turns a small compromise into persistent control of the code, the media or the deploy path. Check each item against your own server layout before go-live.
Web user can write to code
If the PHP-FPM or web server user can write to app/code, vendor or pub/static, a compromised request can plant a file that survives restarts and redeploys. Adobe's security best practices name weak file system permissions as a common cause of compromise, so this is the first control to verify. Check that the web user has write access only to the directories Magento needs at runtime, and that code directories are owned by a separate deploy user.
Uploaded scripts running from media
Product images, CMS uploads and customer files land in pub/media, and that path must never execute server-side code. If the web server parses PHP there, an uploaded file becomes a backdoor even when the code itself is clean. Confirm that the nginx or Apache rules deny script execution under the media and upload paths and that the upload directories are not writable by anything except the expected user.
World-writable directories
Setting directories to 777 to clear an installation error gives every local account write access and often hides the real ownership problem. Any process on the host, including a compromised plugin or a neighboring service, can then modify files the store trusts. Audit the tree for world-writable files and directories and replace each one with an explicit owner and group.
Leaked admin and deploy credentials
The auth.json file holding Composer access keys, the env.php database credentials and deploy SSH keys all grant write access to the codebase if they are readable by the wrong account. A permissive mode on these files exposes them to every process that runs as the web user. Restrict them to the deploy user, keep them out of the web root and confirm that backups do not copy them to broadly readable locations.
Cron and CLI running as the wrong user
Running bin/magento cron jobs or setup commands as root, or as the web user, leaves generated files and cache directories owned by the wrong account. Root-owned files then block the web user from writing caches, and teams respond by loosening permissions further. Confirm that cron and CLI run as the file system owner declared in your install, and that generated and cache paths keep the same owner after every run.
Drift after manual fixes
A permission changed by hand during an incident often stays in place after the incident is closed, and the next release quietly reintroduces the gap. Without a scripted ownership and mode step in the deployment, each server ends up with a different state that no one has reviewed. Ask for the ownership and permission rules to live in the deployment pipeline, and check a sample of production paths against them after each release.
Keeping permissions consistent across nodes and pipeline builds
Ownership and permissions must match on every machine that touches the Magento file system, not just on the first server you installed. On a multi-node layout, each web node, the build server and any shared media location need the same file owner and the same web server user, or a deploy on one machine can leave files that another node cannot write or read. The most common failure is a release built by a deploy user that leaves generated/, var/ or pub/static/ owned by a different account, so PHP-FPM throws permission errors on the next request. Decide the owner and group once, write them into your deployment runbook, and check them after every build and every sync.
Shared media storage and build-to-production copies deserve the same scrutiny. If pub/media is mounted from network storage, confirm which numeric user and group the mount presents to each node, because a mismatch there can either block uploads or make product images writable by accounts that should only read them. When you copy a build from a build server to production, file mode and ownership can change in transit, depending on the tool and flags you use. Verify ownership and modes on the target after each copy, and do not fix errors by widening permissions to world-writable, which removes the separation this topic is meant to create.
Load balancer and Varnish placement can change which paths each node serves and writes, so the set of directories you need to check may differ from a single-server install. Confirm in your own layout which nodes run PHP-FPM, which handle cron, where the page cache sits and which paths any sync job touches. Adobe's security best practices name weak file system permissions as one of the main causes of compromise, so treat each mismatch you find as a finding to close, not a cosmetic issue. Record the expected owner and mode for each path in your runbook and test them as part of the release checklist.
Limits to confirm in your environment
Permissions on a Magento Open Source host depend on the release line you run, the security layers around it and who else touches the files. The cards below list the limits to settle with your platform, hosting and security teams before you apply any ownership or mode settings.
Writable paths for your release line
The set of directories Magento must write to depends on the exact version in production, so confirm the list against the release you run, whether that is 2.4.9, 2.4.8-p5 or another line. Check which paths hold generated code, cache, sessions, logs and media, and confirm that var, generated, pub/static and pub/media are the only locations your team plans to open for writing. Treat any extra writable path as a finding to justify.
SELinux or AppArmor policy
Mandatory access control can block PHP-FPM or nginx from writing to directories that Unix permissions allow, and it can also grant access that permissions alone would deny. Ask your Linux platform team which policy mode is enforced on the web nodes, which contexts apply to the Magento root and how file labels will be set after deployment. Confirm the policy in a staging host before changing ownership in production.
Shared hosting restrictions
On shared hosting, the web server often runs as the same account as other sites, which weakens the separation that ownership and mode settings are meant to provide. Confirm whether the provider lets you set the file owner and web server user independently, whether you can change the PHP-FPM pool user, and whether cron and CLI commands run under the same identity. If the answer is no, the store cannot meet the separation described in this topic, and that gap belongs in your risk record.
Container and volume ownership
In containers, the UID and GID inside the image rarely match the owner on mounted volumes, so write failures often appear only after a deployment. Confirm which user runs PHP-FPM inside each container, whether var, generated and media are mounted as named volumes or bind mounts, and whether an init step fixes ownership on start. Test a full deploy and restart on a clone so the team sees the ownership state that the running containers actually use.
Backup tool access
Backup agents, snapshot tools and file-sync jobs need read access to the store, and they often run as a separate account that can change ownership or write to the restore path. Confirm which account runs each backup job, whether it can write into the Magento tree during restore and whether its credentials are stored where the web user can read them. Restrict that account to the read access and restore destination it needs, and record who may change it.
Temporary write access for CI
Pipeline users that run Composer, static content deployment or setup commands may need write access during a release, and teams often leave that access in place afterward. Confirm which CI user performs each step, whether it runs under the web user or a deploy user, and how write access is granted and removed for the release window. Ask your team to document the revocation step and to check that the pipeline does not keep a writable tree between releases.
Questions teams ask before setting file permissions
Can a small team set Magento file permissions without outside help?
Yes, if one or two engineers already administer the Linux host, understand the web server user and can test changes on a copy of the store first. The work itself is a defined set of steps: choose one owner account for the code, give the web server user write access only to the directories Magento must write to, and confirm the store still runs. The harder part is keeping that state over time, because every Composer install, setup command and manual fix can reset ownership. Small teams often find the first pass manageable and the ongoing discipline the real test. Ask whether the team can reproduce the permission state from a script after each release.
How long does a permission review take and what changes the time?
The duration depends on what you start with. Drivers include the host type (a single VM, a container image or a managed Kubernetes setup each handle file ownership differently), the number of web nodes that must match, whether shared storage such as NFS is involved, and how much permission drift already exists. A clean Composer install on one server is a short job. A store with years of manual chmod and chown changes, several nodes and uploads owned by a different user needs an inventory first. No duration figure is supplied for this work, so ask any provider for a timeline tied to a written scope that lists these factors.
What access does a permission project need from our team?
You need an account that can change ownership and modes on every node in scope, which usually means root or sudo on those hosts, plus read access to the Magento installation and its app/etc/env.php file. You also need a staging copy that matches production closely enough to test a full install and a storefront check, and a change window for production. Ask for a list of the exact commands the work will run, a rollback path for each host, and confirmation that no credentials are stored in shared tickets or chat. Access should end when the work is complete.
Does a Magento release change which paths the web server must write to?
It can. Releases add generated code, static view files, cache and log locations, and sometimes new directories used by modules, so a permission set that worked on one version may block a later setup step. Adobe's upgrade guide recommends upgrading every patch cycle to stay secure and PCI compliant, which means permission rules belong in the release checklist, not only in the first install. Test the writable paths against each target version on staging before production, and check the release notes for the version you plan to use.
Why do weak file permissions matter for a store that handles payments?
Adobe's security best practices say most compromises exploit unpatched vulnerabilities, weak passwords and weak file system permissions. If the web server user can rewrite application code, an attacker who finds an upload or code execution flaw can plant persistent changes. Narrow write access limits what a compromised process can alter and makes unexpected file changes easier to spot. For PCI DSS scoping, the aim is that the team can show who may change code and how those changes are controlled. This is a control to prepare and document, and an independent assessor decides whether it meets the standard.
What should a permission review cost, and what drives the price?
A quote should follow from a written scope, and DeployOpen does not publish a price list. Cost components are the inventory of current ownership and modes, the change plan, the work on each host, testing on staging, the production change window and the handover documentation. Costs rise with the number of nodes, the number of custom modules and third-party extensions that write files, and the amount of drift found. Ask for a fixed scope covering named hosts, the Magento version, the test steps and what counts as done. Ongoing checks after each patch are a separate recurring item.
Which permission checks should an engineer run after a change?
Start by confirming that the code owner and web server user are the ones documented for the host, and that the web server user cannot write to application code outside the directories Magento needs. Then run a full setup check, load the storefront and admin, and test an upload and a cache flush. Compare the final state with the previous state, and store the commands in version control so the state can be reapplied. Confirm exact commands and directory lists against the Magento documentation for your release, because the required writable paths vary by version.
How DeployOpen scopes and delivers permission hardening
DeployOpen plans, implements, hardens, documents and supports self-hosted open-source platforms inside your own infrastructure. For Magento Open Source, that means mapping which directories the store must write to, setting the file owner and web server user accordingly, and handing your team a documented, repeatable permission model.
How we scope
- Inventory your current file layout, deployment method, and any extensions that write to code or generated directories.
- Agree in writing which directories need write access, which stay read-only, and which hosts or nodes the change covers.
- Confirm who owns the file system account, who runs PHP-FPM, and who may approve changes to permissions later.
How we build
- Apply the owner, group, and permission model in a staging copy first, then verify the store installs, runs, and generates static content.
- Test upload paths, the admin, and cron jobs to confirm the store writes only to the directories it needs.
- Review the web server rules that block uploaded scripts from running, alongside the permission changes, so both controls are tested together.
How we hand over
- Deliver a written permission map listing each path, its owner, its mode, and the reason it is writable.
- Provide the deployment steps and scripts so your team can reapply the same model on every release and node.
- Walk your engineers through the checks they should run after upgrades, extension installs, and pipeline changes.
How we support
- Re-check permissions after each Magento patch or upgrade, since new releases can change which paths need write access.
- Ongoing support, upgrades, and continuous testing are available as a retainer, with the scope agreed in writing.
- Ask your DeployOpen contact to confirm which items in the permission map are covered by a retainer before work starts.

