fyi - if you have file fault on ... your home folder in /Users/yourname has tight permissions (700) which will prevent apache from reading your rails projects folder if it is there; fix/change it by doing "chmod 755 /Users/yourname" - worked for me, after hours of fighting with a somewhat generic "Forbidden"; also consider setting the Apache "Listen" directive to "Listen 127.0.0.1:80" to avoid somebody else in your subnet accessing your server/site
@Ryan and @Marc
When it comes to clustering I believe it behaves pretty much the same way as if you were using Apache to run a PHP site, should you be any more familiar with that.
Just put a load balancer in front of 2 or more servers, each having it's own Apache + Passsenger.
@James, thanks for that! It would explain why I didn't get the 403 error.
@Marc, Passenger spawns new instances of your Rails app on demand, as your site needs it. This way it is very efficient because it uses only the resources it needs. Also, according to the benchmarks, it is better on memory and performance than other servers when combined with Ruby Enterprise Edition. I highly recommend it.
As for load balancing across a cluster of machines, I don't know if Passenger does this. Anyone want to chime in?
it was a message from the almighty himself, I just browsed to railscasts to search for such a topic... And what do ya know, top and center!!
So perfect!
Maybe there should be a note stating that most of the information in this screencast is out of date. I watched the entire thing only to find out that Rails is now on Lighthouse. :(
Sorry for the double entry but it turns out Jame's solution also worked for the test-page-problem. I have my rails projects in ~/Sites, so chmoding ~/Sites to 711 worked for me.
I have the same issue as Boza. Passenger seems to set up the routing correctly, but accessing the resulting URL in Safari loads a "Test Page for Apache Installation".
I haven't found a entry in /etc/apache2/httpd.conf that looks like it might cause this. Any ideas?
The "Forbidden" errors are permission issues. Apache needs the Rails application directory and public directory to have at least 755 permissions. It also needs all directories in the path before the Rails application to have at least 711.
My problem was my Documents folder. My application was inside of this and it was not executable by anyone. I fixed it with the command:
chmod 711 ~/Documents
I also assume the log and tmp (plus all tmp subdirectories) need to be writeable, but I haven't verified that. I switched those to 777.
For those worried about the start up lag in production, you can set the idle time to some value with the apache directive
PassengerPoolIdleTime <integer>
More info at http://www.modrails.org/documentation/Users%20guide.html#PassengerPoolIdleTime
I set this to some value like 15 minutes then I usually have site monitoring setup like pingdom or site24x7 which hit the site every 15 minutes and will keeps the process alive. That way at least one instance is always running. But others shutdown when not used.
I see how you added custom filters, but what about custom tags? I tried creating a file in libs containing
module LiquidTags
class X < Liquid::Tags
end
end
but that didn't seem to be the right way to do it. What seems to work is freezing the gem and putting a new file in 'vendor/liquid-x.x.x/lib/liquid/tags'
I don't like doing it that way, but is that the best way to do it?
Is there a way to count the number of times you have clicked on "Add a task" without using Javascript? I'm using a radio button in the partial and need a way to distinguish if one of the added partials contains the radio button that was the selected.
We have passenger running on both a ubuntu production server and debian production server and so far there have no issues. Thank you for the great tip about the prefpane, didn´t know about that one.
A way (hack) to logout of HTTP-Basic-auth is to let the user follow a link to a special 'logout' resource which will always return "401 Unauthorized", after which the browser will reset the user's credentials and therefore stop sending them as such.
This was a great episode. I've long done this but still strive to make it elegant. The major hangup I have with this is getting an index page to display but not be required. I usually end up defining a map.root with a :action => show and :permalink => index for the page I created. My problem with this is if the page isn't in the database, how do I get the route to fall back to the :action => index?
For those using VMWare to test sites in Windows, don't use 127.0.0.1 for the hostname resolution. Run "ifconfig vmnet8" and grab that address. That should be the same address that the VM gets for its gateway when you run it as shared (NAT) networking. For Parallels, it creates a NAT host-guest network in your Network preference pane, and you can use that address in that case. Don't forget to copy what you added to your Mac hosts file to your Windows hosts file, in /Windows/system32/drivers/etc/hosts.
@Carl: Thanks for the suggestions, I shall have a play. I made the assumption that Passenger worked in that way, but didn't know for sure. My setup is really only a test bed. For production servers that have a significant load I can't see this being a problem. We use nagios to monitor the site which would keep the Passenger processes going.
@Rob: check my response above for a way to combat that lag. Passenger will deallocate memory when processes are not used for a while and return that to the system (imagine with you had something that spawn Mongrels as needed for your app and then shut them down if they weren't used for a while, that's a simplification but basically accurate as I understand it). So if the site isn't used for a while you will have a short lag (5 to 10 seconds sounds about normal) the first time it is used after the last process is stopped (again, not perfectly accurate but close enough). If you create the cron job to have the box hit the site once a minute then there should always be one instance running (at least) and you should have that lag. The only exception, if you are running in production at least, if if you create a file in the rails_root/tmp directory called restart.txt (easiest way: use the command "touch tmp/restart.txt" if you are in the root of your rails app). In that case it will reload all the rails files the next time a request is made (and that text file will disappear).
I've been using Passenger for a number of months now, while it seems to work great. It always takes 5 - 10 seconds to return a response (on the first response) and then its lightning fast. I am running it only on a Xen guest so perhaps I need more memory. Its certainly encouraging to drop multiple mongrels in place of a small amount of apache tinkering :)
In case anyone else has any questions about setting some of this sort of stuff up (passenger, Apache, etc) I've found the articles on slicehost to be quite helpful, and they are freely available to everyone here:
http://articles.slicehost.com/
They seem to update them pretty frequently and while they do have them broken down by OS (for the OS's most commonly installed on their hosting plans) many of them are just good articles and apply, with a little understanding, to most OS's.
I have an Apache Preference Pane for a second install of Apache, which was causing confusion.
I turned that off and made sure I edited the right config file. I also had to start File Sharing and then used terminal to start Apache, rather than the Apache Preference Pane.
@Dinooz: Passenger will use less memory than Thin if you use it in combination with Ruby Enterprise Edition. www.rubyenterpriseedition.com/comparisons.html has details, most notably the graphs at the bottom.
@Gavin Laking: Make sure you've set it to development environment, not production environment (the default).
I've been using passenger on my slicehost account for a couple of months now and it makes deployment much easier, especially when you have a couple of different sites that you want to have available for clients to check out when they have time, and don't want to set up a mongrel permanently. Because a site that isn't used for a while can take a little bit to start up again when someone hits the site (it's not long, but I deal with very non-technical people who sometimes freak out when something even seems slow) I will sometimes add a cron job to hit the site every minute and then just disable it when that's not as important anymore. Example cron job:
Even with the smallest slice they have I'm able to run a few sites and still have about 100 MB free most of the time, which would be hard with running mongrels for each one all the time.
A potential fix: When you add the configuration code to your Apache configuration file, make sure you manually restart the server before installing the prefpane; as the prefpane might be asking Apache about it's configuration not checking the httpd.conf file itself.
Thank you for yet another great railscast. I have been wanting to check out Passenger for quite some time now and found this a perfect opportunity. I followed the instructions for OS X with the prefpane and everything went smoothly. However, when I navigate to site.local, I get a Forbidden/Access Denied error for everything on that site. I added an Allow from all to my httpd.conf for that directory but I still get the same error. Any ideas?
I'm just wondering why I'm having to restart passenger every time I make even the most minute of changes to a controller, model or view. It's like some sort of caching is going on, but I don't remember ever setting it up. Any ideas?
Then you can add the same apache directives as ryan did on his show:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName mysite.local
DocumentRoot "path/to/doc/root"
<directory "path/to/directory">
Order allow,deny
Allow from all
</directory>
</VirtualHost>
This is language agnostic, but if your working with rails, you can add the rails directives in the virtual host statement as well.
I did try Passenger, however, I noticed it wasn't as fast as my current "Thin". Sounds like a really nice & easy way to quickly configure for hosting companies, but my question is regarding memory optimization when you have multiple virtual domains.
Maybe does not take as much memory at the begining since you run your a single Apache daemon and fork all the child processes, but I'm not sure how to compare with have Apache as a load balancer and multiple Thin servers oposite to let passenger to handle everything...
In your screencast you asked whether Windows is supported. Phusion Passenger intents to support all POSIX-compliant operating systems. That is, pretty much all operating systems in the world, except Microsoft Windows.
fyi - if you have file fault on ... your home folder in /Users/yourname has tight permissions (700) which will prevent apache from reading your rails projects folder if it is there; fix/change it by doing "chmod 755 /Users/yourname" - worked for me, after hours of fighting with a somewhat generic "Forbidden"; also consider setting the Apache "Listen" directive to "Listen 127.0.0.1:80" to avoid somebody else in your subnet accessing your server/site
Very useful tip, thanks!
@Joshua - Just what I needed, thanks!
For those you want validation:
Put a errors div above the form_remote_for function in your view.
<div id="errors"></div>
Then in your reviews controller, handle errors for the object.
respond_to do |format|
if(@review.save)
format.html { redirect_to(@review.product) }
format.js
else
format.js { render :update do |page|
page.replace_html :question_errors, error_messages_for(:review)
page.visual_effect :highlight, :errors, :duration => 2
end
}
end
end
You will want to update your create.rjs file to clear the errors message on a valid save.
page.replace_html :question_errors, ""
I hope I haven't missed anything.
@Ryan and @Marc
When it comes to clustering I believe it behaves pretty much the same way as if you were using Apache to run a PHP site, should you be any more familiar with that.
Just put a load balancer in front of 2 or more servers, each having it's own Apache + Passsenger.
Best regards.
@James, thanks for that! It would explain why I didn't get the 403 error.
@Marc, Passenger spawns new instances of your Rails app on demand, as your site needs it. This way it is very efficient because it uses only the resources it needs. Also, according to the benchmarks, it is better on memory and performance than other servers when combined with Ruby Enterprise Edition. I highly recommend it.
As for load balancing across a cluster of machines, I don't know if Passenger does this. Anyone want to chime in?
OH MAN!!
it was a message from the almighty himself, I just browsed to railscasts to search for such a topic... And what do ya know, top and center!!
So perfect!
thanks for the pref pane tip!
cheers
Maybe there should be a note stating that most of the information in this screencast is out of date. I watched the entire thing only to find out that Rails is now on Lighthouse. :(
Sorry for the double entry but it turns out Jame's solution also worked for the test-page-problem. I have my rails projects in ~/Sites, so chmoding ~/Sites to 711 worked for me.
I have the same issue as Boza. Passenger seems to set up the routing correctly, but accessing the resulting URL in Safari loads a "Test Page for Apache Installation".
I haven't found a entry in /etc/apache2/httpd.conf that looks like it might cause this. Any ideas?
The "Forbidden" errors are permission issues. Apache needs the Rails application directory and public directory to have at least 755 permissions. It also needs all directories in the path before the Rails application to have at least 711.
My problem was my Documents folder. My application was inside of this and it was not executable by anyone. I fixed it with the command:
chmod 711 ~/Documents
I also assume the log and tmp (plus all tmp subdirectories) need to be writeable, but I haven't verified that. I switched those to 777.
Hope that helps.
the default date_select will break this quite spectacularly. I dont have a workaround yet but want to give a heads up.
For those worried about the start up lag in production, you can set the idle time to some value with the apache directive
PassengerPoolIdleTime <integer>
More info at http://www.modrails.org/documentation/Users%20guide.html#PassengerPoolIdleTime
I set this to some value like 15 minutes then I usually have site monitoring setup like pingdom or site24x7 which hit the site every 15 minutes and will keeps the process alive. That way at least one instance is always running. But others shutdown when not used.
I'm getting this message when I try to access the application
"Seeing this instead of the website you expected?"
Everything else was fine.
I see how you added custom filters, but what about custom tags? I tried creating a file in libs containing
module LiquidTags
class X < Liquid::Tags
end
end
but that didn't seem to be the right way to do it. What seems to work is freezing the gem and putting a new file in 'vendor/liquid-x.x.x/lib/liquid/tags'
I don't like doing it that way, but is that the best way to do it?
Is there a way to count the number of times you have clicked on "Add a task" without using Javascript? I'm using a radio button in the partial and need a way to distinguish if one of the added partials contains the radio button that was the selected.
We have passenger running on both a ubuntu production server and debian production server and so far there have no issues. Thank you for the great tip about the prefpane, didn´t know about that one.
For those using non-Apple suppied Ruby, you might not have RubyCocoa installed, and will experience errors with the prefPane.
Eloy was kind enough to help me out, so check out his advice, before you bug him, like I did.
http://fingertips.lighthouseapp.com/projects/13022/tickets/4-nothing-happens-when-clicking
@nelson et al.
A way (hack) to logout of HTTP-Basic-auth is to let the user follow a link to a special 'logout' resource which will always return "401 Unauthorized", after which the browser will reset the user's credentials and therefore stop sending them as such.
Wonderful, I was really tired of starting my development apps every time I wanted to develop, this is so useful.
Thank you Ryan!
If you have apache2 with MacPorts installed. Than you have to do 2 extra things :
export APXS2=/opt/local/apache2/bin/apxs
export PATH=/opt/local/apache2/bin:$PATH
sudo passenger-install-apache2-module
Thanks to the link to that prefpane!
Ryan,
This was a great episode. I've long done this but still strive to make it elegant. The major hangup I have with this is getting an index page to display but not be required. I usually end up defining a map.root with a :action => show and :permalink => index for the page I created. My problem with this is if the page isn't in the database, how do I get the route to fall back to the :action => index?
Thanks for all your ideas and time.
For those using VMWare to test sites in Windows, don't use 127.0.0.1 for the hostname resolution. Run "ifconfig vmnet8" and grab that address. That should be the same address that the VM gets for its gateway when you run it as shared (NAT) networking. For Parallels, it creates a NAT host-guest network in your Network preference pane, and you can use that address in that case. Don't forget to copy what you added to your Mac hosts file to your Windows hosts file, in /Windows/system32/drivers/etc/hosts.
Hey Ryan,
I was wondering how I can combine nested routing with this. I want static pages, but in sections...so URLs like this:
/issues/issue1
/issues/issue2
I tried looking up nested routing and it all points me in the direction of URLs like this
/category/1/page/34
Any help would be appreciated!
For all those getting 403 forbidden, make sure these lines are specified in your apache config somewhere.
<directory "/path/to/app/public">
Order allow,deny
Allow from all
</directory>
You may need to move that path up a bit so it covers the full rails app instead of just public.
Also check the permissions on the files themselves to make sure apache can read them.
Don't forget to restart apache after changing the config.
@Luigi, are you running 10.5.2 or later? I think that's required to use the preference pane.
Very cool. Great screencast, I'll give this a try. Thanks Ryan.
@Carl: Thanks for the suggestions, I shall have a play. I made the assumption that Passenger worked in that way, but didn't know for sure. My setup is really only a test bed. For production servers that have a significant load I can't see this being a problem. We use nagios to monitor the site which would keep the Passenger processes going.
Also getting Forbidden
@Rob: check my response above for a way to combat that lag. Passenger will deallocate memory when processes are not used for a while and return that to the system (imagine with you had something that spawn Mongrels as needed for your app and then shut them down if they weren't used for a while, that's a simplification but basically accurate as I understand it). So if the site isn't used for a while you will have a short lag (5 to 10 seconds sounds about normal) the first time it is used after the last process is stopped (again, not perfectly accurate but close enough). If you create the cron job to have the box hit the site once a minute then there should always be one instance running (at least) and you should have that lag. The only exception, if you are running in production at least, if if you create a file in the rails_root/tmp directory called restart.txt (easiest way: use the command "touch tmp/restart.txt" if you are in the root of your rails app). In that case it will reload all the rails files the next time a request is made (and that text file will disappear).
Anyone else getting "Preferences Error - Could not load Passenger preference pane." when trying to open the Passenger PrefPane?
Screenshot:
http://bit.ly/1m0dct
Manually setting things up works fine, so I don't think it's specific to the Passenger I'm using (2.0.3).
Ryan, check this out.
http://www.ronfgreen.net/articles/2008/06/03/passenger-and-virtualhostx
Hi
I also get the 403 error when trying to open the site in the browser.. Any clues how to handle this?
I've been using Passenger for a number of months now, while it seems to work great. It always takes 5 - 10 seconds to return a response (on the first response) and then its lightning fast. I am running it only on a Xen guest so perhaps I need more memory. Its certainly encouraging to drop multiple mongrels in place of a small amount of apache tinkering :)
sorry meant "web sharing" not file sharing.
@Gavin: Glad I could help.
In case anyone else has any questions about setting some of this sort of stuff up (passenger, Apache, etc) I've found the articles on slicehost to be quite helpful, and they are freely available to everyone here:
http://articles.slicehost.com/
They seem to update them pretty frequently and while they do have them broken down by OS (for the OS's most commonly installed on their hosting plans) many of them are just good articles and apply, with a little understanding, to most OS's.
@ Jess Olsen
I have an Apache Preference Pane for a second install of Apache, which was causing confusion.
I turned that off and made sure I edited the right config file. I also had to start File Sharing and then used terminal to start Apache, rather than the Apache Preference Pane.
@Dinooz: Passenger will use less memory than Thin if you use it in combination with Ruby Enterprise Edition. www.rubyenterpriseedition.com/comparisons.html has details, most notably the graphs at the bottom.
@Gavin Laking: Make sure you've set it to development environment, not production environment (the default).
@Carl: Great tip to improve the perceived start-up time!
I've been using passenger on my slicehost account for a couple of months now and it makes deployment much easier, especially when you have a couple of different sites that you want to have available for clients to check out when they have time, and don't want to set up a mongrel permanently. Because a site that isn't used for a while can take a little bit to start up again when someone hits the site (it's not long, but I deal with very non-technical people who sometimes freak out when something even seems slow) I will sometimes add a cron job to hit the site every minute and then just disable it when that's not as important anymore. Example cron job:
* * * * * wget -q --spider http://site.name.com/ >/dev/null 2>&1 > /dev/null
Even with the smallest slice they have I'm able to run a few sites and still have about 100 MB free most of the time, which would be hard with running mongrels for each one all the time.
@Jess:
A potential fix: When you add the configuration code to your Apache configuration file, make sure you manually restart the server before installing the prefpane; as the prefpane might be asking Apache about it's configuration not checking the httpd.conf file itself.
I might be wrong!
@Riki
How did you fix the error? I'm having the same problem but don't know what's wrong.
The prefpane just says:
Can’t find the Phusion Passenger Apache module. Visit http://www.modrails.com for installation instructions.
Thank you for yet another great railscast. I have been wanting to check out Passenger for quite some time now and found this a perfect opportunity. I followed the instructions for OS X with the prefpane and everything went smoothly. However, when I navigate to site.local, I get a Forbidden/Access Denied error for everything on that site. I added an Allow from all to my httpd.conf for that directory but I still get the same error. Any ideas?
just a heads up to anyone that is wondering if debugging (ruby-debug) is possible when using mod_rails in development:
http://duckpunching.com/?p=17
have yet to try it myself as i just installed passenger locally yesterday, but i see no reason that it shouldnt work.
Thanks Ryan, great 'cast as usual!
I'm just wondering why I'm having to restart passenger every time I make even the most minute of changes to a controller, model or view. It's like some sort of caching is going on, but I don't remember ever setting it up. Any ideas?
Hey guys,
Doing something similar on Windows PCS is just quite as simple. After you have installed apache you can do the following:
Open to: %SystemRoot%\system32\drivers\etc\ (using Run)
Edit your hosts file and add the domain you wish ie:
127.0.0.1 localhost
127.0.0.1 mysite1.local
127.0.0.1 mysite2.local
Then you can add the same apache directives as ryan did on his show:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName mysite.local
DocumentRoot "path/to/doc/root"
<directory "path/to/directory">
Order allow,deny
Allow from all
</directory>
</VirtualHost>
This is language agnostic, but if your working with rails, you can add the rails directives in the virtual host statement as well.
Samatar Osman
I did try Passenger, however, I noticed it wasn't as fast as my current "Thin". Sounds like a really nice & easy way to quickly configure for hosting companies, but my question is regarding memory optimization when you have multiple virtual domains.
Maybe does not take as much memory at the begining since you run your a single Apache daemon and fork all the child processes, but I'm not sure how to compare with have Apache as a load balancer and multiple Thin servers oposite to let passenger to handle everything...
B. Keep doing the great job.
Sorry for posting an unrelated question.
It turns out that you need the OS X developer tools installed in order to have the ruby header files.
Btw, great episode as always.
/Jess
I'm having problems installing the gem:
Error installing passenger:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb install passenger
can't find header files for ruby.
This also happened to me when I tried to install RedCloth, but why I ask, why?
In your screencast you asked whether Windows is supported. Phusion Passenger intents to support all POSIX-compliant operating systems. That is, pretty much all operating systems in the world, except Microsoft Windows.