Configuring nginx and PHP-FPM for Magento Open Source

Magento Open Source depends on a correctly built web tier to serve storefront and admin traffic and to stop uploaded files from running as code. This page explains the decisions, setup sequence and checks for nginx and PHP-FPM in infrastructure you control.

On this page

How nginx and PHP-FPM configuration keeps Magento Open Source running

The web tier does three jobs for Magento Open Source: it routes incoming requests to PHP-FPM, it enforces rules that stop uploaded files from being executed as scripts, and it sets the limits that decide how large requests, uploads and concurrent PHP workers can grow before the store slows or fails. A team with a store on a default web server install should treat that install as a starting point, not a finished configuration. The shipped nginx.conf.sample in the magento/magento2 repository gives the routing and deny rules Magento expects, but it has to be adapted to your server names, TLS termination, document root, PHP-FPM socket or port, and whether Varnish or a load balancer sits in front.

Plan the version before you edit anything. Adobe's 2.4.9 and 2.4.8-p5 requirements both list nginx 1.30, and Adobe supports only the combinations it lists, so a different nginx build, a different PHP minor version or a different database or search stack falls outside the support statement even if the store appears to run. Confirm the exact PHP-FPM version and pool setup against the system requirements for the release you are installing, and record the chosen values in the same change request as the nginx configuration so auditors and the next engineer can see what was tested.

The web tier is also where several security controls are enforced, and those controls are easy to lose during a rebuild. The deny rules for uploaded scripts, the restriction on direct access to setup and internal directories, the handling of the admin path, and any response headers used for Content Security Policy all live in this configuration. Test each rule after every change with requests a visitor or scanner would send, not only with the homepage. Confirm with your platform or security team which headers and admin path rules they need to see documented before the store goes live.

Which nginx and PHP-FPM options fit your store

This table compares the main nginx and PHP-FPM choices for a self-hosted Magento Open Source store: starting point, pool layout, PHP limits and whether a Varnish layer sits in front of nginx. Read each row for when the option fits, what it adds to maintenance and what to confirm against the release notes for the version you install.

DecisionWhen it fitsMaintenance costWhat to confirm
Start from the shipped nginx.conf.sampleStandard single-store installs where the team wants the rule set Adobe documents for Magento and few local changesLow. Re-apply local edits when the sample changes between releasesCompare your copy with the sample shipped in the installed version before each upgrade
Custom server blockStores with unusual routing, several domains, or specific header or TLS requirementsHigher. Every rule you write must be retested after each patch and minor releaseConfirm that static file, media and admin paths still reach the correct handlers after changes
One PHP-FPM pool per storeMulti-store setups where stores need separate limits, users or process isolationHigher. More pools to size, monitor and restartConfirm the pool user matches the file ownership plan for each store's code tree
Shared PHP-FPM poolSingle-store or small installs where one set of process limits is enoughLower. One pool to tune and monitorCheck that peak admin and cron work does not starve storefront requests in the same pool
php.ini limits set globallyTeams that want one consistent baseline for all PHP applications on the hostLow. One file to change, but other applications on the host inherit the same valuesConfirm memory, upload and execution limits against the PHP version in the system requirements for your release
php.ini limits set per poolHosts that run other PHP applications or stores with different import and report sizesModerate. Limits must be kept in step across poolsConfirm each pool's limits in its own configuration file and document why each value differs
nginx terminates TLS aloneSmaller deployments where full-page caching is not needed or is handled elsewhereLower. Fewer components in the request pathConfirm the nginx version against the Adobe system requirements, since only listed combinations are supported
nginx behind a Varnish 8 layerTraffic levels where full-page caching is part of the design, as Adobe documents Varnish for self-managed installsHigher. Cache rules, purge behavior and headers must be tested alongside nginxConfirm the Varnish version and the cache configuration guidance for your Magento release before go-live

How the web tier changes by environment and topology

On a single host, nginx, PHP-FPM and the Magento code all live together, so there is one place to edit and one place to verify. The nginx server block usually starts from the nginx.conf.sample file shipped in the Magento root, and it is adjusted for your server name, TLS certificates and the PHP-FPM socket or address. The PHP-FPM pool runs under the same user that owns the file system, which keeps write access limited to the directories the store needs. Because nothing is shared with another machine, host-specific values and shared values sit in the same files and drift is rare.

  • Shared files: the nginx server block, the rewrite rules that send requests to index.php, and the deny rules for generated and upload paths are the same logic you would copy to any other node.
  • Host-specific values: the PHP-FPM pool user, the socket path or listen address, and the memory_limit and upload_max_filesize values in php.ini or the pool file.
  • Varnish placement: if Varnish is used, it sits in front of nginx on the same host, so nginx listens on a backend port and Varnish listens on port 80 or 443.
  • Restarts: nginx and PHP-FPM are reloaded on the same host after each configuration change, so the change order is simple.
  • Confirm: that the PHP-FPM version matches a combination listed in Adobe's system requirements for your release, and that the nginx version is one Adobe lists for that release.

Before sign-off, confirm the server block, pool and limits are documented in one place so the next change is traceable.

How a storefront request reaches PHP-FPM

This illustrative layout starts with a shopper's request at the load balancer on the public side of the trust boundary. An optional Varnish layer may answer cacheable pages before anything reaches the web tier. Inside the web tier, nginx applies the Magento server rules: it serves static files directly and passes PHP requests over FastCGI to a PHP-FPM pool running as the file system owner. Check that only the front controller reaches PHP and that the pool can write only where Magento requires.

Illustrative layout of a typical self-managed Magento Open Source web tier, not a required design.

nginx and PHP-FPM configuration setup sequence for Magento Open Source

This sequence takes a self-hosted Magento Open Source store from a supported stack to a web tier that serves the storefront and admin, runs PHP through a dedicated pool, and refuses to execute uploaded scripts. Each step ends with a check you can repeat after every change.

  1. Confirm the supported stack for your release line

    Before touching any config, check the system requirements for the exact Magento Open Source release you will run, including the PHP, nginx and Varnish versions Adobe lists for that line. Adobe supports only the listed combinations, so record the versions your build server and production hosts actually run. Confirm with your platform team whether a Varnish layer sits in front of nginx in your design, since Adobe documents Varnish as the full-page cache for self-managed installs. Done when you have a written version matrix that matches the requirements page for your release.

  2. Copy and adapt the nginx sample configuration

    Start from the nginx.conf.sample file shipped with Magento Open Source rather than a generic web config. Point the root directive at the pub directory of your installation, set the server names for the storefront and admin hosts, and keep the sample's location rules for static files, PHP handling and the blocks that deny access to sensitive paths. Keep the file in version control so changes are reviewed. Done when nginx -t reports that the configuration syntax is ok and the test is successful, with no warnings about the document root.

  3. Create a dedicated PHP-FPM pool

    Create or adjust a PHP-FPM pool for the store with its own user and group, matching the file system owner used for the installation, and a dedicated socket or port that nginx passes PHP requests to. Use a pool name that identifies the store so logs and process lists are easy to read. Limit the pool's writable paths to what Magento needs, and align the socket path in the pool with the fastcgi_pass value in nginx. Done when the PHP-FPM configuration test passes and the pool appears in the service status output with the expected user.

  4. Set php.ini limits and required extensions

    Enable the PHP extensions the release requirements list, then set upload size, post size, memory and execution time limits in the php.ini that the pool reads. Set the values from the Magento documentation for your release and your own load tests rather than copying figures from forum posts. Make sure the nginx client body size limit is not lower than the PHP upload limit, or uploads fail before PHP sees them. Done when php -m lists every required extension and php -i confirms the limits your pool actually uses.

  5. Block execution of uploaded scripts

    Confirm that the web server rules deny PHP execution in upload and media directories, such as the media and var paths, and that only the front controller and designated entry points reach the PHP handler. Remove or deny any directory listing and any location that passes arbitrary file types to PHP-FPM. Keep the file ownership and write permissions tight so the web user can write only where the store requires. Done when a test file with a PHP extension placed in a media path returns an error or plain content instead of running, and the check is recorded for the release.

  6. Reload services and confirm pool health

    Reload PHP-FPM first, then nginx, so the new socket and pool settings are live without a full restart. Watch the error logs for both services while you do this. If you use Varnish, confirm its backend points at the nginx address and port you configured. Done when both services report active status, the error logs show no new permission or socket errors, and the pool still shows its expected process count.

  7. Finish with storefront and admin checks

    Load the storefront home page, a category page, a product page and the admin login from a browser, and check that static assets such as CSS and JavaScript return successfully. Confirm that PHP responses carry the security headers your team has agreed and that the admin path is reached through the configured server name. Record the results with the nginx and PHP-FPM versions and the configuration commit ID. Done when every page loads without server errors and the record is filed with the release notes.

Blocking uploaded scripts from running on the web server

Uploads are a common route into ecommerce stores, so the web server must refuse to execute anything an attacker manages to place in a writable directory. Product images, customer files, import files and cache content all land on disk through the application. If a file with a .php extension can be requested from a media path and handed to PHP-FPM, a single upload vulnerability becomes code execution. The defense is layered: the file system owner and the web server user should only have write access to the directories Magento Open Source needs, the nginx location rules should refuse script handling in upload paths, and the application should validate and store uploads without trusting client-supplied names or types. No single layer is sufficient on its own, so plan and verify all three together.

Start by comparing your server block with the nginx configuration file that ships with your release. Magento Open Source includes a sample, and the sample's location rules for media, static and script handling have changed between releases. A change to the sample, or a local edit made during a previous upgrade, can silently remove a block that was there before. Confirm the rules against the sample for the exact version you run, including the release you are upgrading to, and record the diff in your change records. Adobe's system requirements list the nginx version that is supported for your release, so check that version at the same time.

Test the block rather than assuming it works. Place a harmless file in a writable media path on a non-production host, for example a .php file that only returns a fixed string, and request it through the public hostname. The expected result is a refusal, not the string. Repeat the test for uppercase and double extensions, for a file inside a nested directory, and for a request with a trailing path segment, because these are the forms that often bypass a regular expression. Remove the test file afterward, and rerun the same checks after every web server change or upgrade. Ask your security tester to include these cases in the scope so the result is recorded as evidence.

Security controls the web tier must enforce

The web tier is the first place a request meets your store, so it is where several basic controls can stop common abuse before it reaches Magento code. These controls complement application-level hardening in the admin, modules and configuration. They do not replace it, and each one should be verified on the running server rather than assumed from the sample file.

Deny access to sensitive paths

Block direct web requests to directories that hold configuration, logs, Composer metadata and setup scripts, such as app/etc, var, vendor and setup. Start from the rules in the shipped nginx.conf.sample, then confirm each denied path returns a refusal rather than file contents. Ask your team to repeat this check after every release, since new files or directories can appear in an upgrade.

Block script execution in writable paths

Uploaded media, generated files and cache directories are writable by the web user, so a PHP file placed there must never run. Add location rules that refuse PHP handling under pub/media and similar paths, and pass only the front controller and approved entry points to PHP-FPM. Test by uploading a harmless test script in a staging environment and confirming the server does not execute it.

Isolate the PHP-FPM pool user

Run the Magento pool under its own system user and group, separate from other web applications and from services such as the database or cache. Set the pool's listen permissions so only the web server can reach the socket. Confirm with your system administrator that the file system owner and the pool user are different roles, as described in the file ownership guidance, so a compromise in one site cannot write to another.

Restrict admin paths by network

Where your business allows, limit the admin path to office, VPN or bastion addresses at the web server, so the login form is not reachable from the open internet. Keep the rule in the web tier and in version control, and document who maintains the allowed address list. Confirm that load balancers and proxies pass the true client address, or the rule may allow or block the wrong traffic.

Set security headers and CSP

Add response headers such as Content Security Policy where your store configuration requires them. Magento Open Source supports CSP headers from 2.3.5, and from 2.4.7 CSP runs in restrict mode by default on storefront and admin payment pages. Check that your nginx headers do not duplicate or conflict with headers the application sends, and test payment and checkout pages in a browser after each change.

Keep nginx and PHP patched

Run nginx and PHP versions that Adobe lists as supported for your Magento release, and apply security updates on the same cycle as your store patches. Adobe's system requirements for 2.4.9 list nginx 1.30 and PHP 8.5, and Adobe supports only the listed combinations. Ask your team to record the exact versions in use and to check them against the requirements page before each patch window.

Which nginx and PHP versions to pin for each release line

The PHP and nginx versions you pin follow the Magento Open Source release line you run, not the newest packages on your distribution. Adobe's system requirements for 2.4.9 list PHP 8.5 and nginx 1.30, alongside OpenSearch 3, Redis or Valkey 9, RabbitMQ 4.3, Composer 2.10 and MariaDB 12.3 (recommended) or 11.8 or MySQL 8.4, on Linux x86-64. For 2.4.8-p5, the listed PHP versions are 8.4 or 8.3, paired with nginx 1.30, Varnish 8, OpenSearch 3, Redis or Valkey 8.1 and RabbitMQ 4.3. Record the PHP minor version, the nginx build and the php-fpm pool version in your build notes so the web tier and the application agree on one row of the matrix.

Adobe supports only the combinations it lists, so a PHP version that happens to run the store is not a supported configuration. Magento Open Source 2.4.9 was released May 12, 2026, according to Adobe's released versions page. Under Adobe's lifecycle policy, 2.4.8 remains in standard support until May 31, 2028, so a 2.4.8 store can stay on its current matrix for now, but security patch releases still need the matching PHP and nginx versions. Check the Adobe Commerce system requirements for your exact patch level before each upgrade, because these pages change between releases.

Before you change a PHP-FPM pool or nginx package, confirm the matrix with the release you are moving to and run a staging build with the same php.ini limits and nginx.conf rules you plan to ship. Ask your hosting or platform team who owns the OS packages, how minor PHP upgrades reach the web nodes, and who signs off when a security patch requires a new PHP minor. Treat any version outside the listed row as unsupported until Adobe lists it.

Limits to confirm in your environment

The nginx and PHP-FPM rules in Magento Open Source depend on your exact release, your hosting layer and your monitoring. Each item below is something to confirm with the vendor documentation or your own environment before you commit to a configuration.

Shipped nginx sample for your release

Compare the nginx.conf.sample file in your exact Magento Open Source release against the rules your security team expects. Rules for static files, PHP entry points and denied paths can change between releases, so do not reuse a sample from an earlier install. Confirm the nginx version your release lists in Adobe's system requirements, since Adobe supports only the listed combinations.

System requirements

Platform overrides of server blocks

Check whether your hosting provider, control panel or ingress controller writes its own server blocks, rewrite rules or default PHP handlers. A panel can silently re-enable directories that the Magento rules block, and a managed platform may not allow edits to the nginx configuration at all. Ask the provider in writing which files you can change and how they are reloaded.

PHP build and required extensions

Confirm that your PHP-FPM build is the version Adobe lists for your release and that it includes every extension Magento requires, along with the php.ini limits you plan to set. Adobe's requirements list which PHP versions each release supports. Ask your platform team to confirm the exact extension list from the release documentation, not from memory of an earlier version.

Requirements by release

Varnish and load balancer effects

If Varnish or a load balancer sits in front of nginx, confirm how it sets the upstream address, forwarded protocol and client IP headers. Magento and nginx rules that depend on these headers can misroute requests or log the wrong client if the front tier rewrites them. Test HTTPS redirects and admin access through the full path, not only against the origin.

Varnish cache guide

Monitoring for PHP-FPM and nginx

Confirm that your monitoring can read the PHP-FPM status page and the nginx error log, since blocked uploads and pool exhaustion both show up there first. If the status endpoint is reachable only from localhost, your agent must run on the same host. Agree who receives alerts and how long logs are kept before you rely on them during an incident.

Custom rules and future upgrades

List every custom location block, header or rewrite you add, and record why it exists. Rules copied from a community example can conflict with a later release's sample or with a security patch that changes the same paths. Plan to diff your file against the sample at each upgrade, and confirm the step in your upgrade test environment before production.

What buyers ask before hiring help with nginx and PHP-FPM for Magento

How much effort does configuring nginx and PHP-FPM for Magento Open Source take?

For a single server built from the shipped nginx.conf.sample, the work is a bounded set of tasks: adapting the server block, creating a PHP-FPM pool for the store user, setting php.ini limits, and writing rules that stop uploaded scripts from executing. The effort grows with the number of web nodes, the TLS setup, the caching layer and any custom routes. Ask your team or a partner to list each server, pool and rule in the written scope so the effort can be counted rather than guessed.

How long does a web tier configuration usually take to finish?

Duration depends mostly on your environment: how many nodes sit behind the load balancer, whether TLS termination and Varnish are already in place, and how many change approvals your organization needs before a production change. No fixed duration applies across these setups. Ask for a schedule that separates a staging build, load and security verification, and the production change window, with each step tied to a named owner.

What does the work need from our team?

You need someone who owns the server and can grant access to the build and staging hosts, someone who can approve the production change, and an application owner who can confirm which Magento paths must accept uploads or custom routes. Platform versions matter too. Adobe's 2.4.9 system requirements list PHP 8.5 and nginx 1.30 on Linux x86-64, and Adobe supports only the listed combinations, so confirm your operating system and package sources early.

Can we configure nginx and PHP-FPM ourselves?

Yes, if your team already runs PHP-FPM and nginx for other applications and can test each rule against the Magento paths it affects. The risk sits in the details: an overly broad location block can expose files, and a missing rule can leave an upload directory executable. Teams without that experience often choose a partner for the review and verification steps, while keeping day-to-day ownership in-house.

What drives the cost of this work up or down?

Cost follows the number of web nodes, the number of PHP-FPM pools, the amount of custom routing, the TLS and certificate setup, and how much testing your change process requires. Recurring costs appear when each Magento patch or PHP upgrade changes the supported stack. Ask for a quote that splits one-time build and verification work from any retainer for later upgrades, and that names who pays for test environments.

How do Magento upgrades change the web tier?

Each release line can move the supported PHP, nginx and database versions, so a Magento upgrade may require a new pool configuration or a new nginx setting. Adobe's upgrade guide recommends upgrading every patch cycle to stay secure and PCI compliant, and it names customizations and third-party integrations as drivers of effort. Plan web tier checks into every upgrade, and confirm the current support dates for your release line in Adobe's lifecycle policy before you commit.

Does Varnish change the nginx and PHP-FPM work?

Yes. Adobe documents Varnish as the full-page cache accelerator for self-managed installations, so the request path passes through Varnish before nginx and PHP-FPM. That changes which headers nginx forwards, how cache purges reach the application, and which upstream addresses the configuration references. Confirm the Varnish version your release line supports in Adobe's system requirements before you finalize the proxy settings.

What should we ask for in a quote for this work?

Ask for a written scope that lists each file to be produced or changed, including the nginx server block, the PHP-FPM pool files, the php.ini overrides and the rules that block script execution in upload and media paths. Also ask for the test cases used to prove blocked requests return the expected responses, the rollback steps, the handover documentation, and the upgrade support terms. A quote without these items is hard to compare against your own team's effort.

How DeployOpen works on this

DeployOpen plans and delivers the nginx and PHP-FPM layer for Magento Open Source inside your own infrastructure, from the server rules to the pool and php.ini settings. Each engagement starts with a written scope so the web tier is configured, tested and handed over against the platform versions you actually run.

How we scope

  • Confirm the Magento Open Source release line and the PHP, nginx and database versions against Adobe's system requirements for that release.
  • Record the number of web nodes, whether Varnish sits in front of nginx, and where TLS terminates.
  • Agree in writing which upload and media paths must block script execution and which exceptions the store needs.

How we build

  • Start from the shipped nginx.conf.sample, then adapt the server block, PHP handoff and static asset rules to your document root.
  • Create dedicated PHP-FPM pools with process limits and a user matching the file system owner, and set php.ini limits for upload and memory needs.
  • Test that script files in media and upload directories return errors rather than executing, and that admin and setup paths are restricted.

How we hand over

  • Deliver versioned nginx, PHP-FPM and php.ini files with a short note on each setting and why it was chosen.
  • Document the checks used to confirm blocked uploads, cache headers and Content Security Policy headers still reach the browser.
  • Walk your operations team through reloading services, validating configuration syntax and rolling back to the previous files.

How we support

  • Re-test the web tier after each Magento patch, PHP or nginx upgrade, since version changes can alter the supported combinations.
  • Review configuration drift when new extensions add routes or upload paths that need their own rules.
  • Ongoing support, upgrades and continuous testing are available as a retainer after the fixed-scope delivery.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.