# Browser downloads index.php instead of rendering — Nginx has no fastcgi PHP location

**Code:** `PHP file downloads instead of running (Nginx)` · **Category:** Nginx / Apache · **Seen on:** Nginx, PHP, Linux

Nginx serves `.php` files as static downloads because no `location ~ \.php$` passes them to PHP-FPM.

## Meaning

Add a PHP location block with `fastcgi_pass` to the FPM socket/port, include `fastcgi_params` and `SCRIPT_FILENAME`, and install/start PHP-FPM. Also check the location block order and that `try_files` doesn't intercept `.php`.

## Common causes

- No PHP location block
- PHP-FPM not installed/running
- Wrong `fastcgi_pass`
- Location regex not matching
- Snippet include commented out

## Quick fix

1. Add `location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.3-fpm.sock; }`
2. Install and start `php8.3-fpm`
3. `nginx -t` and reload

## Detailed fix by platform

### Nginx

1. `location ~ \.php$ { include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass unix:/run/php/php8.3-fpm.sock; }`

## How to diagnose

1. **Location** — PHP block present?
2. **FPM** — Running?
3. **Socket** — Correct?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/nginx-apache/nginx-php-file-downloaded-instead-of-executed)
