Using router in php

How can I use router in php? I tried the following code:
$parsed_url = parse_url($_SERVER['REQUEST_URI'])['path'];
echo $parsed_url;
print_r($_SERVER);

if ($parsed_url == '/test/hihi/') {
echo 'hihi';
}
$parsed_url = parse_url($_SERVER['REQUEST_URI'])['path'];
echo $parsed_url;
print_r($_SERVER);

if ($parsed_url == '/test/hihi/') {
echo 'hihi';
}
It return error 404 instead of hihi
32 Replies
Percy
Percy6mo ago
Project ID: N/A
Brody
Brody6mo ago
https://nixpacks.com/docs/providers/php
If a NIXPACKS_PHP_FALLBACK_PATH variable is passed, that will be used as a fallback for the server - for instance, if your app uses index.php as a router, you would set this variable to /index.php
Croissant
Croissant6mo ago
Thanks, is the link correct?
Brody
Brody6mo ago
lmao nope, my bad fixed
Croissant
Croissant6mo ago
Thanks! I tried using the template and I got this error message: nginx: [emerg] directive "include" is not terminated by ";" in /app/nginx.conf:11 which points to include $!{nginx}/conf/mime.types; I think $!{nginx} is causing issue
Brody
Brody6mo ago
did you name the conf file correctly as it is named in railways github? but also, you don't need to modify it to achieve what you have asked
Croissant
Croissant6mo ago
Where can I get the conf file? Because I want to fallback at different php file for different directory
Brody
Brody6mo ago
did you read this message?
Croissant
Croissant6mo ago
Yes, I only copy this file and put it on my root directory https://github.com/railwayapp/nixpacks/blob/main/src/providers/php/nginx.template.conf
GitHub
nixpacks/src/providers/php/nginx.template.conf at main · railwayapp...
App source + Nix packages + Docker = Image. Contribute to railwayapp/nixpacks development by creating an account on GitHub.
Croissant
Croissant6mo ago
Is there additional files that I have to copy?
Brody
Brody6mo ago
my original message says nothing about a conf file, please read the message
Croissant
Croissant6mo ago
I understand but what I am trying to achieve is /test/anything will fallback to /test/index.php
Brody
Brody6mo ago
that is exactly what my message explains how to do I'm not understanding where the confusion is coming from
Croissant
Croissant6mo ago
From my understanding, setting NIXPACKS_PHP_FALLBACK_PATH means everything will failback to a file if it's not found in the server right?
Brody
Brody6mo ago
correct
Croissant
Croissant6mo ago
However, I only want certain directory to failback to the file, not everything
Brody
Brody6mo ago
that was not clearly communicated to me until just now
Croissant
Croissant6mo ago
That's on me, my bad
Brody
Brody6mo ago
show me your conf file how you have it in your repo
Croissant
Croissant6mo ago
I just copy this configuration file from the example repo and try to deploy it, however I couldn't get it work normally. https://github.com/railwayapp/nixpacks/blob/main/src/providers/php/nginx.template.conf The error I got is nginx: [emerg] directive "include" is not terminated by ";" in /app/nginx.conf:11
GitHub
nixpacks/src/providers/php/nginx.template.conf at main · railwayapp...
App source + Nix packages + Docker = Image. Contribute to railwayapp/nixpacks development by creating an account on GitHub.
Brody
Brody6mo ago
please show me your conf file how you have it in your repo
Croissant
Croissant6mo ago
No description
Croissant
Croissant6mo ago
No description
Croissant
Croissant6mo ago
It's in the root directory
Brody
Brody6mo ago
you have changed it's name
Croissant
Croissant6mo ago
yes, I changed it to nginx.conf
Brody
Brody6mo ago
why though?
Croissant
Croissant6mo ago
It mentioned it's supported
No description
Brody
Brody6mo ago
yes but why would you rename it?
Croissant
Croissant6mo ago
Just to try out if it will work
Brody
Brody6mo ago
it's not going to work if it's named incorrectly
Croissant
Croissant6mo ago
I have renamed it to nginx.template.conf I think it works