R
Railwayโ€ข10mo ago
70

file not found

I'm using my own router and want everything to work trough the index.php But i get the message file not found idk which file they mean since i'm just echoing hello as a test
130 Replies
Percy
Percyโ€ข10mo ago
Project ID: 5a0ee64c-4acb-4b7a-a156-b53fd08e9edd
70
70OPโ€ข10mo ago
5a0ee64c-4acb-4b7a-a156-b53fd08e9edd NIXPACKS_PHP_FALLBACK_PATH=/index.php NIXPACKS_PHP_ROOT_DIR=public
Brody
Brodyโ€ข10mo ago
beat me to it applicable docs link https://nixpacks.com/docs/providers/php#php
70
70OPโ€ข10mo ago
I already followed the docs thats why im asking here
If a NIXPACKS_PHP_ROOT_DIR variable is passed, that will be used as the server root. 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.
If a NIXPACKS_PHP_ROOT_DIR variable is passed, that will be used as the server root. 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.
Brody
Brodyโ€ข10mo ago
oh so you already have those variables set and you are getting a 404?
70
70OPโ€ข10mo ago
. I'm not getting a 404 im getting the literal message file not found
Brody
Brodyโ€ข10mo ago
how is that not the same as 404 lol
70
70OPโ€ข10mo ago
I thought you meant the nginx 404 view my bad but ok its a so called 404
Brody
Brodyโ€ข10mo ago
what does your project structure look like?
70
70OPโ€ข10mo ago
well a public folder for my routing with a index.php an app folder and a views folder thats it and some other files like composer.json I did this before and it worked. idk why not rn
Brody
Brodyโ€ข10mo ago
so your root directory is the project directory itself?
70
70OPโ€ข10mo ago
what do you mean
Brody
Brodyโ€ข10mo ago
the root directory of your php app is just the root directory of the project?
70
70OPโ€ข10mo ago
no
Brody
Brodyโ€ข10mo ago
please show me your project structure
70
70OPโ€ข10mo ago
No description
70
70OPโ€ข10mo ago
No description
70
70OPโ€ข10mo ago
inside public idk what this is lol i used this before and it worked perfectly fine so weird
Brody
Brodyโ€ข10mo ago
you already have these set, correct?
70
70OPโ€ข10mo ago
yes
Brody
Brodyโ€ข10mo ago
@aleks - any ideas here?
70
70OPโ€ข10mo ago
I even tried a clean folder made a new folder called public with a index.php just a message saying hello and still the same issue
Brody
Brodyโ€ข10mo ago
where have you set those nixpacks variables?
70
70OPโ€ข10mo ago
in my variable tab
70
70OPโ€ข10mo ago
No description
Brody
Brodyโ€ข10mo ago
is your build detected as php?
70
70OPโ€ข10mo ago
yes
Brody
Brodyโ€ข10mo ago
show me please
70
70OPโ€ข10mo ago
No description
70
70OPโ€ข10mo ago
like that right
Brody
Brodyโ€ข10mo ago
yes show the specific error you get?
70
70OPโ€ข10mo ago
No description
Brody
Brodyโ€ข10mo ago
gotcha
70
70OPโ€ข10mo ago
this is so weird
Brody
Brodyโ€ข10mo ago
we shall wait for aleks
70
70OPโ€ข10mo ago
is aleks an expert
Brody
Brodyโ€ข10mo ago
yes he wrote the php provider
70
70OPโ€ข10mo ago
oh nice it worked before perhaps something changed uh i still didnโ€™t fix it could you try @Brody making a new project with same file structure and see if it works on your end
Brody
Brodyโ€ข10mo ago
dont know php
70
70OPโ€ข10mo ago
oh <?php echo โ€˜messageโ€™; ๐Ÿ™ƒ
Brody
Brodyโ€ข10mo ago
wheres the closing tag
70
70OPโ€ข10mo ago
you donโ€™t need it if youโ€™re purely writing php sometimes if you close a php file with only php in it you could cause issues
Brody
Brodyโ€ข10mo ago
told you I didn't know php
70
70OPโ€ข10mo ago
thas ok you probably know other stuff that I donโ€™t
Brody
Brodyโ€ข10mo ago
have you tried to do what you're asking me to do?
70
70OPโ€ข10mo ago
yes still file not found I worked with railway before and had zero issues
Brody
Brodyโ€ข10mo ago
what's your root dir set to
70
70OPโ€ข10mo ago
public fallback path index
Brody
Brodyโ€ข10mo ago
what show me the raw editor for these variables please
70
70OPโ€ข10mo ago
okay iโ€™ll finish my pizza first if you donโ€™t mind
Brody
Brodyโ€ข10mo ago
haha ofc not
70
70OPโ€ข10mo ago
NIXPACKS_PHP_FALLBACK_PATH=/index.php NIXPACKS_PHP_ROOT_DIR=public there
Brody
Brodyโ€ข10mo ago
shouldn't it be /public
70
70OPโ€ข10mo ago
i tried both
Brody
Brodyโ€ข10mo ago
have you tried setting the fallback path to /public/index.html
70
70OPโ€ข10mo ago
no i'll try that
70
70OPโ€ข10mo ago
No description
70
70OPโ€ข10mo ago
i read this before still file not found
Brody
Brodyโ€ข10mo ago
we will have to wait for aleks then
root
rootโ€ข10mo ago
hmm Try using /app/public as a root directory.
70
70OPโ€ข10mo ago
okay will do so now
70
70OPโ€ข10mo ago
No description
70
70OPโ€ข10mo ago
if i remove nixpacks variables and put my index outside public it works
root
rootโ€ข10mo ago
Well, it should work on /, but if you don't have FALLBACK_PATH set it won't work on other paths but ROOT_DIR defaults to /app, which is where Nixpacks puts your project in the built container
70
70OPโ€ข10mo ago
oh so like /app/public and fallback path to index.php
root
rootโ€ข10mo ago
(ROOT_DIR is relative to the filesystem root, not the project root)
70
70OPโ€ข10mo ago
yes I understand
root
rootโ€ข10mo ago
yes, that should do it should probably add that to the docs
70
70OPโ€ข10mo ago
Its ok so like fallback just to index.php /index.php root to /app/public It worked before as the way I did it
root
rootโ€ข10mo ago
just index.php, not /index.php
70
70OPโ€ข10mo ago
okay it works how could i not discover this myself ;/
root
rootโ€ข10mo ago
Hooray! ๐ŸŽ‰
70
70OPโ€ข10mo ago
but when i want to go to another route i get file not found again
root
rootโ€ข10mo ago
Huh.
70
70OPโ€ข10mo ago
only / works when i wanna do /example (for example)
root
rootโ€ข10mo ago
Where are you seeing file not found? In the browser or in the logs?
70
70OPโ€ข10mo ago
i get file not found again browser
root
rootโ€ข10mo ago
Hmm, it looks like this is a misconfiguration in the PHP provider that I've never run into before not sure why I never ran into this before
70
70OPโ€ข10mo ago
damn
root
rootโ€ข10mo ago
no, never mind, it's not that hmm Is 'file not found' the only thing you're seeing? Is there anything in the logs?
70
70OPโ€ข10mo ago
in deploy logs?
root
rootโ€ข10mo ago
yes
70
70OPโ€ข10mo ago
2024/02/18 21:45:31 [error] 50#50: *27 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.0.4, server: localhost, request: "GET /read-email HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "temp-mail-test.up.railway.app"

192.168.0.4 - - [18/Feb/2024:21:45:31 +0000] "GET /read-email HTTP/1.1" 404 27 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
2024/02/18 21:45:31 [error] 50#50: *27 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.0.4, server: localhost, request: "GET /read-email HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "temp-mail-test.up.railway.app"

192.168.0.4 - - [18/Feb/2024:21:45:31 +0000] "GET /read-email HTTP/1.1" 404 27 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
@aleks have you changed some stuff in the last months my last project had zero issues
root
rootโ€ข10mo ago
These are the only recent ones - the only major one is the Perl -> JS transition, and I thought I had tested that to make sure that functionality was equivalent
No description
70
70OPโ€ข10mo ago
I see is there a possible way i could do it trough nginx config?
root
rootโ€ข10mo ago
You can add a custom nginx config - just put an nginx.conf in your project and it'll be used
70
70OPโ€ข10mo ago
okay i'm not familar with that but i'll see if i can make it work
root
rootโ€ข10mo ago
Alright, sorry I couldn't help with the PHP provider Let me send an nginx config that should work put this in nginx.template.conf in your project:
worker_processes 5;
daemon off;

worker_rlimit_nofile 8192;

events {
worker_connections 4096; # Default: 1024
}

http {
include $!{nginx}/conf/mime.types;
index index.html index.htm index.php;

default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] $status '
'"$request" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /dev/stdout;
error_log /dev/stdout;
sendfile on;
tcp_nopush on;
server_names_hash_bucket_size 128; # this seems to be required for some vhosts

server {
listen ${PORT};
listen [::]:${PORT};
server_name localhost;

root /app/public;

add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";

index index.php;

charset utf-8;
location / {
try_files $uri $uri/index.php?$query_string;
}

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include $!{nginx}/conf/fastcgi_params;
include $!{nginx}/conf/fastcgi.conf;
}

location ~ /\.(?!well-known).* {
deny all;
}
}
}
worker_processes 5;
daemon off;

worker_rlimit_nofile 8192;

events {
worker_connections 4096; # Default: 1024
}

http {
include $!{nginx}/conf/mime.types;
index index.html index.htm index.php;

default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] $status '
'"$request" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /dev/stdout;
error_log /dev/stdout;
sendfile on;
tcp_nopush on;
server_names_hash_bucket_size 128; # this seems to be required for some vhosts

server {
listen ${PORT};
listen [::]:${PORT};
server_name localhost;

root /app/public;

add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";

index index.php;

charset utf-8;
location / {
try_files $uri $uri/index.php?$query_string;
}

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include $!{nginx}/conf/fastcgi_params;
include $!{nginx}/conf/fastcgi.conf;
}

location ~ /\.(?!well-known).* {
deny all;
}
}
}
There are some pitfalls with this configuration due to Nix, try the one above
70
70OPโ€ข10mo ago
okay can i delete the nix variables
root
rootโ€ข10mo ago
What do you mean? Oh, I see, yes, you can
70
70OPโ€ข10mo ago
okay thanks still getting file not found im confused
70
70OPโ€ข10mo ago
No description
70
70OPโ€ข10mo ago
in my root
root
rootโ€ข10mo ago
Kind of shooting in the dark here, but maybe this'll work?
worker_processes 5;
daemon off;

worker_rlimit_nofile 8192;

events {
worker_connections 4096; # Default: 1024
}

http {
include $!{nginx}/conf/mime.types;
index index.html index.htm index.php;

default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] $status '
'"$request" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /dev/stdout;
error_log /dev/stdout;
sendfile on;
tcp_nopush on;
server_names_hash_bucket_size 128; # this seems to be required for some vhosts

server {
listen ${PORT};
listen [::]:${PORT};
server_name localhost;

root /app/public;

add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";

index index.php;

charset utf-8;
location / {
try_files $uri /app/public/index.php?$query_string;
}

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include $!{nginx}/conf/fastcgi_params;
include $!{nginx}/conf/fastcgi.conf;
}

location ~ /\.(?!well-known).* {
deny all;
}
}
}
worker_processes 5;
daemon off;

worker_rlimit_nofile 8192;

events {
worker_connections 4096; # Default: 1024
}

http {
include $!{nginx}/conf/mime.types;
index index.html index.htm index.php;

default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] $status '
'"$request" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /dev/stdout;
error_log /dev/stdout;
sendfile on;
tcp_nopush on;
server_names_hash_bucket_size 128; # this seems to be required for some vhosts

server {
listen ${PORT};
listen [::]:${PORT};
server_name localhost;

root /app/public;

add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";

index index.php;

charset utf-8;
location / {
try_files $uri /app/public/index.php?$query_string;
}

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include $!{nginx}/conf/fastcgi_params;
include $!{nginx}/conf/fastcgi.conf;
}

location ~ /\.(?!well-known).* {
deny all;
}
}
}
.
70
70OPโ€ข10mo ago
iโ€™ll try 1 sec file not found from index now this is so weird
root
rootโ€ข10mo ago
I don't know what's going on here, you'd probably have more luck asking in a PHP community Sorry
70
70OPโ€ข10mo ago
its ok ty for trying I hope you could or someone else fix it in the future back to when it worked fine ๐Ÿ˜„
Brody
Brodyโ€ข10mo ago
this just a misconfiguration
70
70OPโ€ข10mo ago
i always configured like this and it always worked
Brody
Brodyโ€ข10mo ago
unfortunately that's doesn't mean it's not a misconfiguration
70
70OPโ€ข10mo ago
from whose end mine?
Brody
Brodyโ€ข10mo ago
yeah
70
70OPโ€ข10mo ago
how lol when im literally doing the things i always did and it just doesnt wanna work
Brody
Brodyโ€ข10mo ago
I'm not sure what's being done wrong, sorry
70
70OPโ€ข10mo ago
imma start a new repo and see what happens after a few tests i notice NIXPACKS_PHP_FALLBACK_PATH=/index.php this is acting up i tried /app/public/index.php /public/index.php but no luck sadly
root
rootโ€ข10mo ago
you tried just index.php without the /, right?
70
70OPโ€ข10mo ago
yes same message i give up for now
Solution
Brody
Brodyโ€ข10mo ago
https://test-service2.up.railway.app/ https://test-service2.up.railway.app/test
NIXPACKS_PHP_ROOT_DIR=/app/public
NIXPACKS_PHP_FALLBACK_PATH=/index.php
NIXPACKS_PHP_ROOT_DIR=/app/public
NIXPACKS_PHP_FALLBACK_PATH=/index.php
Brody
Brodyโ€ข10mo ago
my folder structure is
.
โ””โ”€โ”€ public/
โ””โ”€โ”€ index.php
.
โ””โ”€โ”€ public/
โ””โ”€โ”€ index.php
70
70OPโ€ข10mo ago
it works????????? was it because mine was NIXPACKS_PHP_FALLBACK_PATH=/index.php NIXPACKS_PHP_ROOT_DIR=/app/public instead of NIXPACKS_PHP_ROOT_DIR=/app/public NIXPACKS_PHP_FALLBACK_PATH=/index.php
Brody
Brodyโ€ข10mo ago
no
70
70OPโ€ข10mo ago
then what
Brody
Brodyโ€ข10mo ago
I don't know
70
70OPโ€ข10mo ago
. im confused
Brody
Brodyโ€ข10mo ago
I did what you asked me to and it works, you're doing something wrong somewhere else wish I knew what that something was though
70
70OPโ€ข10mo ago
root
rootโ€ข10mo ago
That should not affect it, but glad it's fixed!
70
70OPโ€ข10mo ago
very weird i'll try on my main application
Brody
Brodyโ€ข10mo ago
๐Ÿ™‚
root
rootโ€ข10mo ago
oh sorry, I didn't scroll down, I was responding to the env var ordering
Brody
Brodyโ€ข10mo ago
i mean it is fixed, just something wrong on their end
70
70OPโ€ข10mo ago
how tho we literally have the same variables .
Brody
Brodyโ€ข10mo ago
bruh that's not the same
70
70OPโ€ข10mo ago
lol you have /app/public i also tried that ๐Ÿ˜„
Brody
Brodyโ€ข10mo ago
if it works for me it means you have something missconfigured somewhere else
70
70OPโ€ข10mo ago
it also works for me now in my main project
Brody
Brodyโ€ข10mo ago
there you go
70
70OPโ€ข10mo ago
i literally copied your variables and pasted them but i had the same before weird but glad it works
Brody
Brodyโ€ข10mo ago
woohoo typo always gets ya
70
70OPโ€ข10mo ago
i dont think thats it because i also copied the lines from nixpacks website and tried the nginx but thanks anyways
Want results from more Discord servers?
Add your server