Rails 3 + passenger conf file - ruby-on-rails

I have been trying to install a rails app on a box that originally was used for multiple php applications. I installed passenger and created a conf file but I am confused about how it all works together.
What should my ServerName be if i want to access a Rails app? The box is a debian squeeze running apache2 with passenger module installed. Below is my conf file. I currently have to go to xxx.xxx.xxx.xxx/leoadmin/public to get the application to run properly. I have the following htaccess in the public directory. Which I think is unnecessary if my conf file is configured correctly.
I think my main issue is the misconfiguration of the conf file. I believe the conf file is being loaded but i don't understand why i still need the htaccess for me to see any action.
.htaccess
#PassengerEnabled On
PassengerAppRoot /var/www/leoadmin/
#Options -MultiViews
#PassengerResolveSymlinksInDocumentRoot on
#Set this to whatever environment you'll be running in
RailsEnv production
#RackBaseURI /var/www/leoadmin
vhost config
<VirtualHost *>
ServerName leoadmin
DocumentRoot /var/www/leoadmin/public
<Directory /var/www/leoadmin/public>
Allow from all
</Directory>
Alias /leoadmin /var/www/leoadmin/public
<Location /leoadmin>
SetEnv RAILS_RELATIVE_URL_ROOT "/leoadmin"
PassengerAppRoot /var/www/leoadmin
</Location>
ErrorLog /var/log/apache2/leoadmin-error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/leoadmin-access.log combined
</VirtualHost>

I had nothing but pain and more pain trying to get this sorted a few months back, my configuration allows me to do sub URIs, so I'm not sure if that's what you want, but it'll be along these lines. I've never needed a .htaccess file for this setup:
NameVirtualHost *:80 <VirtualHost *:80>
ServerName www.test.co.uk
DocumentRoot /web/rails
<Directory /web/rails>
Allow from all
</Directory>
RailsBaseURI /test
RailsEnv development
<Directory /web/rails_projects/test/>
Options -MultiViews
</Directory>
For me /web/rails is a root directory, from there I have a number of symlinks to my /home/ directory where I store my projects. ServerName is whatever qualified name you're using for the machine that's going to be recognised.
(just in case, I'm running Passenger 3.0.9, and Rails 3.2.11)

Related

Rails 3 Deploy: Multiple rails apps single domain error: No such file or directory - config/environment.rb

Yesterday, I bought a server on Linode. I setup Apache, RVM, Rails, MySQL and have got a single rails app hosted on a domain, following a nice guide from http://library.linode.com/frameworks/ruby-on-rails-apache/ubuntu-10.04-lucid. It also explains how to put multiple rails apps on the same domain, however when I try, I get an error when I access my domain our-portal.com/adm :
No such file or directory - config/environment.rb
Application root: /srv/www/our-portal.com/public_html
Somethings wrong here... anyone have any ideas? I am able to host a single app just fine, but not multiple... Here is my Virtual Host settings
<VirtualHost *:80>
ServerAdmin webmaster#our-portal.com
ServerName our-portal.com
ServerAlias www.our-portal.com
DocumentRoot /srv/www/our-portal.com/public_html/
RailsBaseURI /adm
RailsBaseURI /matrix
ErrorLog /srv/www/our-portal.com/logs/error.log
CustomLog /srv/www/our-portal.com/logs/access.log combined
</VirtualHost>
My applications path is in /srv/www/our-portal.com/adm/ and I linked using
ln -s /srv/www/our-portal.com/adm/public/ /srv/www/our-portal.com/public_html/adm/
ln -s /srv/www/our-portal.com/matrix/public/ /srv/www/our-portal.com/public_html/matrix/
Try by setting the DocumentRoot to the public folder of your application:
DocumentRoot /srv/www/our-portal.org/app/public
I got it working, these are the changes I made.
<VirtualHost *:80>
ServerAdmin webmaster#our-portal.com
ServerName our-portal.com
ServerAlias www.our-portal.com
DocumentRoot /srv/www/our-portal.com/public_html
<Directory /srv/www/our-portal.com/public_html>
Allow from all
</Directory>
RailsBaseURI /adm
RailsBaseURI /matrix
<Directory /srv/www/our-portal.com/public_html/adm>
Options -MultiViews
</Directory>
<Directory /srv/www/our-portal.com/public_html/matrix>
Options -MultiViews
</Directory>
ErrorLog /srv/www/our-portal.com/logs/error.log
CustomLog /srv/www/our-portal.com/logs/access.log combined
</VirtualHost>
I also believe my links were not created correctly. It helped to type
ln -s
and double-click tab (without executing the command) to look at the correct way Unix handles the path for this function. My links looked like this
ln -s /srv/www/our-portal.com/adm/public/ our-portal.com/public_html/adm
ln -s /srv/www/our-portal.com/sitedb-pro/public/ our-portal.com/public_html/matrix
Notice the difference from my old links. Using double-click tab I was able to reference these folders correctly.

Passenger on Ubuntu still only serving default index.html

Trying to get my server to serve my rails apps.
I have a test app installed, apache2 and passenger have been installed have I have added the following to the apache2.conf
# Include the virtual host configurations:
Include sites-enabled/
NameVirtualHost localhost:80
<VirtualHost localhost:80>
ServerName 192.168.1.67
DocumentRoot /home/john/Public/test-app
</VirtualHost>
Clearly, I am misunstanding something, because I think that should redirect calls to my local IP to my rails app. It is not. It is going to the default apache index.html.
What am I doing wrong?
UPDATED answer:
I think you are missing the "Directory" node. try using this config code:
(assuming your project path is: /home/john/Public/test-app)
<VirtualHost *:80>
DocumentRoot /home/john/Public/test-app/public
RailsEnv development
<Directory /home/john/Public/test-app/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
This is how I usually do it:
<VirtualHost *:80>
ServerName mysubdomain.betamaster.us
DocumentRoot /var/www_home/mysubdomain/
</VirtualHost>
After applying these changes make sure to execute
/etc/init.d/apache2 reload
in order to reload the server configuration.
I had the same symptoms in this question but it was a different problem. My apache install already had a Virtual host enabled, so I had to disable it and enable my own with the commands
sudo a2dissite default
sudo a2ensite myapp
where default was the name of the Virtual Host file included by default in sites-avaliable/ and myapp is the file i added.
Hopefully this helps someone.

Seeing the document root instead of my rails app running, Ubuntu VPS with Phusion Passenger

I am running ubuntu on my VPS and have installed apache as well as phusion passenger to deploy my rails apps with. I went through the setup for phusion passenger and everything installed just fine. I edited the apache configuration files and have appended the information below. I have also made sure that the Virtualhost is not being overridden the default host and when I changed that and refreshed a browser I was brought to the public directory of my rails app instead of having the rails app being executed. Any help would be appreciated.
additions to /etc/apache/apache2.conf
LoadModule passenger_module /var/lib/gems/1.8/gems/passenger-3.0.8/ext/apache2/mod_passenger.so
PassengerRoot /var/lib/gems/1.8/gems/passenger-3.0.8
PassengerRuby /usr/bin/ruby1.8
PassengerDefaultUser www-data
<VirtualHost *:80>
ServerName localhost
DocumentRoot /home/bodylabel/globify/public
<Directory /home/bodylabel/globify/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
/etc/apache2/sites-enabled/000-default
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
/etc/host.conf
# The "order" line is only used by old versions of the C library.
order hosts,bind
multi on
Just ran sudo passenger-status and got back the following:
*** Cleaning stale folder /tmp/passenger.44591
*** Cleaning stale folder /tmp/passenger.44300
*** Cleaning stale folder /tmp/passenger.44372
*** Cleaning stale folder /tmp/passenger.44200
*** Cleaning stale folder /tmp/passenger.21157
*** Cleaning stale folder /tmp/passenger.43944
*** Cleaning stale folder /tmp/passenger.21589
*** Cleaning stale folder /tmp/passenger.44878
ERROR: Phusion Passenger doesn't seem to be running.
the obligatory dumb question, but, did you restart apache?
Also, although this probably isn't the source of your problem, you may want to use the debian-esque method of deploying sites here and drop that virtualhost config into /etc/apache2/sites-available and run a2ensite to activate it.
There's probably a similar construct in place for modules-available and modules-enabled, where you might put that passenger code, rather than in apache2.conf.
You have two VirtualHost with the ip/port name *:80. Apache will do one of two things here. If you have a matching NameVirtualHost directive in your config then it will look for ServerName (and ServerAlias) directives within those two virtual host sections, and if the incoming request matches those server names/aliases then it will serve that virtual host.
Otherwise, it will serve the first VirtualHost block that is defined first in your configuration files. So, which one is being served will depend on the order that sites-enabled/000-default is included relative to the location of the VirtualHost section in apache2.conf

Rails app deployed with Passenger just displays index of app's public directory

I am trying to deploy a Rails application on Ubuntu 9.04 using Passenger.
As far as I can see, I have everything configured correctly; however when I point my browser at my domain, all I see is the index of the app's public directory.
My hunch is that Passenger is not starting up - at the bottom of just-plain-folks.co.uk there's no reference to Passenger at all. There's nothing interesting in the log files.
This is my config:
/etc/apache2/mods-enabled/passenger.conf
<IfModule passenger_module>
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.9
PassengerRuby /usr/bin/ruby1.8
</IfModule>
/etc/apache2/mods-enabled/passenger.load
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.9/ext/apache2/mod_passenger.so
/etc/apache2/sites-enabled/just-plain-folks.co.uk
<VirtualHost *:80>
ServerAdmin admin#just-plain-folks.co.uk
ServerName just-plain-folks.co.uk
ServerAlias www.just-plain-folks.co.uk
DocumentRoot /srv/www/just-plain-folks.co.uk/public_html/
ErrorLog /srv/www/just-plain-folks.co.uk/logs/error.log
CustomLog /srv/www/just-plain-folks.co.uk/logs/access.log combined
</VirtualHost>
/srv/www/just-plain-folks.co.uk/public_html/ is a simlink to the public directory of my application
If there's anything else that might be useful in diagnosing this, let me know. Any help is much appreciated!
Try ditching the symlink and pointing directly as public. I believe passenger is a little magic in this area as to how it detects the rails app.
Even if the symlink source was called public, I suspect it would still be looking for a rails_root in /srv/www/just-plain-folks.co.uk/.
(Updated: I missed the fact that you're trying to serve from the docroot)
Try turning off MultiViews
<VirtualHost *:80>
...
<Directory /srv/www/just-plain-folks.co.uk/public_html>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
Well, I had the similar issue with Sinatra, Phusion Passenger and Apache. My public directory was nested somewhere in deep, and the same thing with the views directory.
So, following configurations made my app running.
In apache's conf file, instead of /home/me/projects/fantasy-app/somewhere/nested/public, I just had to use /home/me/projects/fantasy-app/public in the DocumentRoot and <Directory> directives.
In my app.rb which onfig.ru refers to, I had the following:
set :public_folder, 'build/development/public'
set :views, Proc.new { File.join(root, "build/development/views") }

Controller pages inaccessible in new RoR project...why?

I set up a new RoR project on MAC OS Leopard, created a repository, svn added the whole Rails project, committed, checked out at my site, set up a vhost (see below), and I cannot get to a new controller page I created (/mycontroller/index). I CAN get to the "Welcome Aboard" page. I have another Ruby install (Redmine project management software) running with Apache.
I get this:
Not Found
The requested URL /developer was not found on this server.
Apache/2.2.8 (Ubuntu) mod_fastcgi/2.4.6 PHP/5.2.4-2ubuntu5.3 with Suhosin-Patch mod_scgi/1.12 Server at colorubooks.chadjohnson.ath.cx Port 8080
Here is my vhost setting:
<VirtualHost *:80>
ServerName mysite.mydomain.ath.cx
ServerAdmin email#gmail.com
DocumentRoot /srv/www/mysite.mydomain.ath.cx/public
RailsEnv development
<Directory "/srv/www/mysite.mydomain.ath.cx/public">
Options Indexes ExecCGI FollowSymLinks -MultiViews
Order allow,deny
Allow from all
AllowOverride all
</Directory>
</VirtualHost>
First:
In DocumentRoot you missed a /
change:
DocumentRoot /srv/www/mysite.mydomain.ath.cxpublic
to:
DocumentRoot /srv/www/mysite.mydomain.ath.cx/public
then you should be able to see static files in the /public directory (like the welcome aboard page)
Now I have a question for you... I presume that you want to use apache to deploy... Have you already installed and setup passenger (mod_rack) apache module?
Link to easy passenger install guide: http://modrails.com/install.html
enjoy!

Resources