R
Railway14mo ago
frich14

Can't get any route using php and slim framework

It's a small app that I wanted to deploy. Everything works normal but when I try to get into a route I get a 404 error. I think the .htaccess file is not working like it does locally. Works: https://slim-php-deployment-production-8419.up.railway.app/ Not: https://slim-php-deployment-production-8419.up.railway.app/test a6ace02e-d783-426b-9daf-613e795ce691
27 Replies
Percy
Percy14mo ago
Project ID: a6ace02e-d783-426b-9daf-613e795ce691
frich14
frich1414mo ago
GitHub
GitHub - AgustinFrich/slim-php-deployment: Aplicación Slim Framewor...
Aplicación Slim Framework 4 PHP con despliegue automático 🚀 - GitHub - AgustinFrich/slim-php-deployment: Aplicación Slim Framework 4 PHP con despliegue automático 🚀
Brody
Brody14mo ago
an htaccess file is not applicable for the php provider on railway since it uses nginx, but you can provide your own nginx.conf, this explains a little on how you can do that https://nixpacks.com/docs/providers/php
frich14
frich1414mo ago
When I add a nginx.conf, even if it doesn't have any configurations, I get an "Application failed to respond" but doesn't crash or gives any log.
Brody
Brody14mo ago
can you send your nginx config
frich14
frich1414mo ago
worker_processes 5;
daemon off;

events {
worker_connections 4096; # Default: 1024
}

http {
index index.html index.htm index.php;
default_type application/octet-stream;
server_names_hash_bucket_size 128; # this seems to be required for some vhosts

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

index index.php;

charset utf-8;

}
}
worker_processes 5;
daemon off;

events {
worker_connections 4096; # Default: 1024
}

http {
index index.html index.htm index.php;
default_type application/octet-stream;
server_names_hash_bucket_size 128; # this seems to be required for some vhosts

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

index index.php;

charset utf-8;

}
}
I tried with and same output. It gives me an error if I don't put events or if it has any syntax error
events {
worker_connections 1024;
}

http {

server {
index index.php;
}
}
events {
worker_connections 1024;
}

http {

server {
index index.php;
}
}
Brody
Brody14mo ago
please reference the nginx config file in the link I sent you
frich14
frich1414mo ago
GitHub
nixpacks/nginx.template.conf at main · railwayapp/nixpacks
App source + Nix packages + Docker = Image. Contribute to railwayapp/nixpacks development by creating an account on GitHub.
Brody
Brody14mo ago
yes you'll need to modify that to redirect all requests to index.php
frich14
frich1414mo ago
I've tried modifying that but the application fails to respond every time, and only works again if I delete the nginx.conf
Brody
Brody14mo ago
try without modifying, /test wont work, but let me know if the root endpoint does at least work
frich14
frich1414mo ago
Root doesn't work when I have the nginx.conf
Brody
Brody14mo ago
none of the routes?
frich14
frich1414mo ago
None
Brody
Brody14mo ago
what status code do you get
frich14
frich1414mo ago
The app doesn't crash, it is still active
Brody
Brody14mo ago
what status code do you get when hitting the root route
frich14
frich1414mo ago
Sorry, 503
Brody
Brody14mo ago
and thats when using the unmodified config?
frich14
frich1414mo ago
Exactly Or with the empty roules, same thing
Brody
Brody14mo ago
okay, i will look into it in a bit
frich14
frich1414mo ago
Thanks!
Brody
Brody14mo ago
frich14
frich1414mo ago
Thank you so muchhh!!!!!!
Brody
Brody14mo ago
all good?
frich14
frich1414mo ago
All good, yes
Brody
Brody14mo ago
awsome