Accidental Technologist

Musings about Entrepreneurship, Technology and Software Development

  • Home
  • About
  • Still River Software
  • Privacy Policy

Powered by Genesis

You are here: Home / Ruby / My Improved Rails Development Environment on the Mac

My Improved Rails Development Environment on the Mac

April 7, 2009 by Rob Bazinet

Tweet

I use Apache and Phusion Passenger for my production Ruby on Rails applications, it has worked well and the deployment story couldn’t be any easier.

Most Ruby on Rails developers probably are familiar with running either WebBrick or Mongrel on their development system with the usual script/server command in a terminal session and access their application in the browser with http://localhost:3000.

This works fine in most circumstances but it does really mimic how I setup a web server in a production environment.  One application I have been working on recently makes pretty heavy use of subdomains, such as customer1.myapp.com, customer2.myapp.com, etc. and implementing this on my Mac, where I do development, is not as trivial as I had hoped.  It seems creating wildcard domains on the Mac is not possible and something strange has been going on relating to sessions and ports other than 80.

Since Apache2 is already running on my Mac I decided to investigate running Passenger Phusion alongside Apache as I do in production.

Passenger Setup

Setting up Passenger is pretty straightforward, just need to install the gem and create a configuration file.  Installing the gem:

sudo gem install passenger

Once the gem is finished install then I installed the required Apache module:

sudo passenger-install-apache2-module

Passenger uses configuration files much like those used by Apache2.  I needed to create a configuration file for Apache to use to load up mod_passenger when it started along with my virtual host information.  My file is called passenger.conf and is kept in /etc/apache2/other directory. The main apache2 configuration file (/etc/apache2/httpd.conf) has a command to load all files ending in .conf from the other directory to be processed.  My setup looks like this:

#/etc/apache2/other/passenger.conf
LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-2.1.3/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-2.1.3
PassengerRuby /usr/local/bin/ruby
# Set the default environment to development
RailsEnv development
# Which directory do you want Apache to be able to look into for projects?
<Directory "/Users/rbazinet/rails_apps">
Order allow,deny
Allow from all
</Directory>
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/Users/rbazinet/rails_apps/myrailsapp/public"
ServerName myrailsapp.dev
ServerAlias myrailsapp.dev *.myrailsapp.dev
</VirtualHost>

I decided to put the virtual host info in here instead of using something like Passenger Preference Pane.  This option would be cleaner and easier to manage but it didn’t work for me, seemed to just hang and then lose all of my virtual host setup.  After several attempts it hardly seemed worth the pain, maybe your mileage will vary.

After the configuration file is in place, a restart of Apache will load up the configuration file:

sudo apachectl restart

Name Resolution

One issue that needs to be addressed is how our local, customer domain will be resolved.  One approach is adding entries to the /etc/hosts file to represent domains and subdomains I have, something like this:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1    localhost mywebapp.dev company1.mywebapp.dev
255.255.255.255    broadcasthost
::1             localhost
fe80::1%lo0    localhost

This seems to work just fine but thanks to gem named Ghost:

This gem is designed primarily for web developers who need to add and modify hostnames to their system for virtual hosts on their local/remote web server. However, it could be of use to other people who would otherwise modify their /etc/hosts file manually and flush the cache.

Ghost is a nice little gem used from the command line that lets me add host names, list them, delete etc. without modifying the hosts file.  A simple command such as:

ghost add customer1.mywebapp.dev

Is all that is needed to be able to browse to customer1.mywebapp.dev, without any resolution issues.  It’s easy to added and delete right from the command-line with Ghost.  The projects GitHub page says this works with Linux too.

Conclusion

This setup has solved my problems as far as getting these domains to resolve on my development system.  There are probably many ways to solve this problem but the overall solution worked and now has me using Passenger, which is on my production systems.  I have always believe developers should be writing software on the software they use for production and Apache with Passenger has me a whole lot closer.

I have not addressed debugging Rails apps in this configuration yet but I did find a plug-in called socket-debugger on GitHub.  It appears to allow debugging in the style we are used to with WebBrick or Mongrel.  I would love to hear with others are using to debug Rails apps on the Mac using Passenger.

There are also a couple other good resources for running Passenger in this configuration.  The first is from Railscasts called Passenger in Development, which I found after I setup my environment.  The other is a screen cast from Peepcode.

 

Technorati Tags: Ruby,Ruby on Rails,Passenger Phusion,Apache

Share this:

  • LinkedIn
  • Twitter
  • Facebook
  • Email
  • More
  • Pinterest
  • Tumblr
  • Pocket
  • Reddit

Related

Filed Under: Ruby

Care about your privacy? I do and use Fathom Analytics on this site.

Fathom Analytics

Comments

  1. Mike Breen says

    April 7, 2009 at 9:35 am

    did you try the ghost gem for setting up subdomains on you Mac?
    http://www.robbyonrails.com/…/get-to-know-a-g

  2. Mike Breen says

    April 7, 2009 at 9:35 am

    did you try the ghost gem for setting up subdomains on you Mac?

    http://www.robbyonrails.com/…/get-to-know-a-g

  3. Rob Bazinet says

    April 7, 2009 at 9:36 am

    @Mike Umm…did you read my blog post???
    Yes, the post talks about Ghost.

  4. Rob Bazinet says

    April 7, 2009 at 9:36 am

    @Mike Umm…did you read my blog post???

    Yes, the post talks about Ghost.

  5. Mike Breen says

    April 7, 2009 at 9:40 am

    heh, heh. sorry about Rob. The name resolution section was missing in my reader?

  6. Mike Breen says

    April 7, 2009 at 9:40 am

    heh, heh. sorry about Rob. The name resolution section was missing in my reader?

  7. Double Shot #426 « A Fres says

    April 8, 2009 at 6:16 am

    RE: My Improved Rails Development Environment on the Mac

    Pingback from Double Shot #426 « A Fresh Cup

  8. Double Shot #426 « A Fresh Cup says

    April 8, 2009 at 6:16 am

    RE: My Improved Rails Development Environment on the Mac

    Pingback from Double Shot #426 « A Fresh Cup

  9. Theo says

    April 8, 2009 at 10:53 am

    The "Passenger in Development" railscasts link is wrong.

  10. Theo says

    April 8, 2009 at 10:53 am

    The "Passenger in Development" railscasts link is wrong.

  11. Rob Bazinet says

    April 8, 2009 at 4:46 pm

    @Theo – Fixed! Thank you for the heads up, I was a victim of the wrong copy and paste.

  12. Rob Bazinet says

    April 8, 2009 at 4:46 pm

    @Theo – Fixed! Thank you for the heads up, I was a victim of the wrong copy and paste.

  13. The Cave » Blog Archive & says

    April 20, 2009 at 12:11 pm

    RE: My Improved Rails Development Environment on the Mac

    Pingback from The Cave » Blog Archive » Rails + Passenger + Apache

  14. The Cave » Blog Archive » Rails + Passenger + Apache says

    April 20, 2009 at 12:11 pm

    RE: My Improved Rails Development Environment on the Mac

    Pingback from The Cave » Blog Archive » Rails + Passenger + Apache

  15. top online gambling site list says

    July 21, 2009 at 7:48 am

    I had problems creating models and scaffold projects because /tmp/mysql.sock would not be found. A simple solution to this was to swap "localhost" with "127.0.0.1"(local ip). Just thought that could be added to the tutorial perhaps.

  16. top online gambling site list says

    July 21, 2009 at 7:48 am

    I had problems creating models and scaffold projects because /tmp/mysql.sock would not be found. A simple solution to this was to swap "localhost" with "127.0.0.1"(local ip). Just thought that could be added to the tutorial perhaps.

  17. movie online says

    July 22, 2009 at 8:36 am

    thanks for the great article, this really nice blog

  18. movie online says

    July 22, 2009 at 8:36 am

    thanks for the great article, this really nice blog

  19. Law degree says

    August 1, 2009 at 2:41 am

    I have always believe developers should be writing software on the software they use for production and Apache with Passenger has me a whole lot closer.

  20. Law degree says

    August 1, 2009 at 2:41 am

    I have always believe developers should be writing software on the software they use for production and Apache with Passenger has me a whole lot closer.

  21. ??????? says

    August 15, 2009 at 11:11 pm

    thanks for the great article, this really nice blog

  22. ??????? says

    August 15, 2009 at 11:11 pm

    thanks for the great article, this really nice blog

  23. ??????? says

    August 15, 2009 at 11:16 pm

    thanxs aloooooooT

  24. ??????? says

    August 15, 2009 at 11:16 pm

    thanxs aloooooooT

  25. ????? says

    August 15, 2009 at 11:24 pm

    @Theo – Fixed! Thank you for the heads up, I was a victim of the wrong copy and paste

  26. ????? says

    August 15, 2009 at 11:24 pm

    @Theo – Fixed! Thank you for the heads up, I was a victim of the wrong copy and paste

  27. save lifestyle story says

    August 25, 2009 at 1:21 am

    First of all, I admit that this is kinda difficult to follow, at least to me. Nevertheless, I did it after several times of trial and error. Thanks anyway. 🙂

  28. save lifestyle story says

    August 25, 2009 at 1:21 am

    First of all, I admit that this is kinda difficult to follow, at least to me. Nevertheless, I did it after several times of trial and error. Thanks anyway. 🙂

  29. unlocking blackberry says

    August 26, 2009 at 1:59 pm

    Incredibly detailed analysis that have really helped me out, so a big thank you for taking the time to write it all up

  30. unlocking blackberry says

    August 26, 2009 at 1:59 pm

    Incredibly detailed analysis that have really helped me out, so a big thank you for taking the time to write it all up

  31. Ryan says

    March 17, 2010 at 12:08 am

    Thanks for the post. Have you tried installing passenger with a ruby 1.9.1 and rails 3 install? Installing the passenger apache2 module fails for me.

  32. Ryan says

    March 17, 2010 at 12:08 am

    Thanks for the post. Have you tried installing passenger with a ruby 1.9.1 and rails 3 install? Installing the passenger apache2 module fails for me.

Recent Posts

  • How to Fix Rails Flash Rendering When Using Hotwire
  • Hotwire Fix for CORS Error when using Omniauth
  • Fix Installation of Ruby using rbenv on macOS Big Sur
  • RailsConf 2021 and the Future of Conferences
  • Fixing Out of Diskspace Errors on Amazon EC2

Categories

Services I Love

HatchBox - Easy Rails Deploys Fathom Analytics
Follow @rbazinet

Rob Bazinet
@rbazinet

  • Exactly this…. https://t.co/yWj7fZ01HR
    about 17 hours ago
  • https://t.co/EmagdpLoNv "Introducing GitHub Copilot X · GitHub"
    about 1 day ago
  • RIP Gordon Moore: https://t.co/c5J9LaHrj8
    about 1 day ago
  • Our daughter works as a teaching assistant at a local K-8 public school. It’s become apparent that students today r… https://t.co/p2t912GVyc
    about 2 days ago
  • Working to wrap up my current consulting gig by mid-April. I will be looking for the next thing soon. If anyone has… https://t.co/sg3cSV9yqM
    about 3 days ago
  • RSS - Posts
  • RSS - Comments
Find me on Mastodon