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
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
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:
# tree /var/www/html/
/var/www/html/
├── app.rb
├── config.ru
├── public
└── tmp
A basic config.ru would look like:
require 'rubygems'
require 'sinatra'
require File.expand_path '../app.rb', __FILE__
run Sinatra::Application
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 the passenger-install-apache2-module it should have provided you with the correct value.
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /var/www/html/public
LoadModule passenger_module /usr/local/rvm/gems/ruby-2.2.1/gems/passenger-5.0.28/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /usr/local/rvm/gems/ruby-2.2.1/gems/passenger-5.0.28
PassengerDefaultRuby /usr/local/rvm/gems/ruby-2.2.1/wrappers/ruby
</IfModule>
<Directory /var/www/html/public>
Require all granted
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
Remember to restart Apache after making configuration changes:
sudo service apache2 restart
For more information on using Sinatra with Passenger and Apache, see Sinatra Recipes.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.