Symfony - can not redirect all requests to index.php

netpyceb
HOBBY

6 months ago

Hello people

I am trying to deploy a Symfony app. All cool, it is deployed, but works only with the main index.php in the /public/ folder.

As soon as I go to e.g. url/health-check/ - it actually loads file index.php from the folder /public/health-check/index.php, and not from the main public/index.php

I tried to use .htaccess file, I tried to create multiple nginx.conf and nginx.template.conf, and I tried using Caddyfile...

I put them in different folders...

I write any garbage in them, correct or not....

They are NOT picked up. No changes at all, no good, no bad. Many random folders were tried. Nothing.

How do I point it in the Railway UI? Where should it be in the code? How do I know that that file was even found or exists in the service container?

I googled, I tried multiple Templates, and other repos. It just does not work in my code repo.

I do not need a "create the repo based on our code and just ad your files" solution.

I need a "add the file with config here, and the config should have that" solution please. Because I have a hundred existing repos to migrate, and literally thousands of code files. The all follow the same structure.

Please help, would appreciate any hint or example.

Solved

2 Replies

netpyceb
HOBBY

6 months ago

For the reference. This is what works in Heroku

server_name localhost;

index index.php index.html;

location / {
    # Check if the requested file exists, if not pass the request to index.php
    try_files $uri $uri/ /index.php?$query_string;
}

Simple as that

Can not make it run in Railway.app


netpyceb
HOBBY

6 months ago

One of the employees helped me.

---

For example, if I have the code


#[Route('')]
class IndexController extends AbstractController
{
    #[Route('', name: 'app_index', methods: ['GET'])]
    public function index(Request $request): JsonResponse
    {
        return new JsonResponse(['Nothing' => 'here']);
    }

    #[Route('/health-check', name: 'app_health_check', methods: ['GET'])]
    public function healthCheck(Request $request): JsonResponse
    {
        return new JsonResponse(['status' => 'ok']);
    }
}

and I want all requests go to public/index.php - need to set the variable:

NIXPACKS_PHP_FALLBACK_PATH = /index.php

That will redirect all requests there.

Also, it solved the issues with not served static files from assets. Now it works.


Status changed to Solved brody 6 months ago


Symfony - can not redirect all requests to index.php - Railway Help Station