Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
VGSources
Blog

Fix Nginx Downloading PHP Files Instead of Running Them

A PHP download means Nginx served the file statically instead of handing it to PHP-FPM. This guide fixes location matching, listener, path, reload, routing, and security problems.
Length8 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If Nginx downloads a .php file, it is serving that request as a static file instead of passing it to PHP-FPM. Add a PHP location that forwards requests with FastCGI, point fastcgi_pass at the PHP-FPM listener actually running on the machine, build a correct SCRIPT_FILENAME, test the active virtual server, and reload Nginx. Until that handoff works, the browser can only receive the PHP source file.

What a PHP download tells you

Nginx does not execute PHP itself. It serves static files and can route application requests to a FastCGI server, such as PHP-FPM. A browser download therefore means the request reached a static-file handler, or a PHP handler that never successfully forwarded the request to PHP-FPM. PHP-FPM is the process that interprets the script and returns a response for Nginx to send to the client.

As an Amazon Associate I earn from qualifying purchases.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The PHP handoff depends on three pieces matching one another:

  • A location block must match the requested PHP URI.
  • fastcgi_pass must identify the socket or TCP listener used by the running PHP-FPM pool.
  • SCRIPT_FILENAME must resolve to the actual script on the filesystem.

NGINX’s Beginner’s Guide describes the role directly: “nginx can be used to route requests to FastCGI servers which run applications built with various frameworks and programming languages such as PHP.” It also notes that PHP uses SCRIPT_FILENAME to determine the script name and QUERY_STRING to pass request parameters.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

Use a known-good PHP location

Start with a minimal handler in the server block that serves the site. This example uses a Unix-domain socket; substitute the endpoint used by your PHP-FPM pool.

location ~ .php(?:/|$) {
    try_files $fastcgi_script_name =404;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass unix:/run/php/php-fpm.sock;
}

The regular expression matches a URI ending in .php and also supports a path-info suffix such as /file.php/articles/1. The try_files line rejects a request when the script does not exist, rather than sending a made-up path to PHP-FPM. The include supplies the standard FastCGI parameters, while the explicit SCRIPT_FILENAME tells PHP-FPM which file to open.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the listener that really exists

NGINX accepts either a Unix socket or a TCP address:

Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed
PHP-FPM endpoint fastcgi_pass form When it is typical
Unix-domain socket unix:/run/php/php-fpm.sock PHP-FPM and Nginx share the same host filesystem.
Versioned Unix socket unix:/run/php/php8.3-fpm.sock A distribution names the socket for a particular PHP version.
TCP listener localhost:9000 PHP-FPM listens on a local network address and port.
Container service php-fpm:9000 Nginx and PHP-FPM run as separate services on a container network.

These are alternatives, not interchangeable examples. A socket path that is absent, or a TCP address where no pool is listening, produces an upstream connection error; it does not execute the script. Find the listener in the active PHP-FPM pool configuration and use that exact value.

Fix the document root and script path

In the example, Nginx constructs the filename as $document_root$fastcgi_script_name. If the server’s root is /var/www/example/public and the request is /index.php, PHP-FPM receives /var/www/example/public/index.php. The root must be the directory that actually contains the script.

A common mistake is to prepend the root twice, for example by combining an absolute root with a variable that already contains it. Another is putting a different root inside the PHP location from the one used by the rest of the server. Both errors can produce “No input file specified”, a 404 response, or a PHP-FPM “Primary script unknown” message.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)

Check the path without guessing

  1. Identify the server block handling the site’s hostname and port.
  2. Read its root directive and confirm that the PHP file is below that directory.
  3. Compare the requested URI with $fastcgi_script_name. For a direct request to /admin/test.php, the expected script component is /admin/test.php.
  4. Make sure the resulting absolute path exists and is readable by the PHP-FPM worker.
  5. Do not add a second copy of the root in SCRIPT_FILENAME.

Inspect the configuration Nginx is actually using

Editing an unused site file does not change the virtual server handling the request. Dump the complete active configuration:

nginx -T

Use the output to verify the requested hostname appears in the intended server_name, that the expected root is present, and that a PHP location is loaded. This also exposes duplicate server blocks and included files that may override your edit.

Understand location precedence

Nginx first selects the longest matching prefix location, then evaluates regular expressions unless a prefix marked ^~ prevents that regex search. A broad prefix such as location ^~ /downloads/ can therefore bypass a regular-expression PHP location for a script under /downloads/. A more specific regex or another included location can have the same effect. If the site’s home page works but a direct or subdirectory PHP URL downloads, compare the locations that match each URI.

Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC

Front-controller applications add another routing layer. Nginx’s static-content guidance shows that try_files can internally redirect a request: if /path/index.html is absent but /path/index.php exists, the request can be mapped to the PHP location. A front controller may therefore work at / while a direct .php request follows a different location and is served as a static file. Test both paths when diagnosing the problem.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Verify PHP-FPM is installed, running, and listening

The Nginx configuration cannot compensate for a stopped pool. Check the service using the service manager on your operating system, then verify the configured socket or port exists and is accepting connections. A versioned service may use a name such as php8.3-fpm; the exact service name depends on the installed PHP package.

  • If the configured Unix socket does not exist, inspect the PHP-FPM pool configuration for its listen value and correct fastcgi_pass.
  • If the socket exists but Nginx reports permission denied, check its owner, group, and mode against the user running Nginx and the pool’s listen permissions.
  • If using TCP, confirm PHP-FPM is bound to the address and port named in fastcgi_pass, not only to a different interface or port.
  • In containers, ensure the Nginx service can resolve the PHP-FPM service name and that both services share the intended network.

PHP’s documentation describes FPM as a primary PHP FastCGI implementation and gives an important security warning: “php-fpm must not be reachable from an untrusted network.” Keep a TCP listener on a private interface or protected network, use firewall rules where appropriate, and never expose the FPM port directly to the public Internet.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Apply the change safely

  1. Edit the server configuration and add or correct the PHP location. Keep the root and the PHP handler in the same server context unless your deployment deliberately uses a different filesystem mapping.
  2. Run a syntax check:
nginx -t

Fix every reported error before continuing. Nginx keeps the old configuration active when a syntax check fails.

  1. Reload the validated configuration:
nginx -s reload

A service-manager reload is equivalent when your platform uses one. Configuration edits do not affect existing workers until Nginx reloads or restarts.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Request a harmless test script from a protected environment. A temporary script that returns a plain, non-sensitive response is enough to confirm execution. Remove it immediately after testing; do not leave phpinfo() or diagnostic output publicly accessible.
  2. Repeat the request with the real application URL and inspect logs if the result is still wrong.

Use logs to identify the remaining failure

Read the Nginx error log and the PHP-FPM log at the same time as you make a test request. The message usually identifies which layer is failing.

Observed symptom Likely cause What to check
The browser downloads PHP source The request is handled as static content. Active server block, PHP location matching, and any ^~ prefix or competing regex location.
502 Bad Gateway or upstream connection failure Nginx cannot connect to PHP-FPM. Socket path, TCP host and port, PHP-FPM service state, network reachability, and socket permissions.
“No input file specified” or “Primary script unknown” SCRIPT_FILENAME resolves to a path PHP-FPM cannot find. The effective root, URI, duplicated path segments, and file permissions.
404 from the PHP location The existence check rejects the path. Whether the requested script exists under the configured root and whether rewrites produced the expected URI.
Changes have no effect The edited file is not active or Nginx was not reloaded. nginx -T, nginx -t, and the reload result.

Handle PATH_INFO requests correctly

Some applications use a URL such as /file.php/articles/1. The script is /file.php; /articles/1 is PATH_INFO. If the entire URI is placed in SCRIPT_FILENAME, PHP-FPM looks for a file whose name includes the suffix and fails.

For this pattern, split the path before setting the filename. Nginx’s FastCGI reference documents a configuration pattern that captures the script portion and passes the remainder as PATH_INFO. The essential rule is that $fastcgi_script_name must contain only the real PHP filename, while the suffix is supplied separately. Adapt the exact regular expression and parameters to the application’s routing requirements, and test a valid and invalid path after changing it.

Direct scripts versus front-controller routing

Routing style Request flow Important checks
Direct script execution A URI ending in .php matches the PHP location and is sent to PHP-FPM. Correct regex location, real file under root, try_files, and SCRIPT_FILENAME.
Front controller Nginx first tests static files and internally redirects application routes to one entry script such as index.php. The try_files fallback, internal redirect target, and PHP location that receives the rewritten URI.
Path-info routing A script filename is followed by an application path segment. Split the script from PATH_INFO before constructing SCRIPT_FILENAME.

Do not remove the PHP location merely because the front page works. A working front controller proves only that one internal route reaches PHP-FPM; it does not prove that every direct PHP URI is protected from static serving.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Security and operational safeguards

  • Never knowingly serve PHP source as a downloadable file. Source can contain database credentials, signing keys, and application logic.
  • Keep try_files $fastcgi_script_name =404; or an equivalent existence check in the PHP handler to avoid forwarding arbitrary nonexistent paths.
  • Keep PHP-FPM on a private Unix socket or trusted private network. It must not be reachable from an untrusted network.
  • Remove temporary test scripts and diagnostic output immediately after verification.
  • After upgrades, re-check versioned socket names; changing PHP versions can change the listener path while leaving Nginx pointed at the old one.
  • When using a container or chroot, verify that the path visible to Nginx maps to the path visible inside the PHP-FPM environment. A host path and a container path can describe the same file differently.

A compact recovery checklist

  1. Run nginx -T and identify the virtual server handling the hostname.
  2. Confirm that a PHP location matches the failing URI and is not bypassed by a higher-priority location.
  3. Confirm the server’s root contains the requested script.
  4. Set SCRIPT_FILENAME to the root plus the script name, without duplicating the root.
  5. Use try_files $fastcgi_script_name =404; before forwarding.
  6. Match fastcgi_pass to the running PHP-FPM socket or TCP listener.
  7. Check PHP-FPM status, listener availability, and socket permissions.
  8. Run nginx -t; correct errors before reloading.
  9. Reload with nginx -s reload or the platform’s service equivalent.
  10. Test a temporary harmless script privately, remove it, and then review both logs for any remaining path or permission errors.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.