Ruby and PHP are not the same thing. Ruby is a general purpose computer language that can be used to process http requests, among other things. PHP has evolved into a more general purpose language, but in its roots it's made to easily process http requests out of the box.
What that means is that the PHP language processor has everything built in to interact with the Apache server (or nginx, lighttpd, etc.) and run a script when a URL is requested on the server. That script will inherit an environment that includes get variables (the "query" part of the url), post variables (passed in as the body of the request), and various information about the http request, the web server, etc. All of that is presented to your script without you having to do anything else. On the other side, your script just needs to "print" and the information will make it out to the web browser on the other end.
Ruby is a very different beast. It's a general purpose language that wasn't built specifically for use on a web server, so to get this same functionality you have to use some sort of framework - even if it's just a gem - to get information from the server that you'll need as well as to put together an outbound response to the web browser on the other end.
The easiest way to get that functionality is to use Sinatra.
http://sinatrarb.com/
As you can see on the home page, you create a really simple script like this:
require 'sinatra' get '/frank-says' do 'Put this in your pipe & smoke it!' end
Then, in the browser you go to http://whatever.com/frank-says and it'll show "Put this in your pipe & smoke it!".
You still need something to connect Apache and your Sinatra application if you're using Apache, and it'll probably be Passenger or something like it. Alternately you can use a Ruby web server such as Puma.
Edit:
Here's a good article discussing Rails::API vs. Sinatra vs. Grape:
http://blog.scoutapp.com/articles/2017/02/20/rails-api-vs-sinatra-vs-grape-which-ruby-microframework-is-right-for-you
Definitely worth a read, also.