What have I done wrong in setting up Passenger/mod_rails? - ruby-on-rails

I am attempting to get a Rails development environment up using a CentOS virtual machine. It will run Apache with Phusion Passenger, and I will access it from the host OS by entering the VM's LAN IP (eg 192.168.0.5).
I have been able to run Rails apps perfectly using WEBrick, and I have been able to serve static pages and PHP perfectly from Apache. But getting Passenger set up is proving to be a baffling nightmare of endless problems for me, and I would absolutely love some help from someone who knows what they're doing here.
So here's what I've done.
Booted into a fresh CentOS 6.3 machine. Using yum, installed httpd (Apache 2.2), sqlite-devel, all the other good stuff you need.
Installed RVM (to /home/vagrant/.rvm/), and Ruby 2.1.2, which I can confirm is working perfectly.
Installed Passenger with rvmsudo passenger-install-apache2-module.
Added the following to my httpd.conf.
.
LoadModule passenger_module /home/vagrant/.rvm/gems/ruby-2.1.2/gems/passenger-4.0.45/buildout/apache2/mod_passenger.so
<IfModule module_passenger.c>
PassengerRoot /home/vagrant/.rvm/gems/ruby-2.1.2/gems/passenger-4.0.45
PassengerDefaultRuby /home/vagrant/.rvm/gems/ruby-2.1.2/wrappers/ruby
</IfModule>
<VirtualHost *:80>
ServerName localhost
DocumentRoot /var/www/html/dangerzone/public
<Directory /var/www/html/dangerzone/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
Finally, in /var/www/html, I executed rails new dangerzone to create the app.
Initially, trying to access my app gave me a Passenger error 'no JS runtime', which thrilled me because I'd spent 5 or so hours trying to get Passenger recognised at all. I installed Node-JS through Yum, and my current error is a 500, Internal server error.
I see nothing in /etc/httpd/logs/error_log.
I've followed the instructions on the RVM and Passenger websites to a letter. I've Googled this problem until I'd read the entire top 30 results. I've wiped the VM and started from scratch in case I did something wrong -- same problem. So I'm kind of baffled. Have I screwed up something really obvious?

Related

Passenger 5 is listing public directory

I'm using Centos cPanel with Passenger, the app is working when I access in to the sections for example /home or /login but it displays the files when I access directly to the page /.
This is my .htaccess config
PassengerEnabled On
PassengerLoadShellEnvVars On
PassengerAppRoot /home/claude/rails/claude
PassengerRuby /usr/local/rvm/gems/ruby-2.0.0-p648/wrappers/ruby
RackEnv production
PassengerResolveSymlinksInDocumentRoot on
I already tried disabling autoindex
#LoadModule autoindex_module modules/mod_autoindex.so
but it doesn't let me restart apache.
Does anyone have resolved this issue before?
Thanks.
Done!
So the issue was that I installed first passenger-5.0.10 but for some reason Apache was trying to load passenger-5.0.30 but I was including the other version in httpd.conf so I reinstalled again passenger 5.0.30 and that was it.
Thanks.

Ruby/Rails Apache2 & Passenger setup returning directory listing

It's worth nothing, first of all, that I've got a fully-functional Apache2 server (on a Ubuntu 12.04 VPS) with multiple working virtual hosts (but this is my first attempt to deploy a Rails site). Additionally, the Rails site I'm trying to launch is fully functional on my local WEBRick server.
I've referenced various online instructions for making Apache, Ruby, Rails & Passenger play nice together, including:
This from Linode, my host (they don't offer documentation specific for 12.04)
This from O'Reilly
The Passenger documentation that's part of the installation process of passenger-install-apache2-module
The online Passenger documentation
Various old SO questions such as this and this
To summarize, so far I've:
Installed Ruby (ruby -v in site root returns 1.9.3), RVM, Ruby Gems, Rails (rails -v in app folder returns 3.2.8 and I can start a rails server in the app folder) & Passenger (including all dependencies)
As instructed by passenger-install-apache2-module, I've added the following lines to the bottom of /etc/apache2/apache2.conf:
LoadModule passenger_module /var/lib/gems/1.8/gems/passenger 3.0.17/ext/apache2/mod_passenger.so
PassengerRoot /var/lib/gems/1.8/gems/passenger-3.0.17
PassengerRuby /usr/bin/ruby1.8
Created & enabled (it's listed in /etc/apache2/sites-enabled/) a virtual host /etc/apache2/sites-available/foo.com that contains the following:
<VirtualHost *:80>
ServerName foo.com
DocumentRoot /home/user/public/foo.com/public
<Directory /home/user/public/foo.com/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
Uploaded my Rails app to /home/user/public/foo.com/
Did a bundle install in /home/user/public/foo.com/
On my local OSX machine, I've add xxx.xxx.xxx.xxx foo.com [the VPS IP] to /etc/hosts.
Restarted Apache
But when I navigate to foo.com in the browser, I simply see a listing of /home/user/public/foo.com/public. Also, there are no recent entries in the Apache error.log. However, whenever I restart Apache I get:
* Restarting web server apache2
[Fri Oct 26 00:04:12 2012] [warn] module passenger_module is already loaded, skipping
... waiting [Fri Oct 26 00:04:13 2012] [warn] module passenger_module is already loaded, skipping
...done.
I'm hoping I've overlooked something really stupid. Any help figure out what that is would be much, much appreciated. Thanks!
If you're working with apache2.2, you should not include the following in apache2.conf
LoadModule passenger_module /var/lib/gems/1.8/gems/passenger 3.0.17/ext/apache2/mod_passenger.so
PassengerRoot /var/lib/gems/1.8/gems/passenger-3.0.17
PassengerRuby /usr/bin/ruby1.8
Instead you should create 2 files on /etc/apache2/mods-available:
passenger.load with:
LoadModule passenger_module /var/lib/gems/1.8/gems/passenger3.0.17/ext/apache2/mod_passenger.so
passenger.conf with:
PassengerRoot /var/lib/gems/1.8/gems/passenger-3.0.17
PassengerRuby /usr/bin/ruby1.8
Finally you just run:
a2enmod passenger
And it's done. By the way, when you make it work you might consider using a more recent version of ruby (1.9.3... or so). The best way to do that is using RVM.
I was trying to use passenger to run a Rails 2.3. app I had created a couple of years ago and needed to move to a new server.
I added passenger, but all I got was a directory listing.
In the end it turned out that I did not have a config.ru file.
It was enough to create a file with those two lines:
require File.dirname(__FILE__) + '/config/environment'
run ActionController::Dispatcher.new
It took me about 5 hours to find out I was missing those two lines. I am wishing everybody in a similar situation that he/she will find this answer before spending too much time on this... :-)
Had the same problem, turned out, that in /etc/apache2/mods-enabled/passanger.load I had the apache2 installed passenger.so that didn't want to work, changed it to the gems installed passenger.so
LoadModule passenger_module /var/lib/gems/1.9.1/gems/passenger-4.0.20/buildout/apache2/mod_passenger.so

Rails Passenger problem with Apache2

I'm trying to setup a ruby on rails server on ubuntu10.10 with apache2 and mod_rails (Phusion Passenger).
I already installed ruby 1.9.2-p0 and rails 3.0.8 and installed Passenger with the passenger-install-apache2-module and the passenger gem (v3.0.7).
It then tells me to add 3 lines to my Apache config file. So I added these lines to '/etc/apache2/apache2.conf':
LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/gems/1.9.1/gems/passenger-3.0.7
PassengerRuby /usr/local/bin/ruby
And I edited my '/etc/apache2/httpd.conf' and added:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName 192.168.0.2
DocumentRoot /var/www/webop/public
<Directory /var/www/webop/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
I also found out that the file mod_passenger.so in /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.7/ext/apache2/ actually does not exist, its name is mod_passenger.c. But I don't get any errors from that.
The server should only be accessible through a LAN. When I access the server I see all the files and directories in the public folder of my app but the app itself does not get started.
When I restart apache it tells me that mod_rails is already loaded so I guess that passenger is running but I can't figure out why it doesn't start my app!
Thanks in advance!
The reason mod_passenger.so does not exist is because you haven't installed the Apache module. Execute:
passenger-install-apache2-module
This will create the mod_passenger.so file inside your gem directory, and give you three lines to copy into your apache2.conf file.
The passenger module is installed in your current gemset so you shouldn't get any conflicts between projects. You can use any compatible version of Ruby, and any gemset you like, via RVM, and possibly also RBENV. This makes for a nice easy upgrade path from one version of Ruby to the next.
I finally figured out what the problem was: I messed up my ruby installation.
In /usr/local/ I had ruby1.9.2-p0 installed (which was the version I wanted to use) but in /usr/ i had ruby1.8.7 installed.
Passenger was confused which ruby version to use so I changed the LoadModule, PassengerRoot and PassengerRuby paths within apache2/mods-enabled/passenger.load and .config to the correct paths and it finally worked! Both files were created automatically which also caused the problem of a redefinition: On apache startup there was a warning 'mod_passenger already loaded'. So I removed
LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/gems/1.9.1/gems/passenger-3.0.7
PassengerRuby /usr/local/bin/ruby
from the apache config and the warning disappeared!
Probably this will help someone else some day!
I have come across a cleaner solution today. This might help future users. The command -
passenger-install-apache2-module
tells me to put these three lines in apache configuration file.
LoadModule passenger_module /home/anwar/.rvm/gems/ruby-2.2.0/gems/passenger-4.0.59/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /home/anwar/.rvm/gems/ruby-2.2.0/gems/passenger-4.0.59
PassengerDefaultRuby /home/anwar/.rvm/gems/ruby-2.2.0/wrappers/ruby
</IfModule>
But, where is that configuration file? The answer is the configuration files are seperated into many pieces and they reside in /etc/apache2/mods-available.
So you should do three things -
Create a file ending with .load in /etc/apache2/mods-available folder. I used passenger.load.
Paste the three lines in that file and save the file.
Now in terminal use sudo a2enmod <module-conf-filename> to enable the module. In my case, the file was, passenger.load. So, I used
sudo a2enmod passenger
Now, restart the server and use the command apache2ctl -M to find that passenger module is enabled.
I think they want you to put those three lines in your httpd.conf file, not in your apache2.conf. At least that's how I've always done it.

Can't get passenger to serve pages (steps I used inside)

I have been struggling to get passenger to run my Rails/Rack apps.
Steps I used (as root):
Clean Debian 6 installation
aptitude install apache2, (Ruby
requirements taken from RVM),
git-core, curl, (and some more
packages too I guess)
getting rvm installed (system wide)
installing ruby 1.9.2-p180, and
setting it to be used as default
installing passenger gem, and
running the apache2 module
installation (getting apache2
prequisites along the way)
creating
/etc/apache2/mods-available/passenger.load
and placing:
LoadModule
passenger_module ... (the one
printed after apache2 passenger
module got installed)
creating
/etc/apache2/mods-available/passenger.conf
and placing:
PassengerRuby ...
PassengerRoot ... (the ones printed after apache2
passenger module got installed)
ap2enmod passenger (and getting apache restarted afterwards)
mkdir /var/www
setting /var/www to be user: root, group: www-data
creating /var/www/testapp and copying my rails app there
creating /etc/apache2/sites-available/testapp and placing in there:
<VirtualHost *:80>
ServerName localhost/testapp
DocumentRoot /var/www/testapp/public
<Directory /var/www/testapp/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
ap2ensite testapp
bundle install from within /var/www/testapp
/etc/init.d/apache2 restart
After opening in the browser: localhost/testapp I can only see my rails app structure (it didnt fire the page)
I don't know what I have done wrong. It seems to be pretty much okay. I am concerned about file permissions, groups and so on, although I have no clue how should I set these up. How should permissions be structured? Apart from that, anything else that looks suspicious?
Thanks!
ServerName can't have slashes in it. Just make ServerName localhost, and go to http://localhost to visit your site.
If you need multiple websites deployed on localhost, you can do that, but you need to follow the extra steps here:
http://www.modrails.com/documentation/Users%20guide%20Apache.html#deploying_rails_to_sub_uri

rails site showing index of / page

My Rails site used to work, but after starting over after doing an OS upgrade, it is now showing only the index of / with the contents of the rails app's public directory.
My PHP site is working fine, so this must be a configuration issue. I have looked at this problem for a long time, so I'm at a loss here. I really appreciate your help.
I followed the instructions on http://library.linode.com/frameworks/ruby-on-rails-apache/ubuntu-10.04-lucid as before.
I have the following setup in /etc/apache2/sites-availabe/mydomain.com:
<VirtualHost ip:80>
ServerName mydomain.com
DocumentRoot /srv/www/mydomain.com/app/public/
ServerAlias www.mydomain.com
ErrorLog /srv/www/mydomain.com/log/error.log
CustomLog /srv/www/mydomain.com/log/access.log combined
</VirtualHost>
My app is under /srv/www/mydomain.com/app/.
What is wrong here? This used to work before migration.
The app is on ubuntu 10.4.
I had many troubles starting out with vHosts.
This little quick guide may help.
$ gem install passenger
$ passenger-install-apache2-module
Follow the screen instructions.
Edit your current vHost configuration.
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot "/srv/www/mydomain.com/app/public/"
<Directory "/srv/www/mydomain.com/app/public/">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Restart your Apache server.
$ sudo apache graceful
Add the following to the end of your /etc/hosts file in your favorite editor.
127.0.0.1 mydomain.com www.mydomain.com
Test your domain.
$ ping mydomain.com
You should see something like
PING mydomain.com (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.035 ms
Now you should be able to go into your favorite browser and navigate to mydomain.com and see your application instance.
For future readers, I found the answer here:
https://help.ubuntu.com/community/RubyOnRails#Installing%20rails
I had passenger gem installed.
What was missing was:
sudo apt-get install apache2-dev libapr1-dev libaprutil1-dev
Enable the passenger simply by typing:
a2enmod passenger
Then restart apache. Voila!
By the sounds of it you need to install Phusion Passenger?
If you need any help check out Dan Benjamin's guide.
When you upgraded the OS, you also upgraded Apache. If you were using Passenger, you probably installed it by having it compiled it manually, so that got lost in the process of the upgrade. You may need to re-run through the installation of Passenger again.

Resources