# Running Ruby on built in Apache server on Mac

**URL:** <https://www.ruby-forum.com/t/running-ruby-on-built-in-apache-server-on-mac/184092>\
**Category:** Rails\
**Created:** [February 24, 2010, 9:41pm UTC](https://www.ruby-forum.com/t/running-ruby-on-built-in-apache-server-on-mac/184092 "2010-02-24T21:41:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![david2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a87d85/32.png) [@david2](https://www.ruby-forum.com/u/david2)\
**Post date:** [February 24, 2010, 9:41pm UTC](https://www.ruby-forum.com/t/running-ruby-on-built-in-apache-server-on-mac/184092/1 "2010-02-24T21:41:12Z")

</div>

I’m trying to ease into Ruby and Rails.  
Is it possible to simply load a Ruby template file similar to the way  
I load a PHP file?  
The Mac built in Apache web server is preconfigured to support PHP,  
but I can’t find out how to get it to support Ruby. Is there a simple  
way to add Ruby support?  
Can I even use Ruby this way without building a whole Rails app?  
Is there a better place to ask?

Thanks

---

<div class="post-metadata">

**Author:** ![david2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a87d85/32.png) [@david2](https://www.ruby-forum.com/u/david2)\
**Post date:** [February 24, 2010, 9:46pm UTC](https://www.ruby-forum.com/t/running-ruby-on-built-in-apache-server-on-mac/184092/2 "2010-02-24T21:46:28Z")

</div>

I think the closest thing there is to what you’re looking for is  
mod\_rails  
(aka Passenger) [http://www.modrails.com/](http://www.modrails.com/)

Good install directions:  
[http://www.robbyonrails.com/articles/2010/02/08/installing-ruby-on-rails-passenger-postgresql-mysql-oh-my-zsh-on-snow-leopard-fourth-edition](http://www.robbyonrails.com/articles/2010/02/08/installing-ruby-on-rails-passenger-postgresql-mysql-oh-my-zsh-on-snow-leopard-fourth-edition)

---

<div class="post-metadata">

**Author:** ![david2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a87d85/32.png) [@david2](https://www.ruby-forum.com/u/david2)\
**Post date:** [February 24, 2010, 9:53pm UTC](https://www.ruby-forum.com/t/running-ruby-on-built-in-apache-server-on-mac/184092/3 "2010-02-24T21:53:34Z")

</div>

Hi, and of course you can just run Ruby stuff by itself. You don’t need  
Rails if you are doing a Rails app…  
In the tutorial below you can start running Ruby programs as soon as you  
have Ruby installed in your system…

> **[Dan Benjamin](https://danbenjamin.com)**
>
> Dan Benjamin's personal website.

Cheers.

---

<div class="post-metadata">

**Author:** ![david2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a87d85/32.png) [@david2](https://www.ruby-forum.com/u/david2)\
**Post date:** [February 24, 2010, 10:26pm UTC](https://www.ruby-forum.com/t/running-ruby-on-built-in-apache-server-on-mac/184092/4 "2010-02-24T22:26:52Z")

</div>

I went through and installed Passenger, says its started in the log.  
If I try to load a file from the webserver with extension .rb or .erb,  
I get the text file without having been processed by Ruby. Should this  
work? What else do I need to do to get a ruby template file to work?

Thanks

---

<div class="post-metadata">

**Author:** ![david2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a87d85/32.png) [@david2](https://www.ruby-forum.com/u/david2)\
**Post date:** [February 24, 2010, 10:35pm UTC](https://www.ruby-forum.com/t/running-ruby-on-built-in-apache-server-on-mac/184092/5 "2010-02-24T22:35:39Z")

</div>

On Feb 24, 9:24 pm, david2 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I went through and installed Passenger, says its started in the log.  
> If I try to load a file from the webserver with extension .rb or .erb,  
> I get the text file without having been processed by Ruby. Should this  
> work? What else do I need to do to get a ruby template file to work?

Passenger is designed to run rack applications, these must be laid out  
on disk in a certain way (  
[http://www.modrails.com/documentation/Users%20guide.html#\_deploying\_a\_rack\_based\_ruby\_application](http://www.modrails.com/documentation/Users%20guide.html#_deploying_a_rack_based_ruby_application)  
). This can be something very small - a sinatra app can be tiny!

Fred

---

<div class="post-metadata">

**Author:** ![david2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a87d85/32.png) [@david2](https://www.ruby-forum.com/u/david2)\
**Post date:** [February 24, 2010, 10:42pm UTC](https://www.ruby-forum.com/t/running-ruby-on-built-in-apache-server-on-mac/184092/6 "2010-02-24T22:42:05Z")

</div>

So it sounds like I can’t have Ruby process a standalone template  
file? So I can’t use Ruby as a simple replacement for PHP without  
adhering more to an application convention for a framework?

I have a mostly static website that I use PHP for simple things, like  
handling including fragments of HTML that repeat on multiple pages.

It sounds like I can’t reasonably use Ruby as a replacement for PHP in  
this situation?

I’d rather stick to one language and environment if I can. Sounds like  
I’d need to keep using PHP for my mostly static website and Ruby on  
Rails for my web apps. I had hoped to avoid two languages.

On Feb 24, 4:34 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![david2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a87d85/32.png) [@david2](https://www.ruby-forum.com/u/david2)\
**Post date:** [February 24, 2010, 11:34pm UTC](https://www.ruby-forum.com/t/running-ruby-on-built-in-apache-server-on-mac/184092/7 "2010-02-24T23:34:46Z")

</div>

This is all very confusing. I’ve been googling…

I see references to .erb files, .rhtml and .erb.html files. Sounds  
like what I want to do can be done, but I don’t get the impression its  
done very often because it doesn’t seem very easy nor straightforward.

There used to be eRuby. But it sounds like you can use the erb module  
in Ruby instead.

I’ve found instructions where you can manually create a ruby script  
and a CGI command to run whatever extension you define in an Apache  
config file. Its an amazingly manual configuration process.

Does no one do this? Is it Ruby on Rails or bust? Can you use Ruby  
template files, ie Ruby embedded in HTML on an Apache webserver or do  
most folks just use PHP if this is needed and only use Ruby for web  
applications?

Thanks

On Feb 24, 4:34 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![david2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a87d85/32.png) [@david2](https://www.ruby-forum.com/u/david2)\
**Post date:** [February 25, 2010, 4:06pm UTC](https://www.ruby-forum.com/t/running-ruby-on-built-in-apache-server-on-mac/184092/8 "2010-02-25T16:06:34Z")

</div>

david2 wrote:

> This is all very confusing. I’ve been googling…

It’s not really all that confusing, you’re just confusing it all.

> I see references to .erb files, .rhtml and .erb.html files. Sounds  
> like what I want to do can be done, but I don’t get the impression its  
> done very often because it doesn’t seem very easy nor straightforward.

Embedded Ruby (.erb). Ruby HTML (.rhtml). The .rhtml is an older  
convention that isn’t used so much in newer versions of Rails. The  
rendering engine (.erb) has been separated from the template format  
(.html). This eases support for handling multiple representations of  
pages. For example you might have a different layout for mobile devices.  
The newer convention would allow you to name the two layouts  
accordingly, such as index.html.erb & index.mobile.erb. The later could  
still be HTML, but formatted for mobile devices. Both still use Embedded  
Ruby. There are also other engines, such as builder (index.xml.builder)  
and Ruby JavaScript (index.js.rjs).

I think where you might be getting confused is that in the case of PHP  
the “engine,” or “intelligence,” is wrapped up inside the Apache module.  
It’s all that C code that really does the grunt work for PHP template  
rendering.

> I’ve found instructions where you can manually create a ruby script  
> and a CGI command to run whatever extension you define in an Apache  
> config file. Its an amazingly manual configuration process.
> 
> Does no one do this? Is it Ruby on Rails or bust? Can you use Ruby  
> template files, ie Ruby embedded in HTML on an Apache webserver or do  
> most folks just use PHP if this is needed and only use Ruby for web  
> applications?

You don’t seem to be listening to the earlier replies. It is by no means  
Ruby on Rails or bust! There are many options ranging from the most  
fundamental Rack application, through Sinatra and all the way up to  
Rails.

As I said before, a lot of the “intelligence” of PHP is the Apache  
module itself. This might give you a false sense that PHP is simpler  
than a Ruby deployment. Maybe that’s somewhat so, but it’s also less  
flexible than something like Passenger Phusion  
([http://www.modrails.com/](http://www.modrails.com/)) + Rack ([http://rack.rubyforge.org/](http://rack.rubyforge.org/)). Phusion  
is a web interface that connects Apache (or Nginx) to any Rack  
application.

A Rack application can be as simple as:

class HelloWorld  
def call(env)  
[200, {“Content-Type” =\> “text/plain”}, [“Hello world!”]]  
end  
end

If you just want to render some ERB templates then (as Frederick  
mentioned) Sinatra ([Sinatra: README](http://www.sinatrarb.com/intro.html)) is an excellent  
choice.

Given that a lot (now most) Ruby frameworks and web servers are based on  
Rack there is a lot of choice in the Ruby world. This is not a bad  
thing! It allows us to scale our solutions to target specific needs.

In your situation I would strongly suggest you look at Sinatra. I’m mean  
really look at it and not just glance at their home page.
