I am relatively new to Ruby, and I am used to PHP style webservers.
I am wondering if there is a way for me to run ruby the same way as I would PHP. Apache is preferred, but not mandatory.
For example, in my index.php file, I will have something along the lines of echo '<p>hello world</p>;
and when I view the web page, it will show me <p>hello world</p>
, but parsed as HTML.
I am wondering if I would be able to do the same thing with ruby, so puts '<p>hello world</p>'
in index.rb would show the same thing as index.php.
I know about both Rails and Sinatra, but I do not want to have a ruby process running constantly. Sinatra would be perfect, but I have to keep the script running, and restart it after each modification.
I just want to have to save the file, and then that's all. Everything has been updated and no processes need to run.
Is there any way to do this?
The closest thing you'll get is Passenger which is a support module for Apache and Nginx that runs Rack-based Ruby applications.
It will spin up Ruby processes when necessary and will terminate them when they're no longer in use. It's actually quite efficient and even a very modest VPS (512MB) can handle a significant amount of traffic running several sites.
The model of just dumping .php
files on the server and working from there is not scalable, you'll quickly end up with a mess of code. Modern PHP sites use a framework like Laravel which has a routing layer and deploying the application is not as simple as uploading a few files. If you compare a good PHP site with a good Ruby site there's a lot of commonality there, both require a proper deployment procedure rather than ad-hoc dumping files on the server.
Once you get used to it, using a deployment manager like Capistrano is far easier than the arcane method of using FTP. It produces consistent results, it avoids crashing your site during updates, and it can be used more effectively by teams since whatever operations required to get the site operating correctly are expressed in code. Deployment automation is very valuable.
It sounds to me like you're doing a lot of development on the server itself which is a bad habit that you need to break. Create a local development environment and work there, then push your changes live only after you've tested them. Tools like Vagrant make it easy to create a server environment on your machine if your operating system isn't as conducive to that sort of thing. If your target host is Linux-based, you can develop locally with a Linux server environment.
By default Rails has an auto-loader that will kick in when in development mode, most routine changes are automatically applied without having to restart your server.
I think you'll find that after you get over the initial learning curve on Rails you'll be very productive. Sinatra is more light-weight and requires less learning, but it also does a lot less out of the box and its unstructured nature can lead to chaos. Rails has very strong conventions that will help guide you when trying to solve problems, there's a place for everything and everything goes in its place.