# OSX apache2 final-stage setup hints?

**URL:** <https://www.ruby-forum.com/t/osx-apache2-final-stage-setup-hints/87868>\
**Category:** Rails\
**Created:** [March 6, 2007, 3:22pm UTC](https://www.ruby-forum.com/t/osx-apache2-final-stage-setup-hints/87868 "2007-03-06T15:22:31Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![dankitania](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@dankitania](https://www.ruby-forum.com/u/dankitania)\
**Post date:** [March 6, 2007, 3:22pm UTC](https://www.ruby-forum.com/t/osx-apache2-final-stage-setup-hints/87868/1 "2007-03-06T15:22:31Z")

</div>

Preamble: I hope people on this list will tolerate a question that,  
while _motivated_ by RoR, is not strictly _about_ RoR. I’m trying to  
let colleagues see a RoR site I’m developing, so I need to share the  
pages. I’m an academic, and doing this experimentally, so commercial  
hosting is not a possibility. I’d like to host the page on my desktop  
machine, as I’ve been doing for years with (cough) PHP pages. It seems  
that mongrel won’t let me share outside the box, and all the advice  
suggests that I should be using apache2. I’ve followed along with quite  
a few tutorials for installation and configuration, and things are  
working fine locally. The problem is with sharing.

Problem: If I use the control-panel to turn web-sharing OFF, the system  
uses apache-2, but it does NOT share pages to the outside world. If I  
turn sharing ON, then it shares to the world, _but_ it uses apache-1.

Question: Is there a trick to making the system share out apache-2  
pages?

Details: I’ve created a startup item as described at  
[http://developer.apple.com/tools/subversionxcode.html](http://developer.apple.com/tools/subversionxcode.html). The system PATH  
starts with /opt/local/bin:/opt/local/sbin:/opt/local/apache2/bin. A  
“ps aux” reveals that if web-sharing is turned OFF, then I get the  
apache-2 versions of httpd, but that if it’s turned ON, I get these, but  
_also_ apache-1 versions. This is why I think what I need to do is to  
trick the web-sharing part of the control panel.

PS: again, I’m sorry to be asking a question that is not strictly about  
RoR. I’m hoping it will be tolerated here, since it’s my guess that  
there are others in the same boat. Surely it will be good for RoR when  
folks can share pages easily from local machines, as they can with  
(again, cough) PHP.

---

<div class="post-metadata">

**Author:** ![dankitania](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@dankitania](https://www.ruby-forum.com/u/dankitania)\
**Post date:** [March 6, 2007, 3:34pm UTC](https://www.ruby-forum.com/t/osx-apache2-final-stage-setup-hints/87868/2 "2007-03-06T15:34:15Z")

</div>

Dan K. wrote:

> Preamble: I hope people on this list will tolerate a question that,  
> while _motivated_ by RoR, is not strictly _about_ RoR. I’m trying to  
> let colleagues see a RoR site I’m developing, so I need to share the  
> pages. I’m an academic, and doing this experimentally, so commercial  
> hosting is not a possibility. I’d like to host the page on my desktop  
> machine, as I’ve been doing for years with (cough) PHP pages. It seems  
> that mongrel won’t let me share outside the box, and all the advice  
> suggests that I should be using apache2. I’ve followed along with quite  
> a few tutorials for installation and configuration, and things are  
> working fine locally. The problem is with sharing.

You can use mongrel as your “outwards” facing Web server – just don’t  
give it an “-a” parameter.

E.g. this restricts mongrel to “localhost” port 8000 only:

mongrel\_rails start -d -p 8000 -a 127.0.0.1 -e production

This exposes mongrel to the outside world:

mongrel\_rails start -d -p 8000 -e production

–  
Michael W.

---

<div class="post-metadata">

**Author:** ![dankitania](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@dankitania](https://www.ruby-forum.com/u/dankitania)\
**Post date:** [March 6, 2007, 4:12pm UTC](https://www.ruby-forum.com/t/osx-apache2-final-stage-setup-hints/87868/3 "2007-03-06T16:12:00Z")

</div>

Thanks. Is there a trick to the URL, afterwards? For example, I do

mongrel\_rails start -d -p 8000 -e production

but when I point to

http://(host):8000/(page)

it doesn’t respond, _except_ if I’m accessing via the host machine.

Michael W. wrote:

> This exposes mongrel to the outside world:
> 
> mongrel\_rails start -d -p 8000 -e production
> 
> –  
> Michael W.

---

<div class="post-metadata">

**Author:** ![dankitania](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@dankitania](https://www.ruby-forum.com/u/dankitania)\
**Post date:** [March 6, 2007, 4:25pm UTC](https://www.ruby-forum.com/t/osx-apache2-final-stage-setup-hints/87868/4 "2007-03-06T16:25:27Z")

</div>

Dan K. wrote:

> Thanks. Is there a trick to the URL, afterwards? For example, I do
> 
> mongrel\_rails start -d -p 8000 -e production
> 
> but when I point to
> 
> http://(host):8000/(page)
> 
> it doesn’t respond, _except_ if I’m accessing via the host machine.

Start Mongrel and do something like:

netstat --tcp --all --numeric | less

and look for the local address that’s bound to port 8000.

Is it 0.0.0.0:8000 or some internal-only facing IP address?

–  
Michael W.

---

<div class="post-metadata">

**Author:** ![dankitania](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@dankitania](https://www.ruby-forum.com/u/dankitania)\
**Post date:** [March 6, 2007, 6:10pm UTC](https://www.ruby-forum.com/t/osx-apache2-final-stage-setup-hints/87868/5 "2007-03-06T18:10:26Z")

</div>

The netstat seems to take different arguments to those suggested.  
Anyway, if I do

```
netstat -a -n

```

I see the line

```
tcp4 0 0 *.8000 *.* 

```

LISTEN

and I wonder if that tells me something? (I’m sorry to be such a pain,  
but you see, you’ve got me all excited, thinking that I may get this  
working today, after a long time of trying. Hence, I hope you’ll excuse  
my ignorance.)

---

<div class="post-metadata">

**Author:** ![dankitania](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@dankitania](https://www.ruby-forum.com/u/dankitania)\
**Post date:** [March 6, 2007, 11:52pm UTC](https://www.ruby-forum.com/t/osx-apache2-final-stage-setup-hints/87868/6 "2007-03-06T23:52:48Z")

</div>

I don’t know about mongrel, but I’ve allowed a windows xp machine to  
host pages on the same LAN as the accessor by just opening up the port  
that the site is published to. For my situation I was using WEBrick on  
port 3000 so I just opened up port 3000 in my firewall started the  
server (script/server) and anyone on the same LAN as me could hit the  
page by using my machine’s IP:3000 for me it was something like this  
‘[http://137.28.1.130:3000](http://137.28.1.130:3000)’ I imagine something similar would work on  
OS X. As I have recently switched platforms for Rails development to  
OS X and Textmate I’ll give it a try and let you know.

-Jon

On Mar 6, 11:10 am, Dan K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![dankitania](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@dankitania](https://www.ruby-forum.com/u/dankitania)\
**Post date:** [March 7, 2007, 4:41am UTC](https://www.ruby-forum.com/t/osx-apache2-final-stage-setup-hints/87868/7 "2007-03-07T04:41:11Z")

</div>

Dan K. wrote:

> and I wonder if that tells me something? (I’m sorry to be such a pain,  
> but you see, you’ve got me all excited, thinking that I may get this  
> working today, after a long time of trying. Hence, I hope you’ll excuse  
> my ignorance.)

Alright it’s been a while since I’ve used BSD but that looks okay so the  
next question is, do you have a firewall running? It sounds like there’s  
something running on OS X that handles opening and closing ports for you  
which is probably why Mongrel isn’t being seen by the outside world.

At this point it may be easier to just hook Mongrel up through Apache.  
Unfortunately I’m also not an OS X user so I can’t tell you how to  
fiddle with that Control Panel and the different versions of Apache you  
have installed to get that to work with Apache 2.

If you want to try it with Apache 1.3 you can do something like this.  
Setup Mongrel with the -a switch and set it to 127.0.0.1 like in my  
previous example. Then in your Apache httpd.conf file you would have  
something like:

\<VirtualHost \*:80\>  
ServerName [myapp.com](http://myapp.com)  
ServerAlias [www.myapp.com](http://www.myapp.com)

ProxyPass / [http://127.0.0.1:8000/](http://127.0.0.1:8000/)  
ProxyPassReverse / [http://127.0.0.1:8000](http://127.0.0.1:8000)

Change ServerName and ServerAlias as appropriate or leave them that way  
if you just want somebody to access your box by your IP.

The ProxyPass and ProxyPassReverse directives requires that you have the  
mod\_proxy module installed so you’ll need to check for these two lines  
in httpd.conf:

LoadModule proxy\_module libexec/libproxy.so

AddModule mod\_proxy.c

The above instructions work on Linux but I don’t know if OS X handles  
the Apache config differently.

–  
Michael W.

---

<div class="post-metadata">

**Author:** ![dankitania](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@dankitania](https://www.ruby-forum.com/u/dankitania)\
**Post date:** [March 7, 2007, 1:53pm UTC](https://www.ruby-forum.com/t/osx-apache2-final-stage-setup-hints/87868/8 "2007-03-07T13:53:32Z")

</div>

Addendum: the style sheet gets used if I add

DocumentRoot (PATH\_TO\_MY\_APP)/public

but the links are still broken.

---

<div class="post-metadata">

**Author:** ![dankitania](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@dankitania](https://www.ruby-forum.com/u/dankitania)\
**Post date:** [March 7, 2007, 12:53pm UTC](https://www.ruby-forum.com/t/osx-apache2-final-stage-setup-hints/87868/9 "2007-03-07T12:53:50Z")

</div>

I’m starting to see light at the end of this tunnel…

Do I need to do any tricks with directories? If I do as suggested  
(proxying to “/”), then I lose the rest of the machine’s pages. So I  
tried as at the end of this post. This halfway works: if I browse to  
“http://(MY\_HOST)/myapp/(A\_PAGE)”, where “A\_PAGE” is the name of a page  
in my app, then I get the page, but no style sheet. Also, the links in  
the page don’t work. The links are going to e.g.  
“http://(MY\_HOST)/(ANOTHER\_PAGE)”, i.e. the “myapp” part is missing in  
the links.

The link/css issues seem to stem from a problem in the construction of  
relative filenames.

Q: Is there an additional trick with apache?

BTW, I also tried proxying to “/myapp”, i.e. without the trailing slash,  
but that leads to “page does not exist” errors on all but the  
rails-supplied “welcome aboard” page.

OK, so here is what I have so far. I’ve done the other suggested things  
to my http.conf, and it passes cleanly through a /usr/sbin/apachectl  
stop/configtest/start cycle (NB. I’m here being careful to use apache  
1.3, not the apache 2.0 that I had previously thought I would be  
required to use, which is how this thread got started!)

\<VirtualHost \*:80\>  
ServerName [myapp.com](http://myapp.com)  
ServerAlias [myapp.com](http://myapp.com)  
ProxyPass /myapp/ [http://127.0.0.1:8000/](http://127.0.0.1:8000/)  
ProxyPassReverse /myapp/ [http://127.0.0.1:8000/](http://127.0.0.1:8000/)

---

<div class="post-metadata">

**Author:** ![dankitania](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@dankitania](https://www.ruby-forum.com/u/dankitania)\
**Post date:** [March 7, 2007, 3:12pm UTC](https://www.ruby-forum.com/t/osx-apache2-final-stage-setup-hints/87868/10 "2007-03-07T15:12:37Z")

</div>

Dan K. wrote:

> to my http.conf, and it passes cleanly through a /usr/sbin/apachectl  
> stop/configtest/start cycle (NB. I’m here being careful to use apache  
> 1.3, not the apache 2.0 that I had previously thought I would be  
> required to use, which is how this thread got started!)
> 
> \<VirtualHost \*:80\>  
> ServerName [myapp.com](http://myapp.com)  
> ServerAlias [myapp.com](http://myapp.com)  
> ProxyPass /myapp/ [http://127.0.0.1:8000/](http://127.0.0.1:8000/)  
> ProxyPassReverse /myapp/ [http://127.0.0.1:8000/](http://127.0.0.1:8000/)

Okay two more changes.

In your httpd.conf setup change it to:

\<VirtualHost \*:80\>  
ServerName [myapp.com](http://myapp.com)  
ServerAlias [myapp.com](http://myapp.com)  
ProxyPass /myapp [http://127.0.0.1:8000/myapp](http://127.0.0.1:8000/myapp)  
ProxyPassReverse /myapp [http://127.0.0.1:8000/myapp](http://127.0.0.1:8000/myapp)

Then in your command line that starts Mongrel (you’ll need a recent  
version of Mongrel for this) you need to add:

–prefix /myapp

E.g.:

mongrel\_rails start -d -p 8000   
-a 127.0.0.1   
-e production   
–prefix /myapp

–  
Michael W.

---

<div class="post-metadata">

**Author:** ![dankitania](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@dankitania](https://www.ruby-forum.com/u/dankitania)\
**Post date:** [March 7, 2007, 4:17pm UTC](https://www.ruby-forum.com/t/osx-apache2-final-stage-setup-hints/87868/11 "2007-03-07T16:17:17Z")

</div>

Michael, you’re a gem. Links work, and the style sheet is being obeyed.

The one remaining problem is images – they are not showing up.

PS. I have Mongrel Web Server 1.0.1

---

<div class="post-metadata">

**Author:** ![dankitania](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@dankitania](https://www.ruby-forum.com/u/dankitania)\
**Post date:** [March 7, 2007, 4:46pm UTC](https://www.ruby-forum.com/t/osx-apache2-final-stage-setup-hints/87868/12 "2007-03-07T16:46:56Z")

</div>

Dan K. wrote:

> Michael, you’re a gem. Links work, and the style sheet is being obeyed.
> 
> The one remaining problem is images – they are not showing up.

That should work with just the DocumentRoot pointing to the public  
directory within the VirtualHost directive. Did you put the images  
somewhere else? When you view the source of the page, what path is it  
using for the images?

You could try something like this within VirtualHost:

ProxyPass /myapp/images !  
Alias /myapp/images /path/to/public/images

assuming it’s trying to use /myapp/images as the path to the images in  
the source.

–  
Michael W.

---

<div class="post-metadata">

**Author:** ![dankitania](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@dankitania](https://www.ruby-forum.com/u/dankitania)\
**Post date:** [March 7, 2007, 5:24pm UTC](https://www.ruby-forum.com/t/osx-apache2-final-stage-setup-hints/87868/13 "2007-03-07T17:24:05Z")

</div>

Dan K. wrote:

> Alias /(APPNAME)/images APP\_PATH)/public/images
> 
> # test 3
> 
> ProxyPass /(APPNAME)/public/images !  
> Alias /(APPNAME)/public/images APP\_PATH)/public/images

Where are you setting DocumentRoot? Do you have any funky mod\_rewrite  
stuff (RewriteCond, RewriteRule, etc.) going on?

If you view source on one of your Rails pages with an image, what’s the  
URL it is trying to access?

–  
Michael W.

---

<div class="post-metadata">

**Author:** ![dankitania](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@dankitania](https://www.ruby-forum.com/u/dankitania)\
**Post date:** [March 7, 2007, 5:18pm UTC](https://www.ruby-forum.com/t/osx-apache2-final-stage-setup-hints/87868/14 "2007-03-07T17:18:34Z")

</div>

Um, none of the following works. My images are in  
(MY\_APP)/public/images.

# test 1

ProxyPass /images !  
Alias /images (APP\_PATH)/public/images

# test 2

ProxyPass /(APPNAME)/images !  
Alias /(APPNAME)/images APP\_PATH)/public/images

# test 3

ProxyPass /(APPNAME)/public/images !  
Alias /(APPNAME)/public/images APP\_PATH)/public/images

Michael, you’re being amazingly patient with this.

---

<div class="post-metadata">

**Author:** ![dankitania](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@dankitania](https://www.ruby-forum.com/u/dankitania)\
**Post date:** [March 7, 2007, 5:45pm UTC](https://www.ruby-forum.com/t/osx-apache2-final-stage-setup-hints/87868/15 "2007-03-07T17:45:12Z")

</div>

> Where are you setting DocumentRoot?

I’m not setting DocumentRoot inside the , because I found  
that if I did so, my other pages disappeared.

> Do you have any funky mod\_rewrite  
> stuff (RewriteCond, RewriteRule, etc.) going on?

Well, nothing that I have set myself. I do see the following in the  
file, though.

 RewriteEngine On RewriteCond %{REQUEST\_METHOD} ^TRACE RewriteRule .\* - [F]

> If you view source on one of your Rails pages with an image, what’s the  
> URL it is trying to access?

The images are being accessed from the stylesheet. I should have  
pointed that out. For example, in

(MY\_APP)/public/stylesheets/style.css

I have a line like the following:

background-image: url(’/images/background-01.jpg’);

---

<div class="post-metadata">

**Author:** ![dankitania](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@dankitania](https://www.ruby-forum.com/u/dankitania)\
**Post date:** [March 7, 2007, 6:44pm UTC](https://www.ruby-forum.com/t/osx-apache2-final-stage-setup-hints/87868/16 "2007-03-07T18:44:24Z")

</div>

Dan K. wrote:

> The images are being accessed from the stylesheet. I should have  
> pointed that out. For example, in
> 
> (MY\_APP)/public/stylesheets/style.css
> 
> I have a line like the following:
> 
> background-image: url(‘/images/background-01.jpg’);

Okay try it like this:

ProxyPass /images [http://127.0.0.1:8000/myapp/images](http://127.0.0.1:8000/myapp/images)

with no Alias

–  
Michael W.

---

<div class="post-metadata">

**Author:** ![dankitania](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@dankitania](https://www.ruby-forum.com/u/dankitania)\
**Post date:** [March 7, 2007, 7:23pm UTC](https://www.ruby-forum.com/t/osx-apache2-final-stage-setup-hints/87868/17 "2007-03-07T19:23:20Z")

</div>

_success_ at last! Michael, thank you _so_ much for your very generous  
help, and for your patience through so many exchanges.

For the sake of anyone else who is trying this, below I’ve got the  
recipe that worked for me. Here, MYAPP stands for the application name  
and URL stands for the URL of the application (although I haven’t used  
that).

1. SYSTEM DESCRIPTION

OSX + Apache-1.3 + mongrel\_rails-1.0.1 rails-1.2.2

1. INSTRUCTIONS

2.1 Setup

Add the /private/etc/httpd.conf, where MYAPP is the name of the  
application.

\<VirtualHost \*:80\>  
ServerName [MYAPP.com](http://MYAPP.com)  
ServerAlias [MYAPP.com](http://MYAPP.com)  
ProxyPass /MYAPP [http://127.0.0.1:8000/MYAPP](http://127.0.0.1:8000/MYAPP)  
ProxyPassReverse /MYAPP [http://127.0.0.1:8000/MYAPP](http://127.0.0.1:8000/MYAPP)  
ProxyPass /images [http://127.0.0.1:8000/MYAPP/images](http://127.0.0.1:8000/MYAPP/images)

Then do

```
/usr/sbin/apachectl stop
/usr/sbin/apachectl configtest
/usr/sbin/apachectl start

```

and be sure that there are no errors.

2.2 Start the server

Run the following to start the server

mongrel\_rails start -d -p 8000 -a 127.0.0.1 -e production --prefix  
/MYAPP

1. CONCLUSIONS

Some people are awfully nice on the web, helping out strangers 🙂

---

<div class="post-metadata">

**Author:** ![dankitania](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9a140/32.png) [@dankitania](https://www.ruby-forum.com/u/dankitania)\
**Post date:** [March 8, 2007, 3:14am UTC](https://www.ruby-forum.com/t/osx-apache2-final-stage-setup-hints/87868/18 "2007-03-08T03:14:46Z")

</div>

Dan K. wrote:

> _success_ at last! Michael, thank you _so_ much for your very generous  
> help, and for your patience through so many exchanges.

It probably would’ve been easier to ask an OS X guru how to open up a  
port for Mongrel 😃

–  
Michael W.
