Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lara336223's avatar

php-fpm8.3 php Router script won't run/work.

Hello , Novice here (php) I'm using the basic php Router. It did work on my Ubuntu 20 LTS server (NGINX) But my Control panel (HestiCP) updated & now it runs php-fpm.8.3 :( The Index page works , but if I go to /login all I get is a 404 from the Server (not Mine) , so I think there is a problem with the config / setup with the php-fpm ! I have Searched for days now for an answer, but to No avail :( So I was wondering if anyone here might have a clue :~/ Thank-You Sid

0 likes
3 replies
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

Certainly! This is a common issue when switching to PHP-FPM with NGINX, especially when using a custom PHP router script (like for a simple PHP app or a micro-framework).

Problem Explanation:

  • By default, NGINX does not route all requests to your index.php (or router script). Instead, it tries to serve static files directly, and if the file does not exist, it returns a 404.
  • On Apache, .htaccess handles this for you. On NGINX, you must configure this in your server block.

Solution: You need to update your NGINX server block configuration to pass all requests to your PHP router script (usually index.php) if the requested file does not exist.

Example NGINX Configuration:

Open your site’s NGINX config file (commonly found in /etc/nginx/sites-available/your-site.com).

Look for the location / block and update it as follows:

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

This tells NGINX:

  • Try to serve the file as is ($uri)
  • If not found, try as a directory ($uri/)
  • If still not found, pass the request to index.php (your router script), preserving the query string.

Make sure you also have a PHP block like this:

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
}

After editing:

  1. Save the file.
  2. Test your NGINX config:
    sudo nginx -t
    
  3. Reload NGINX:
    sudo systemctl reload nginx
    

Summary:

  • The 404 is because NGINX is not passing non-existent files to your router script.
  • The try_files directive fixes this.

Let me know if you need help with the exact file path or further details!

1 like
lara336223's avatar

Thank-You. But still no good. here is my Block code as Installed.

location ~ [^/].php(/|$) { try_files $uri =404;

                    include /etc/nginx/fastcgi_params;

                    fastcgi_index index.php;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

                    fastcgi_pass unix:/run/php/php8.3-fpm-Domain.sock;

                    include /home/Owner/conf/web/Domain/nginx.fastcgi_cache.conf*;
            }

I hope that helps ? Sid

lara336223's avatar

Thank-You Larry :~) Got it working now. Changed the domain.conf file a Lot You lot here are as always Brill !

Please or to participate in this conversation.