How to serve static websites and Passenger Rails projects from the same Mac OS X Apache instance
When your http://localhost/~username/ sites go haywire, it's time to dig into your Apache config files
As Rails pros know, Phusion Passenger allows you to serve multiple Rails apps on the same Apache webserver instance with few configuration or deployment headaches. When you install it in your local Mac dev environment, you can easily work on a bunch of Rails projects simultaneously without having to manually start and stop individual server instances all the time. The OS X Passenger preference pane makes deployment even easier. Just add a project, give it a custom local URL, and point it at a directory. You're good to go.
But what happens if you're already using OS X's built-in Apache webserver to dish up local content such as PHP applications or static HTML? When I first got Passenger up and running, all of my local sites in /Users/<username>/Sites/ stopped working. It took a bunch of digging, but I eventually realized that something in my Apache configuration had gotten messed up during the Passenger installation process. I was missing the configuration file for my OS X user account. OS X generates this file the first time you enable web sharing for any individual user. It's responsible for mapping your /Sites subdirectory to localhost URLs, so that http://localhost/~<username>/myapplication/ points to /Sites/myapplication/index.html.
The file should live here:
/private/etc/apache2/users/<username>.conf
If it gets blown away, all you need to do is replace it and populate it with meaningful instructions. The contents should look like this:
<Directory "/Users/<username>/Sites/"> Options Indexes MultiViews AllowOverride None Order allow,deny Allow from all </Directory>
Once you've created and populated the file, just bounce Apache by turning Web Sharing off and then on again in the Sharing prefpane of System Preferences. Voila, your http://localhost/~username/ URLs should start working again.
Just in case you want a little more background, here's how this file gets executed by Apache:
-
The root Apache config file is here:
/private/etc/apache2/httpd.conf
-
It includes the userdir module for serving local user content:
LoadModule userdir_module libexec/apache2/mod_userdir.so
-
Further down, it includes a separate config file for user directories:
# User home directories Include /private/etc/apache2/extra/httpd-userdir.conf
-
Inside that file, you should see code like this:
# Settings for user home directories # # Required module: mod_userdir # # UserDir: The name of the directory that is appended onto a user's home # directory if a ~user request is received. Note that you must also set # the default access control for these directories, as in the example below. # UserDir Sites # # Users might not be in /Users/*/Sites, so use user-specific config files. # Include /private/etc/apache2/users/*.conf
-
Finally the line
Include /private/etc/apache2/users/*.confcalls the<username>.conffile we created above.
Comments: 1 so far
Leave a comment
About Pathfinder
Follow the Blog
-
Get a monthly update on best practices for delivering successful software.
Subscribe via email
Subscribe via RSS
Categories
Topics
Archives
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006
Blogroll
Recent
- Elements of Testing Style
- Aesthetics and Web Design
- Asterisk-Java Testing with Groovy
- 3 Misuses of Code Comments
- Fluently NHibernate
- Digging a Hole and Covering it with Leaves — The Software Development Version
- The Importance of User Experience - Do You Understand It in Your Bones?
- Writing Your Own Protocol With NSURLProtocol
- What’s In Your Dock: iPhone edition
- Feature Fatigue


Hi,
That’s really very important article. That will be good way to users who want to develop apache web server. Thank you.
Comment by vps, Saturday, June 6, 2009 @ 9:36 pm