R
Railway•16mo ago
Felinto

I can't deploy a PHP application using Slim Framework

I have a simple application that uses slim framework: https://github.com/felinto-dev/wp-package-parser-api-php but I receive this error in railway deployment:
sh: 2: daemon: not found
sh: 4: worker_rlimit_nofile: not found
sh: 6: events: not found
sh: 7: worker_connections: not found
sh: 8: Syntax error: "}" unexpected
sh: 2: daemon: not found
sh: 4: worker_rlimit_nofile: not found
sh: 6: events: not found
sh: 7: worker_connections: not found
sh: 8: Syntax error: "}" unexpected
sh: 2: daemon: not found
sh: 4: worker_rlimit_nofile: not found
sh: 6: events: not found
sh: 7: worker_connections: not found
sh: 8: Syntax error: "}" unexpected
Server starting on port 6615
nginx: [emerg] open() "/conf/mime.types" failed (2: No such file or directory) in /nginx.conf:11
sh: 2: daemon: not found
sh: 4: worker_rlimit_nofile: not found
sh: 6: events: not found
sh: 7: worker_connections: not found
sh: 8: Syntax error: "}" unexpected
sh: 2: daemon: not found
sh: 4: worker_rlimit_nofile: not found
sh: 6: events: not found
sh: 7: worker_connections: not found
sh: 8: Syntax error: "}" unexpected
sh: 2: daemon: not found
sh: 4: worker_rlimit_nofile: not found
sh: 6: events: not found
sh: 7: worker_connections: not found
sh: 8: Syntax error: "}" unexpected
Server starting on port 6615
nginx: [emerg] open() "/conf/mime.types" failed (2: No such file or directory) in /nginx.conf:11
GitHub
GitHub - felinto-dev/wp-package-parser-api-php
Contribute to felinto-dev/wp-package-parser-api-php development by creating an account on GitHub.
123 Replies
Percy
Percy•16mo ago
Project ID: 48866d2b-59f7-4e12-889d-1f377cee4c17
Percy
Percy•16mo ago
Unknown User
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Brody
Brody•16mo ago
@Willian @codehaven this should be fixed now, could you try redeploying and let me know how it goes?
Unknown User
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Brody
Brody•16mo ago
Do you have an index.php file?
Unknown User
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Brody
Brody•16mo ago
Well unfortunately it looks like PHP apps on railway aren't quite fixed yet, I know zero about PHP so the best advice I could give would be to put together your own Dockerfile for your app
Unknown User
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Felinto
Felinto•16mo ago
I get the same error
Felinto
Felinto•16mo ago
Felinto
Felinto•16mo ago
I didn't know I could put personalized dockerfile on Railway. How is resource allocation control done so that I do not pay more than it is necessary for my application to work?
Unknown User
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Adam
Adam•16mo ago
Your app always has access to the maximum amount of resources for your plan (8GB ram 8vCPU for dev plan). It’s up to what your app uses for how much you’ll pay
Felinto
Felinto•16mo ago
Is someone has an example about how to deploy a PHP application using Apache for Railway app ?
Brody
Brody•16mo ago
this is a known problem, hopefully fix coming soon
root
root•16mo ago
PHP should be fixed soon.
Felinto
Felinto•16mo ago
I don't feel confident using railway's PHP builder because I need to set custom values in php.ini and my "index.php" is currently in "public/index.php" and not in the main directory. I couldn't find any documentation or template about it.
root
root•16mo ago
You don't need to set any custom values And if it's Laravel, it automatically uses public/
Felinto
Felinto•16mo ago
i'm using slim framework how railway can figure out this ?
root
root•16mo ago
Figure out what exactly? And actually I guess it won't autodetect Laravel if it isn't laravel I'll fix that in a bit
Felinto
Felinto•16mo ago
1. I'm using "public/index.php" and not "index.php" 2. post_max_filesize should be 50MB
root
root•16mo ago
Ah. The first one I'll fix in a bit, and the second one should be fine to set in php.ini
Felinto
Felinto•16mo ago
I use apache mod_rewrite to avoid the user needs to type "public/index.php" in browser
root
root•16mo ago
Ah, Railway uses nginx instead of apache by default
Felinto
Felinto•16mo ago
I need to create a nginx.conf in the main directory ?
root
root•16mo ago
No; nixpacks creates it for you.
Felinto
Felinto•16mo ago
how could I get the same result and avoid the user needs to type "public/index.php" ? I want the user just type the domain and that's it
root
root•16mo ago
As I said, I'll fix that in a bit, and it should be the default behavior soon.
Felinto
Felinto•16mo ago
thanks 🙂 @aleks do you will tell us here when you fix the issue ?
Brody
Brody•16mo ago
@Felinto Changes Should be live, can you try deploying again and let me know how it goes?
Unknown User
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Felinto
Felinto•16mo ago
I received the same error again
Felinto
Felinto•16mo ago
Felinto
Felinto•16mo ago
GitHub
GitHub - felinto-dev/wp-package-parser-api-php
Contribute to felinto-dev/wp-package-parser-api-php development by creating an account on GitHub.
Felinto
Felinto•16mo ago
I know that is not necessary .htaccess but I use apache in development environment.
Brody
Brody•16mo ago
take a look at this .htaccess file https://github.com/railwayapp-templates/laravel/blob/main/.htaccess its been a very long time since ive had to write htaccess rules, so im no help there
Felinto
Felinto•16mo ago
but the problem is not .htaccess you guys use nginx
Felinto
Felinto•16mo ago
Felinto
Felinto•16mo ago
maybe @aleks could look ?
Brody
Brody•16mo ago
you have a good point there, why would the railway provided template have a htaccess file then please dont directly ping team / conductor
Felinto
Felinto•16mo ago
Is there anything I can do to resolve this issue?
Brody
Brody•16mo ago
try setting the NIXPACKS_PHP_ROOT_DIR = /public
Felinto
Felinto•16mo ago
environment variable, right ? ok, i'll check
Brody
Brody•16mo ago
service variable in the service settings
Felinto
Felinto•16mo ago
done I'll wait and check I receive the 404 error now
Felinto
Felinto•16mo ago
Felinto
Felinto•16mo ago
Felinto
Felinto•16mo ago
maybe is that the reason ? I'll check
Felinto
Felinto•16mo ago
I removed the slash (because relative path...) and the issues continue
Felinto
Felinto•16mo ago
Brody
Brody•16mo ago
i can see how this would be frustrating, i will bring this up to aleks sorry for the poor php support
Felinto
Felinto•16mo ago
Thank you for understanding
root
root•16mo ago
Ah, try setting NIXPACKS_PHP_ROOT_DIR=/app/public I'm not sure if that will help, but it might
Felinto
Felinto•16mo ago
It worked! Thanks 🙂
root
root•16mo ago
Great! Also, if you want to have a custom configuration, it should now be possible.
Felinto
Felinto•16mo ago
Do you know what the PHP server resolves for $_SERVER["DOCUMENT_ROOT"] ? I need to create a temporary directory but I don't get the right permissions maybe I will need to use environment variables 😦
Felinto
Felinto•16mo ago
Felinto
Felinto•16mo ago
php.ini, right ? I'll check
root
root•16mo ago
nginx.conf I'm pretty sure it should use your public/ dir; that's the root passed to the NGINX configuration.
Felinto
Felinto•16mo ago
How could I simulate the same environment of railway in my computer to test this issue ? to avoid do a lot of "trash commits" in git repository
root
root•16mo ago
You should be able to download Nixpacks from https://github.com/railwayapp/nixpacks, and then (assuming you have Docker installed) run nixpacks build . --name <image name> and docker run -p 8080:80 -it <image name>
Felinto
Felinto•16mo ago
root
root•16mo ago
It should be running as root anyway, so there shouldn't be any permission issues.
Felinto
Felinto•16mo ago
the files are from the root user
Felinto
Felinto•16mo ago
Felinto
Felinto•16mo ago
but the PHP server run using the "nobody" user and that the reason because I can't create the folder do you have any suggestion ?
Finn
Finn•16mo ago
the fs is frozen at built time
root
root•16mo ago
Huh, that's interesting. I haven't dug into that part of the codebase in a bit.
Finn
Finn•16mo ago
so you cant create any new folders
root
root•16mo ago
No, it isn't.
Finn
Finn•16mo ago
on railway it is?
root
root•16mo ago
Nope. Just not persisted across deployments.
Finn
Finn•16mo ago
you can create new files but no folders?
root
root•16mo ago
You can create folders. And files.
Finn
Finn•16mo ago
im 90% sure you cant is this a new thing?
Felinto
Felinto•16mo ago
do you know any workaround ?
root
root•16mo ago
I'll look into it. Nope.
root
root•16mo ago
Finn
Finn•16mo ago
does railway run now run commands inside the container hosted on railway?
root
root•16mo ago
No, that was locally messing around with docker. But it works the same way on Railway - if it didn't, Laravel wouldn't work at all
Finn
Finn•16mo ago
i guess yea
root
root•16mo ago
Since it caches built templates in the storage folder at runtime
Finn
Finn•16mo ago
wonder why a dumb thaught that then... i based my comment of that
root
root•16mo ago
🤷‍♂️
Brody
Brody•16mo ago
A dumb said they also don't know why they said that, guess it's a telephone situation
Finn
Finn•16mo ago
lmao guess we both thaught it sounded wierd but didnt ask
Brody
Brody•16mo ago
I would have accepted it too, but I've created folders and files inside a railway container It's just not recommended because the no persistent storage thingy
Finn
Finn•16mo ago
ye
Brody
Brody•16mo ago
Just store temp files in a memory fs for super speed
Felinto
Felinto•16mo ago
how did you bypass the user permissions issue ?
root
root•16mo ago
I don't honestly know why it's running as nobody; there's nothing in the generated dockerfile to make it do that. And the perl script that runs for laravel apps can access the filesystem just fine
Brody
Brody•16mo ago
I never had any permission issues since I was creating folder / files in my apps own directory
Felinto
Felinto•16mo ago
If you want replicate the issue, you can git clone my repository https://github.com/felinto-dev/wp-package-parser-api-php =\
Brody
Brody•16mo ago
I also build with a dockerfile, nixpacks is mid (jokes)
root
root•16mo ago
I mean, dockerfile is probably better
Felinto
Felinto•16mo ago
do you have any example than you can share ? could I create a custom Dockerfile based on nixpacks and change the ownership of folder manually ?
Brody
Brody•16mo ago
No sorry, I don't do php
root
root•16mo ago
Yes, I think so. I'm not sure where Nixpacks puts the generated Dockerfile, though. Oh, actually, that could get pretty complicated. Oh 🤦‍♂️ Create a nixpacks.toml
[phases.build]
cmds = ["...", "chmod -R ugo+rw /app"]
[phases.build]
cmds = ["...", "chmod -R ugo+rw /app"]
@Felinto ^
Felinto
Felinto•16mo ago
thanks for ping me i'll check I get the same issue again
Felinto
Felinto•16mo ago
Felinto
Felinto•16mo ago
Felinto
Felinto•16mo ago
If AFTER the container was created I login and change the permissions, everything works fine but I can't do that using nixpacks.yaml If I execute this command AFTER the container was created everything works fine =\
Brody
Brody•16mo ago
welp, dockerfile time
Felinto
Felinto•16mo ago
😢
Brody
Brody•16mo ago
its a very simple php app, im sure it wont be that hard to create a caddy + php dockerfile for it theres a few resources on creating a caddy + php dockerfile
Felinto
Felinto•16mo ago
I wait so much time to works with nixpacks that I kind of fell guilty if I give up just because one line of code kekw guess... should to have a "pre-start" command or "post-build" like in NPM IDK I'll check
Brody
Brody•16mo ago
haha i get what you mean, but either way a caddy + php dockerfile isnt a bad idea
Felinto
Felinto•16mo ago
I know. I'll keep trying Brody If I know that was not possible to works with Nixpacks I could use Dockerfile since last friday I found this image that works very well in development environment https://hub.docker.com/r/webdevops/php-nginx PHP + Nginx however, does not works in railway
Brody
Brody•16mo ago
Dockerfile.png
Felinto
Felinto•16mo ago
Brody
Brody•16mo ago
caddy + php please
Felinto
Felinto•16mo ago
root
root•16mo ago
Uh, that error isn't an error
Felinto
Felinto•16mo ago
root
root•16mo ago
Set PORT to 80 in your Variables tab.
Felinto
Felinto•16mo ago
that what I guess thanks i'll do It worked! i knew it! ohhhh guys :3
Felinto
Felinto•16mo ago
GitHub
wp-package-parser-api-php/Dockerfile at main · felinto-dev/wp-packa...
Contribute to felinto-dev/wp-package-parser-api-php development by creating an account on GitHub.
Felinto
Felinto•16mo ago
If someone has the same issue you can use my repository as template I will delete the .htaccess files and use the same image for development too
Brody
Brody•16mo ago
yay happy for you!
root
root•16mo ago
Great!