R
Railwayβ€’2y 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β€’2y ago
Project ID: 48866d2b-59f7-4e12-889d-1f377cee4c17
Percy
Percyβ€’2y ago
Unknown User
Unknown Userβ€’2y ago
Message Not Public
Sign In & Join Server To View
Brody
Brodyβ€’2y ago
@Willian @codehaven this should be fixed now, could you try redeploying and let me know how it goes?
Unknown User
Unknown Userβ€’2y ago
Message Not Public
Sign In & Join Server To View
Brody
Brodyβ€’2y ago
Do you have an index.php file?
Unknown User
Unknown Userβ€’2y ago
Message Not Public
Sign In & Join Server To View
Brody
Brodyβ€’2y 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β€’2y ago
Message Not Public
Sign In & Join Server To View
Felinto
Felintoβ€’2y ago
I get the same error
Felinto
Felintoβ€’2y ago
Felinto
Felintoβ€’2y 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β€’2y ago
Message Not Public
Sign In & Join Server To View
Adam
Adamβ€’2y 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β€’2y ago
Is someone has an example about how to deploy a PHP application using Apache for Railway app ?
Brody
Brodyβ€’2y ago
this is a known problem, hopefully fix coming soon
root
rootβ€’2y ago
PHP should be fixed soon.
Felinto
Felintoβ€’2y 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β€’2y ago
You don't need to set any custom values And if it's Laravel, it automatically uses public/
Felinto
Felintoβ€’2y ago
i'm using slim framework how railway can figure out this ?
root
rootβ€’2y 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β€’2y ago
1. I'm using "public/index.php" and not "index.php" 2. post_max_filesize should be 50MB
root
rootβ€’2y 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β€’2y ago
I use apache mod_rewrite to avoid the user needs to type "public/index.php" in browser
root
rootβ€’2y ago
Ah, Railway uses nginx instead of apache by default
Felinto
Felintoβ€’2y ago
I need to create a nginx.conf in the main directory ?
root
rootβ€’2y ago
No; nixpacks creates it for you.
Felinto
Felintoβ€’2y 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β€’2y ago
As I said, I'll fix that in a bit, and it should be the default behavior soon.
Felinto
Felintoβ€’2y ago
thanks πŸ™‚ @aleks do you will tell us here when you fix the issue ?
Brody
Brodyβ€’2y ago
@Felinto Changes Should be live, can you try deploying again and let me know how it goes?
Unknown User
Unknown Userβ€’2y ago
Message Not Public
Sign In & Join Server To View
Felinto
Felintoβ€’2y ago
I received the same error again
Felinto
Felintoβ€’2y ago
Felinto
Felintoβ€’2y 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β€’2y ago
I know that is not necessary .htaccess but I use apache in development environment.
Brody
Brodyβ€’2y 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β€’2y ago
but the problem is not .htaccess you guys use nginx
Felinto
Felintoβ€’2y ago
Felinto
Felintoβ€’2y ago
maybe @aleks could look ?
Brody
Brodyβ€’2y 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β€’2y ago
Is there anything I can do to resolve this issue?
Brody
Brodyβ€’2y ago
try setting the NIXPACKS_PHP_ROOT_DIR = /public
Felinto
Felintoβ€’2y ago
environment variable, right ? ok, i'll check
Brody
Brodyβ€’2y ago
service variable in the service settings
Felinto
Felintoβ€’2y ago
done I'll wait and check I receive the 404 error now
Felinto
Felintoβ€’2y ago
Felinto
Felintoβ€’2y ago
Felinto
Felintoβ€’2y ago
maybe is that the reason ? I'll check
Felinto
Felintoβ€’2y ago
I removed the slash (because relative path...) and the issues continue
Felinto
Felintoβ€’2y ago
Brody
Brodyβ€’2y ago
i can see how this would be frustrating, i will bring this up to aleks sorry for the poor php support
Felinto
Felintoβ€’2y ago
Thank you for understanding
root
rootβ€’2y ago
Ah, try setting NIXPACKS_PHP_ROOT_DIR=/app/public I'm not sure if that will help, but it might
Felinto
Felintoβ€’2y ago
It worked! Thanks πŸ™‚
root
rootβ€’2y ago
Great! Also, if you want to have a custom configuration, it should now be possible.
Felinto
Felintoβ€’2y 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β€’2y ago
Felinto
Felintoβ€’2y ago
php.ini, right ? I'll check
root
rootβ€’2y ago
nginx.conf I'm pretty sure it should use your public/ dir; that's the root passed to the NGINX configuration.
Felinto
Felintoβ€’2y 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β€’2y 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β€’2y ago
root
rootβ€’2y ago
It should be running as root anyway, so there shouldn't be any permission issues.
Felinto
Felintoβ€’2y ago
the files are from the root user
Felinto
Felintoβ€’2y ago
Felinto
Felintoβ€’2y 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β€’2y ago
the fs is frozen at built time
root
rootβ€’2y ago
Huh, that's interesting. I haven't dug into that part of the codebase in a bit.
Finn
Finnβ€’2y ago
so you cant create any new folders
root
rootβ€’2y ago
No, it isn't.
Finn
Finnβ€’2y ago
on railway it is?
root
rootβ€’2y ago
Nope. Just not persisted across deployments.
Finn
Finnβ€’2y ago
you can create new files but no folders?
root
rootβ€’2y ago
You can create folders. And files.
Finn
Finnβ€’2y ago
im 90% sure you cant is this a new thing?
Felinto
Felintoβ€’2y ago
do you know any workaround ?
root
rootβ€’2y ago
I'll look into it. Nope.
root
rootβ€’2y ago
Finn
Finnβ€’2y ago
does railway run now run commands inside the container hosted on railway?
root
rootβ€’2y 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β€’2y ago
i guess yea
root
rootβ€’2y ago
Since it caches built templates in the storage folder at runtime
Finn
Finnβ€’2y ago
wonder why a dumb thaught that then... i based my comment of that
root
rootβ€’2y ago
πŸ€·β€β™‚οΈ
Brody
Brodyβ€’2y ago
A dumb said they also don't know why they said that, guess it's a telephone situation
Finn
Finnβ€’2y ago
lmao guess we both thaught it sounded wierd but didnt ask
Brody
Brodyβ€’2y 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β€’2y ago
ye
Brody
Brodyβ€’2y ago
Just store temp files in a memory fs for super speed
Felinto
Felintoβ€’2y ago
how did you bypass the user permissions issue ?
root
rootβ€’2y 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β€’2y ago
I never had any permission issues since I was creating folder / files in my apps own directory
Felinto
Felintoβ€’2y 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β€’2y ago
I also build with a dockerfile, nixpacks is mid (jokes)
root
rootβ€’2y ago
I mean, dockerfile is probably better
Felinto
Felintoβ€’2y 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β€’2y ago
No sorry, I don't do php
root
rootβ€’2y 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β€’2y ago
thanks for ping me i'll check I get the same issue again
Felinto
Felintoβ€’2y ago
Felinto
Felintoβ€’2y ago
Felinto
Felintoβ€’2y 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β€’2y ago
welp, dockerfile time
Felinto
Felintoβ€’2y ago
😒
Brody
Brodyβ€’2y 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β€’2y 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β€’2y ago
haha i get what you mean, but either way a caddy + php dockerfile isnt a bad idea
Felinto
Felintoβ€’2y 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β€’2y ago
Dockerfile.png
Felinto
Felintoβ€’2y ago
Brody
Brodyβ€’2y ago
caddy + php please
Felinto
Felintoβ€’2y ago
root
rootβ€’2y ago
Uh, that error isn't an error
Felinto
Felintoβ€’2y ago
root
rootβ€’2y ago
Set PORT to 80 in your Variables tab.
Felinto
Felintoβ€’2y ago
that what I guess thanks i'll do It worked! i knew it! ohhhh guys :3
Felinto
Felintoβ€’2y 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β€’2y 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β€’2y ago
yay happy for you!
root
rootβ€’2y ago
Great!