If Nginx downloads a .php file, it is serving that request as a static file instead of handing it to PHP-FPM. Add or repair a PHP location that sends FastCGI requests to the PHP-FPM listener, set SCRIPT_FILENAME to the real script path, verify the site root, and reload Nginx. A typical working block is:
Need a server to try this on? Antihost offers Linux VPS plans with NVMe storage, full root access and a 14-day free trial.
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;
}
Replace the socket with the endpoint used by the PHP-FPM pool on your host. The same configuration can use a TCP listener such as 127.0.0.1:9000 or, in a container network, php-fpm:9000. Do not expose PHP-FPM to an untrusted network.
As an Amazon Associate I earn from qualifying purchases.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →What a PHP download tells you
Nginx is not a PHP interpreter. It can serve files directly, or it can route an application request to a FastCGI server such as PHP-FPM. When a browser receives the PHP source as a download, the request matched a static-file path and never reached PHP-FPM. The immediate fix is therefore routing, not a change to the PHP script itself.
The normal request flow is:
- Nginx selects a server block for the request’s host and URI.
- A PHP location matches the URI ending in
.php. - Nginx checks that the script exists and builds its filesystem path.
- Nginx forwards FastCGI parameters to the configured PHP-FPM socket or TCP address.
- PHP-FPM executes the script and returns the response through Nginx.
If any of those steps is missing, Nginx may return the file as ordinary content, produce a 404, or return a 502 upstream error.
#1 Best Overall
- [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
- [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
- [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
- [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
- [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.
Inspect the configuration Nginx is actually using
Editing a file is not enough if that file is not included by the running instance, or if another virtual server handles the request. Start with the complete active configuration:
sudo nginx -T
Find the server block whose listen, server_name, and request host match the URL you are testing. Within that block, check the root directive and every location. Look for an existing PHP location, an exact match such as location = /file.php, a prefix marked ^~, and regex locations that might take precedence or prevent the PHP rule from being selected.
Use the configuration test before every reload:
sudo nginx -t
A successful test reports valid syntax. If the test fails, Nginx keeps the old configuration when you attempt a reload; the download problem will therefore remain until the syntax error is corrected.
Install and verify the PHP-FPM endpoint
PHP-FPM is the FastCGI process manager that executes PHP scripts. Nginx must point to the listener created by the running PHP-FPM pool, not to an assumed path. Open the pool configuration and find its listen = value. Common examples include a Unix socket such as /run/php/php8.3-fpm.sock, a generic socket such as /run/php/php-fpm.sock, or a TCP address such as 127.0.0.1:9000. Container deployments often use a service name and port, for example php-fpm:9000.
The endpoint choices have different operational properties:
| Endpoint | Use when | What to verify |
|---|---|---|
Unix socket, for example unix:/run/php/php8.3-fpm.sock |
Nginx and PHP-FPM share the same host or filesystem namespace | The socket exists, the Nginx worker can connect to it, and its owner and group permissions allow access |
TCP loopback, for example 127.0.0.1:9000 |
The pool listens on a local TCP port | The pool is listening on that address and port and local firewall rules permit the connection |
Container service, for example php-fpm:9000 |
Nginx and PHP-FPM run in separate containers on the same private network | The service name resolves from the Nginx container and both containers share the script files at compatible paths |
Check the PHP-FPM service status using the service name supplied by your operating system, then inspect its log if it is stopped or repeatedly restarting. A socket mismatch or a stopped pool causes an upstream connection failure; it cannot execute a script.
Free tools Windows power users keep installed
One-click scans. No signup required.
Rank #2
- 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
- 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
- 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
- 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
- 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.
Use a PHP location that forwards requests
Place a location like this in the intended server block. The example uses a Unix socket:
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;
}
Change only the listener and filesystem values needed by your deployment:
location ~ .php(?:/|$)matches a PHP filename at the end of a URI and also permits a path-info suffix.try_files $fastcgi_script_name =404;rejects a nonexistent script before it is sent to PHP-FPM.include fastcgi_params;supplies the standard FastCGI request variables.fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;tells PHP-FPM which file to execute.fastcgi_passidentifies the Unix socket or TCP listener where PHP-FPM is accepting FastCGI connections.
Some distributions provide an include file that already defines SCRIPT_FILENAME. Keep one correct definition and ensure it uses the root and URI layout of this server; duplicate or conflicting parameters make troubleshooting harder.
Make SCRIPT_FILENAME resolve to the real file
PHP-FPM does not infer the script location from the browser’s URL. Nginx constructs the path from the active root and $fastcgi_script_name. If the server root is /var/www/example/public and the request is /index.php, the resulting filename should be /var/www/example/public/index.php.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsDo not prepend the root twice. With this root:
root /var/www/example/public;
the correct parameter is:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
A value such as /var/www/example/public$document_root$fastcgi_script_name creates an invalid duplicated path. Conversely, a root that points to the project parent while the scripts live in a public directory causes PHP-FPM to search in the wrong place. The symptoms are commonly a 404, No input file specified, or Primary script unknown.
Check the exact path on disk, including capitalization, and check the root in the same server or location context that handles the request. A root declared in a different virtual server does not affect this one.
Rank #3
- [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
- [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
- [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
- [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
- [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by
Why try_files matters
The strict existence check keeps Nginx from forwarding arbitrary or misspelled PHP paths to the interpreter:
try_files $fastcgi_script_name =404;
If the file exists, processing continues to FastCGI. If it does not, Nginx returns a 404 immediately. This prevents confusing PHP-FPM errors and avoids passing requests for nonexistent scripts into the application layer.
Some sites use an equivalent check or a front controller. The important behavior is the same: verify the script path before forwarding it. Do not remove the check merely because a framework normally handles unknown routes; direct requests for real PHP files still need a valid mapping.
Understand front-controller and internal redirects
A site can appear to work at / while direct PHP URLs still download. Nginx’s try_files directive can test several candidates and internally redirect to a fallback such as /index.php. A request for / may therefore reach PHP through the front controller even when /admin/report.php is handled by a different location.
Compare the behavior of the root URL, a known script, and a nonexistent script. If only the root works, inspect every location that can match the direct URI. A prefix location with ^~ can stop regex evaluation, and an exact or more specific location can bypass the PHP block. Remove the bypass, adjust the location hierarchy, or add the FastCGI handling to the location that actually receives the request.
Handle PATH_INFO correctly
Some applications use URLs such as /file.php/articles/1. In that form, /file.php is the script and /articles/1 is PATH_INFO. PHP-FPM must not be given the entire URI as the filename.
Rank #4
- Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
- Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
- All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
- Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
- Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.
A location that explicitly splits the two portions can look like this:
location ~ ^(.+.php)(/.*)$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
try_files $fastcgi_script_name =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass unix:/run/php/php-fpm.sock;
}
Keep a separate ordinary PHP location if the site also serves URLs ending directly in .php. Test both forms after changing the split rule; a malformed expression can turn a valid script into a missing-file error.
Apply the change without guessing
- Back up the active Nginx configuration file and edit the server block selected by
nginx -T. - Set
rootto the directory that actually contains the scripts. - Add or correct the PHP location,
try_files,SCRIPT_FILENAME, andfastcgi_pass. - Run
sudo nginx -tand fix every reported error before proceeding. - Reload Nginx with
sudo nginx -s reloador the equivalent service-manager reload command for your platform. - Confirm that the PHP-FPM pool is running and listening on the exact endpoint in the configuration.
- Test a harmless script, then remove it and clear any temporary diagnostic output.
Nginx applies changed configuration only after a reload or restart. A successful syntax check followed by a reload is therefore part of the fix, not an optional final step.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Test execution safely
Create a temporary file in the document root with a minimal response:
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minute<?php echo 'nginx-php-ok'; ?>
Request it from a protected environment with a browser or a command such as:
curl -i https://your-host.example/health.php
A working setup returns the text generated by PHP, not the PHP source and not a file download. Test a known missing path as well; it should return 404 when the strict try_files check is active. Delete the test file immediately. A temporary phpinfo() page can reveal loaded settings, but it exposes sensitive environment details and must never remain publicly reachable.
Best Value
Read the right log for each failure
Inspect the Nginx error log and the PHP-FPM log at the same time as the request. Their messages distinguish routing, filesystem, and process problems:
| Observed result | Likely cause | Check and correction |
|---|---|---|
| PHP source downloads | The request matched a static location and bypassed FastCGI | Use nginx -T; check server selection, ^~ prefixes, exact matches, and the PHP regex location |
| 502 Bad Gateway | Nginx cannot connect to PHP-FPM | Confirm the pool is running and make fastcgi_pass exactly match its socket or listening address |
No input file specified or a PHP 404 |
SCRIPT_FILENAME points to a nonexistent path |
Correct root, remove duplicated path segments, and verify the file on disk |
Primary script unknown |
PHP-FPM cannot see the path Nginx sent | Compare the assembled filename with the PHP-FPM filesystem, container mount, or chroot path |
| Permission denied on a Unix socket | The Nginx worker lacks permission to open the socket | Check socket owner, group, mode, and the account used by Nginx; adjust the pool or service permissions consistently |
| Root URL works but a direct PHP URL downloads | A front-controller redirect works while another location handles the direct URI | Trace location matching for that URI and remove the higher-priority bypass |
| Path-info URL fails while a plain PHP URL works | The URI suffix was included in the script filename | Split the path, use $fastcgi_script_name for the file, and pass $fastcgi_path_info as PATH_INFO |
Compare common deployment layouts
The same directives behave differently depending on where Nginx and PHP-FPM run and how their filesystems are mapped.
| Layout | Root and filename requirement | FastCGI target | Main failure to avoid |
|---|---|---|---|
| Single host, shared document root | The Nginx root and PHP-FPM view both contain the script at the assembled path | Unix socket or loopback TCP | Wrong root or socket permissions |
| Separate containers | The script directory is mounted into both containers at compatible paths; PHP-FPM must see the path sent in SCRIPT_FILENAME |
Private service name and port such as php-fpm:9000 |
Nginx sees a file that the PHP container cannot see, producing a missing-script error |
| Chrooted or remapped PHP-FPM pool | The path must be valid after the pool’s chroot or path mapping is applied | The pool’s configured socket or TCP listener | Nginx’s host path does not correspond to PHP-FPM’s restricted filesystem |
| Front-controller application | Existing scripts pass the check; unknown routes are internally redirected to the designated controller | The same PHP-FPM endpoint used by the controller | Assuming that a working / proves every .php URI uses the same location |
Keep PHP-FPM private
PHP’s documentation explicitly warns that PHP-FPM must not be reachable from an untrusted network. Prefer a Unix socket when both processes share a host, or bind TCP to a protected loopback or private container network. Do not publish port 9000 directly to the internet. Restrict firewall and container-network access so only the Nginx process can reach the pool.
Remove diagnostic scripts after testing, keep source files outside unintended static directories, and review access and error logs after the change. A configuration that executes PHP correctly but exposes the interpreter or diagnostic output publicly is not a finished fix.
A compact decision path
- Is the file downloaded? Trace the request with
nginx -T. If no PHP location handles it, fix location matching before touching PHP-FPM. - Does a PHP location handle it? Verify that
try_filesandSCRIPT_FILENAMEpoint to the real file under the active root. - Does the endpoint exist? Match
fastcgi_passto the running pool’slistenvalue, including the exact socket path, host, and port. - Can both processes see and access the file? Check permissions, container mounts, and any chroot or path remapping.
- Was the new configuration loaded? Run
nginx -t, reload, test a harmless script, inspect both logs, and remove the test file.
Once those checks agree, Nginx will stop treating PHP as a downloadable static asset and will pass valid script requests through the intended PHP-FPM process.
Quick Recap
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.
Recommended Free Tools




