I have being trying to see how the hell one would deploy rails app via cpanel.So far i have failed miserably.Granted it has beed few hours and in software engineering terms thats nothing, still the experience has been nothing short of nigtmare!
The first problem i was facing is when i try to clone the app in rails project dir given to you by cpanel when you create ruby project.You have to put your codebase on that dir but guess what , you can't clone because the dir is not empty!! So after chatting with perplexity i found a way, set the application root to the the clone project dir when creating a ruby app
The way cpanel make sence of your rails project is by reading the config.ru file.The code base already has that file when you create the project.Next thing you have to do is to bundle install.Basically it reads the gemfile and install all the required libs.Problem is that rails uses native libraries that uses 'C' code.Inorder to install native libraries you need access to commands like gcc and make.This are the command you offen dont have accress to, atleast is true for me when i am writing this.Bacause of that my install kept falling.
The main error occures when I try to install io-console( the native lib).If i would have been given proper access than i am pretty much sure that this error would not have occured
Now in my local system i use renv.I was under the impression that cpanel use that aswell.Not only it does not support renv but also the way it handles envs is pretty odd.It feels like it is creating a different instance of ruby but somehow you still need some root accress.I dont know many be i am missing something or maybe awful lot for that matter :<
To be continue
I am writing this a day a after and i have manage to deploy with cpanel.I mailed my host admin about the issues i was having and he said he will look into it.He later messaged me that he has fixed the issue with a screenshot showing bundle installed has finished with out errors.Although he did not metion what it was he changed i am guessing that since he was a superuser he did not have any permission error that i was having.Also saw that he gave me access to gcc, which you need to build the native libraries.So now i can create rails project without asking him to do gem install for me every time!!
The problems dont end there.I clone my rails project and created a ruby project with cpanel, giving the it the path of my rails project.I bundle install and according to docs it should work when you hit the url as it should be live! Accept when i hit the url it is showing as if noting is connected to the domain.Strange!!
So i tried the next best thing. I created a ruby app with cpanel giving it a project path that does not exists.So it created a dir with some files init.At this point rails is not installed.I used bundle init in the project root, creating the Gemfile.I edited the Gemfile by adding rails on it.I bundle install and restarted the webapp.This it shows 503 error.Ok now atleast its connected!!
Checking the log file made me more confused that i already was!!the error is coming from something called LSAPI.After lot of googling, perplexity and chatgpt i manage to find what was the problem.The hosting service uses LiteSpeed server to serve the website.Apparently is really good at hosing wordpress which is really popular in Bangladesh.I am missing the gem that connect rails with LiteSpeed Server.So i gem install ruby-lsapi
Installed rails again with new libs added to gemfile and created rails project without any error, but when i hit the url there is a dirrent error, active record is calling a function that does not exists.LSPI is the one that is calling the active record.Agains it pretty clear that there is version conflict.I am using both latest rails and lsapi
So for the time being i downgraded both. I am using rails 7.1.4 and ruby lsapi 5.6(Because its taking to much time at this point to follow best practice , whole day is being wasted and i am not even a rails dev !!).After that, it finally worked.I opened the url and it said somrthing went wrong.Its ok because i dont have any controller its normal.I created a controller and called rails asset:precompile to generate static file for production.Copy the public to my public_html and than site worked without error