I am a complete noob and I’m sure I’ve done something wrong, but I’m at a loss in how to make it work. I’ve written a basic “Hello World” script and put it in my /var/www/html/sites directory on Centos. I’ve followed the DO tutorial to install apache, passenger, and sinatra. Tutorial. When I go to my webpage using the ip address I get the apache welcome screen as I should. When I go to http://ip/ruby_script.rb, I get the contents of the script. I can’t seem to get the script to actually run. The script requires sinatra, so I run “ruby script.rb” at the command line before I try and hit the web page so that sinatra is running. I’m sure I’m missing a fundamental step because everything I read seems to indicate that this is a simple process. If you need more specifics to help me, please let me know. I’m feeling a little stupid because I think this should be very simple. BTW, this is the simple script I’m trying to run.
#!/usr/bin/ruby
require 'twilio-ruby'
require 'sinatra'
get '/' do
'Hello World! Currently running version ' + Twilio::VERSION + \
' of the twilio-ruby library.'
end
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
The Sinatra script should not be located directly in the web directory. You’ll also need a
config.ru
file that describes how Passanger should run the programs. You file layout should look something like:A basic config.ru would look like:
And your Apache configuration should look similar to the following. It’s important to note that the path to your
passenger_module
might be different. When you ran thepassenger-install-apache2-module
it should have provided you with the correct value.Remember to restart Apache after making configuration changes:
For more information on using Sinatra with Passenger and Apache, see Sinatra Recipes.