Deploying a Rails Application to an LAMP server with Phusion Passenger - ruby-on-rails

I just finished working on my first rails app and am ready to deploy to my VPS. I decided to try using Phusion Passenger and went through the extremely simple install process. I got all the right dependencies, so on that end things seems to be ok. Where I think my problem lies is in the routing and the apache config file.
As told I added the following at the very end of the following file: /etc/apache2/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
<VirtualHost *:80>
ServerName localhost
DocumentRoot /home/bl/gfy/public
<Directory /home/bl/gfy/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
When I restart apache I get the following message:
* Restarting web server apache2 [Wed Aug 10 03:16:24 2011] [warn] module passenger_module is already loaded, skipping
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
... waiting [Wed Aug 10 03:16:26 2011] [warn] module passenger_module is already loaded, skipping
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
When I point my browser to my the IP I set up I get pointed to the sample file that comes with apache instead of to my rails app.
Any ideas would be greatly appreciated.
Thanks.

Somewhat unrelated to your problem, but still.
Both warning you see are not critical and should not affect server operations.
One means that your server hostname is not set, another just reminds you that passenger is already loaded from somewhere, probably after it stumbles upon in /etc/apache/modules.d.
All in all, you don't really want to edit /etc/apache/apache2.conf. Instead use existing structures, like /etc/apache2/sites-available etc.
Now back to your problem.
Your VirtualHost is most likely being overriden by default host.
Executing sudo a2dissite default in your shell will disable it. Assuming you don't have some exotic LAMP flavor.

Related

Ror app not running on CentOS

I am using CentOS 6.6 first time to deploy Rails 4 application. I have installed all necessary softwares like MySQL, Ruby, Rails, Passenger, Apache2, etc. I have tested it for index.html page inside /var/www/html/index.html and set it on Apache configuration and working perfect.
When I deployed Rails application it did run on the server but it displayed as shown in screenshot below.
Below are my Apache configuration settings which I have done so far.
/etc/httpd/conf/httpd.conf
LoadModule passenger_module /home/user/.rvm/gems/ruby-2.1.2/gems/passenger-5.0.6/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerDefaultRuby /home/user/.rvm/wrappers/ruby-2.1.2/ruby
PassengerRoot /home/user/.rvm/gems/ruby-2.1.2/gems/passenger-5.0.6
</IfModule>
I have created a file vhost.conf inside /etc/httpd/conf.d/
<VirtualHost *:80>
ServerName myipaddress
DocumentRoot /var/www/html/projectname/public_html/current/public
<Directory /var/www/html/projectname/public_html/current/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
# Uncomment this if you're on Apache >= 2.4:
#Require all granted
</Directory>
I run the command below command
service httpd restart
service httpd reload
Neither Rails app running in server nor showing any erros.
Any solution would be appreciated. Thanks in advance.
First and always check the Apache logs. This step is essential, but often overlooked. If that doesn't help, I would try a few things:
Double-check the documentation and make sure you've completely installed Passenger, and haven't skipped a step.
Start by removing the IfModule directive. Since you want Passenger, you want an error message if it isn't loading.
LoadModule passenger_module /home/user/.rvm/gems/ruby-2.1.2/gems/passenger-5.0.6/buildout/apache2/mod_passenger.so
PassengerDefaultRuby /home/user/.rvm/wrappers/ruby-2.1.2/ruby
PassengerRoot /home/user/.rvm/gems/ruby-2.1.2/gems/passenger-5.0.6
You have your IP address as your server name. Make sure this doesn't conflict with any other configurations (other sites, or httpd.conf). Otherwise, you may just be loading a different page / application.
Depending on how you have it set up, you may have permissions issues since you're pointing PassengerDefaultRuby and PassengerRoot to /home/user/.rvm. By convention, these are usually somewhere more public like /var/lib/gems/ and /usr/bin/.
Make sure you have defined a root path in your Rails application's config/routes.rb.
Make sure you've chown -R-ed your application path to the apache user. This will help you with troubleshooting and security.
After you've done all that, check the logs again. After you make a change, check the logs again.

Passenger on Apache: "doesn't seem to be running", app page gives 403; what next?

I'm having trouble getting my web server to talk to an app in Ruby on Rails. This is especially frustrating because I had it working last year for several months; I assume that some setting changed in the course of an upgrade in the meantime, but I can't find it.
The symptom: when I navigate to the page that should be serving the app (a sub-URI of the main domain), Apache gives a 403 error: "There is either no index document or the directory is read-protected.". The bottom of this error page gives the config string "Apache/2.4.9 (Unix) OpenSSL/1.0.1g Phusion_Passenger/4.0.37", which seems to indicate that Passenger is loaded and running. If I navigate directly to the public directory, or to the physical directory where the app lives, Apache happily displays the file listing of that directory (and if I click on any of the files, they display), so it doesn't seem to be that kind of permissions problem, at least.
In the httpd.conf file, there were the following lines to load Passenger:
LoadModule passenger_module modules/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.14
PassengerDefaultRuby /usr/local/rvm/wrappers/ruby-2.0.0-p247/ruby
PassengerEnabled Off
PassengerLogLevel 3
and, later, the following lines to tell Apache about the app:
<Location "/pathtoapp/f13">
Options +Indexes +ExecCGI +FollowSymLinks -MultiViews
Order allow,deny
Require all granted
PassengerEnabled On
RackBaseURI /pathtoapp/f13
#RailsEnv production
RailsEnv development
</Location>
The app itself lives in /pathtoapp/f13app, and there was a symlink in the filesystem from /pathtoapp/f13 to /pathtoapp/f13app/public. If I created a symlink /pathtoapp/test to /pathtoapp/f13app/public, it worked fine (in that it showed a file listing for the public directory, so again, no permissions problems).
I tried changing around a few things based on trawling the net for possible solutions. Most didn't appear to affect anything, so I reverted them; I did note that changing Location to Directory meant that navigating to /pathtoapp/f13 in my browser gave me the file listing of the public directory.
I tried (re-)running sudo passenger-install-apache2-module even though the Apache error seemed to indicate passenger was already installed. It (re-?)installed and prompted some changes to httpd.conf, which now has:
LoadModule passenger_module /usr/lib/ruby/gems/2.1.0/gems/passenger-4.0.37/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /usr/lib/ruby/gems/2.1.0/gems/passenger-4.0.37
PassengerDefaultRuby /usr/bin/ruby
</IfModule>
(I'm not sure if passenger did the ruby upgrade into /usr/lib or if that came in some earlier system update I'd done, but the indicated files are indeed there.) Later in httpd.conf, based on the current text of http://www.modrails.com/documentation/Users%20guide%20Apache.html#deploying_rack_to_sub_uri , I now have
Alias /pathtoapp/f13 /pathtoapp/f13app/public
<Location "/pathtoapp/f13">
PassengerBaseURI /pathtoapp/f13
PassengerAppRoot /pathtoapp/f13app
PassengerEnabled On
RailsEnv development
</Location>
<Directory "/pathtoapp/f13app/public">
Options +Indexes +ExecCGI +FollowSymLinks -MultiViews
Allow from all
Require all granted
</Directory>
I then removed the in-filesystem symlink from f13 to f13app/public. And, of course, I've restarted httpd.
passenger-status still reports "ERROR: Phusion Passenger doesn't seem to be running.", and navigating to the app's page (/pathtoapp/f13) still gives the same 403 error. I'm now completely stuck as to what to try next, or even what diagnostic tool I should be using to help triage the problem. Any ideas?
(Extra system info: uname -r is "3.14.1-1-ARCH"; apachectl -v is "Apache/2.4.9 (Unix)"; passenger -v is "Phusion Passenger version 4.0.37")
After a lot of mucking about, I finally discovered that the problem was with the Apache configuration itself: Apache was never getting far enough in to even talk to Passenger. Specifically, on the lines
Alias /pathtoapp/f13 /pathtoapp/f13app/public
and
PassengerAppRoot /pathtoapp/f13app
it's important that the pathtoapp be relative to the filesystem, not the URI. So those two lines should really be more like
Alias /pathtoapp/f13 /srv/http/htdoc/pathtoapp/f13app/public
and
PassengerAppRoot /srv/http/htdoc/pathtoapp/f13app
though of course the exact details will vary by system. I'm not sure if this was an issue with Apache 2.2-2.4 upgrade or something else (I have root access but am not the primary sysadmin on this system), but now that I've found the problem, I didn't want to leave the question hanging. I'll also add that the Apache config line
LogLevel debug
was invaluable in helping me track down which system component the problem was in.

Trying to get my ROR site up and running...getting a 404

running a R.o.R. site on passenger. Passenger is running fine, but I'm not sure if I am having an issue with the way I setup my vHosts or what, but It's returning a the apache start page, and not my application.
When I run
passenger-status
here is the message:
Version : 4.0.18
Date : 2013-09-26 10:42:03 -0400
Instance: 20958
----------- General information -----------
Max pool size : 6
Processes : 0
Requests in top-level queue : 0
----------- Application groups -----------
[USERNAME#gregorymurray relaunchradio]#
Here is the passenger stuff in my httpd.conf:
LoadModule passenger_module /usr/local/rvm/gems/ruby-2.0.0-p247/gems/passenger- 4.0.18/buildout/apache2/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.18
PassengerDefaultRuby /usr/local/rvm/wrappers/ruby-2.0.0-p247/ruby
PassengerDefaultUser root
No problem that I see there, here is my vhost.conf file in the main directory of my site:
ServerName gregorymurray.com
ServerAlias gregorymurray.com
DocumentRoot /var/www/vhosts/gregorymurray.com/relaunchradio/public
PassengerAppRoot /var/www/vhosts/gregorymurray.com/relaunchradio
<Directory "/var/www/vhosts/gregorymurray.com/relaunchradio/public">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
RailsEnv production
RailsBaseURI /
Here are the two links I followed in the process of getting this running:
http://www.twohard.com/blog/setting-rails-passenger-mediatemple-dv35-servers
https://coderwall.com/p/lu3nfa
Are you sure apache2 is finding the vhost.conf file? Are you using some kind of shared hosting that requires placing that file in your website's main directory? Because, that's not the normal setup. The virtual hosts file belongs under /etc/apache2 or /etc/httpd depending on whether using Ubuntu or centOS. Look at your apache conf file to find out where it's looking for the virtual hosts.
Open /etc/httpd/conf/httpd.conf and look for vhost.conf. Or look for a Include directive of the full path to your gregorymurray.com. I doubt either one will be found. Which means you need to move vhost.conf to /etc/httpd/conf/sites-enabled/vhost.conf and add Include sites-enabled/ in your httpd.conf just above the passenger module stuff.
Placing your vhost.conf in your website directory would require that you alter your httpd.conf to look in that website directory for a virtual host conf file. That's not the default setup or conventional setup.

Trying to run Rails App with Apache/Passenger, but getting 404s

I've installed passenger (don't know if the installation is correct) onto apache (i'm just using a development macintosh running snow leopard).
the httpd.conf file has a VirtualHost setting like this
<VirtualHost *:80>
ServerName myapp
DocumentRoot /webapps/boom/public
<Directory /webapps/boom/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
again, not sure if this is correct.
I can start up apache using apachectl start
and i can pull up the main page using this link (http://localhost).
However, when I try and go to one of my controller pages (I have a controller named blocks_controller.rb), I get a 404 error (http://localhost/blocks).
The apache error_log file shows => [Wed Jul 07 15:25:46 2010] [error] [client 127.0.0.1] File does not exist: /webapps/boom/public/blocks
I think this is something pretty simple that I'm doing wrong, but I don't know what.
Any thoughts??
Thanks!
Looks to me like Apache is not picking up the virtual host configuration so Passenger isn't in the loop. Are you sure that's all working? Apache looks a bit different in different environments so look in your OS specific locations at the Apache log files to be sure.

Problem deploying Rails with Passenger to Mac OS X Leopard Server

I'm spinning my wheels... Apache is working and serving static html, png, etc. normally. Trying to get Passenger to serve a rails app out of www.mydomain.com/rails/
as it stands when i try to hit my app: www.mydomain.com/rails/myapp/railsclassname
I get only an Apache 403 Errors. Nothing in myapp's Production Log.
Apache2 access.log:
"GET /rails/ HTTP/1.1" 403 1085
Apache2 error.log:
[Fri Jun 11 22:44:01 2010] [error] [client 10.0.1.41] File does not exist: /Library/WebServer/wwwroot/rails/railsclassname
i've even tried www.mydomain.com/myapp/classname
Passenger, obviously, isn't routing requests made into my sub-folder rails/ to my rails app. not sure where i've screwed up. the most obvious thing is "Passenger doesn't seem to be running"... instructions I've followed just say to sudo apachectl graceful, which i've done (as well as stopped/started). new to this so go easy on me!
Here's some info that might be helpful. happy to provide more as needed...
As per some instruction # Passenger site i've created a symlink from /Library/WebServer/myapp/rails -> /Library/WebServer/rails/myapp/public
myhost:myapp joe$ passenger-config --root
/Library/Ruby/Gems/1.8/gems/passenger-2.2.14
myhost:myapp joe$ passenger-status
ERROR: Phusion Passenger doesn't seem to be running.
apollo:myapp joe$ cat /etc/httpd/httpd.conf
...
<removed for brevity>
...
# Copied From Passenger Installer
LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-2.2.14/ext/apache2/mod_passenger.so
PassengerRoot /Library/Ruby/Gems/1.8/gems/passenger-2.2.14
PassengerRuby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
# End Passenger Installer
NameVirtualHost *
<VirtualHost *:80>
ServerName www.mydomain.com
DocumentRoot /Library/WebServer/rails/myapp/public # <-- be sure to point to 'public'!
RackBaseURI /rails
<Directory /Library/WebServer/rails/myapp/public>
AllowOverride all # <-- relax Apache security settings
Options -MultiViews # <-- MultiViews must be turned off
order allow,deny
Allow from all
</Directory>
</VirtualHost>
This last bit from NameVirtualHost on is pieced together from a number of online material i've found...as i've been desperately trying to find something/anything that'll show Passenger at least has a pulse!?!
So, you've got
www.mydomain.com
www.mydomain.com/rails
These both point to different websites (lets call them main and rails), the code for each site might be saved on the file system like so:
/Library/WebServer/main/
/Library/WebServer/rails/
We create a symlink from your rails app's public folder to a folder called rails in your main app:
ln -s /Library/WebServer/rails/public /Library/WebServer/main/rails
Then we create a VirtualHost for the main site (not the rails one, and I'm assuming the main site is not rails) and add the rails app as a sub URI, like so:
<VirtualHost *:80>
ServerName www.mydomain.com
DocumentRoot /Library/WebServer/main
<Directory /Library/WebServer/main>
Allow from all
</Directory>
RackBaseURI /rails
<Directory /Library/WebServer/main/rails>
Options -MultiViews
</Directory>
</VirtualHost>
(If you already have a VirtualHost set up for your main website, you can add the RackBaseURI and preceding Directory declaration to that instead).
Now restart apache and you should be able to go to:
www.mydomain.com/rails
and see the "Welcome to Rails" page, or:
www.mydomain.com/rails/controllername
Hope that helps.

Resources