How to activate Rails with Passenger and Apache on CentOs - ruby-on-rails

I've been struggling with this for hours. It's the first time that I try to establish a server.
I have rails, passenger and apache installed.
In the httpd.conf here is what I wrote:
ServerRoot "/etc/httpd"
# Here I wrote the IP address, since I still did not manage the DNS
Listen ##.##.##.94:80
ServerAdmin root#localhost
ServerName ##.##.##.94:80 # Do I need this?
<Directory />
AllowOverride none
Require all denied
Options Indexes FollowSymLinks Includes ExecCGI
</Directory>
<Directory "/var/www">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.3-p551/gems/passenger-4.0.59/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /usr/local/rvm/gems/ruby-1.9.3-p551/gems/passenger-4.0.59
PassengerDefaultRuby /usr/local/rvm/gems/ruby-1.9.3-p551/wrappers/ruby
</IfModule>
<VirtualHost *:80>
ServerName ##.##.##.##
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /var/www/blah_blah/public_html/public
<Directory /var/www/blah_blah/public_html>
# 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>
</VirtualHost>
The last section was produced by passenger (I did not! copy it from the instructions :-) ).
When I go to the IP address I get an error that the page was not found.
I have rails running with "rails s". Before that I reloaded the server and restarted it for the config file to take effect.
Also, I granted apache user permission to the www folder.
What is the problem?
I even tried to put an index.html file in the public folder of rail and tried to go there, but failed.
BTW - when I do it from the console:
wget http://0.0.0.0:3000
I get a 200 response which means that it is OK.
Where is the fault?

I think you should change the port:
<VirtualHost *:3000>
Because when you run rails s it run on port 3000.

Related

Apache Passenger module does not route certain file extensions to Rails

I have installed mod_passenger (passenger-install-apache2-module) and have the following in my Apache configuration:
LoadModule passenger_module /var/www/html/vendor/bundle/ruby/2.2.0/gems/passenger-5.0.24/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /var/www/html/vendor/bundle/ruby/2.2.0/gems/passenger-5.0.24
PassengerDefaultRuby /usr/local/rvm/wrappers/ruby-2.2.2/ruby
</IfModule>
RackEnv production
<VirtualHost *:80>
ServerName domain.com
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /var/www/html/public
<Directory /var/www/html/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost>
My Rails website is working however some URLs that end in .php or .txt do not get processed by Passenger resulting in a generic 404 page instead of the nicely formatted 404 page on my Rails site.
How can I route all file extensions to Passenger/Rails?
Or how can I make URLs that end in .php actually be processed by PHP.

Rails app on apache, passenger lists the directory instead of showing login page?

I am deploying a ruby-on-rails application.
I have configured apache and passenger and the http server is listening on port 80.
When I try to access the home page using the browser, I simply get a list of files and directories instead of the home page.
Following are snippets from the apache config.
/etc/apache2/apache2.conf
<Directory />
#Options FollowSymLinks
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order deny,allow
Allow from all
</Directory>
/etc/apache2/httpd.conf
LoadModule passenger_module /home/user1/.rvm/gems/ruby-2.3.0/gems/passenger-5.0.27/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /home/user1/.rvm/gems/ruby-2.3.0/gems/passenger-5.0.27
PassengerDefaultRuby /home/user1/.rvm/gems/ruby-2.3.0/wrappers/ruby
</IfModule>
/etc/apache2/sites-available/ubuntuvm-4.conf
<VirtualHost *:80>
ServerAdmin admin#ubuntuvm-4.com
ServerName ubuntuvm-4
ServerAlias www.ubuntuvm-4.com
DocumentRoot /home/user1/www/myapp/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
What is going wrong?
Could it be that I am trying to access the page via the ip address
http://192.168.0.12?
If you want me to put any other config, please shout.
try to copy the content of the file /etc/apache2/sites-available/ubuntuvm-4.conf
to /etc/apache2/sites-enabled/ubuntuvm-4.conf
cp /etc/apache2/sites-available/ubuntuvm-4.conf /etc/apache2/sites-enabled/ubuntuvm-4.conf
You need to create your config like this
<VirtualHost *:80>
ServerName ubuntuvm-4
<Location /home/user1/www/myapp/public>
PassengerBaseURI /
PassengerAppRoot /home/user1/www/myapp
</Location>
DocumentRoot /home/user1/www/myapp/public
<Directory /home/user1/www/myapp/public>
AllowOverride all
RailsEnv production
# MultiViews must be turned off.
Options -MultiViews
# Uncomment this if you're on Apache >= 2.4:
Require all granted
</Directory>
</VirtualHost>
I had the same problem trying to deploy a 4.2.1 Rails app on Ubuntu 12.04 using Ruby 2.3.2 (RVM because .deb packaged version is damn too old !!) Apache 2.2 and Passenger 5.0.4 (.deb).
Well, after wasting days to try to figure out why passenger wouldn't start (I did this a thousand times, it always worked), I realized it was only because Passenger couldn't print its logs anywhere. So, if you already tried everything you read on forums, just try to add a path to a log file in your apache configuration :
PassengerLogFile /var/log/passenger.log
and it worked like magic. Hope this helps.

Adding second virtual host with different Ruby and Passanger version

I have main Rails app working on system Ruby and Passanger. Following virtual host works just fine:
<VirtualHost x.x.x.x:80>
ServerName domain.com
DocumentRoot /home/john/apps/main_app/public
PassengerRoot /var/lib/gems/1.9.1/gems/passenger-4.0.29
PassengerRuby /usr/bin/ruby
<Directory /home/deploy/apps/main_app/public>
PassengerEnabled On
AllowOverride All
Require all granted
Options -MultiViews
</Directory>
</VirtualHost>
Now I want to add second virtual host for my second app working on different Ruby/Passanger versions and different domain but on same machine:
<VirtualHost x.x.x.x:80>
ServerName domain2.com
DocumentRoot /home/deploy/apps/app/public
PassengerRoot /home/deploy/.rvm/gems/ruby-2.1.5#app/gems/passenger-4.0.59
PassengerRuby /home/deploy/.rvm/rubies/ruby-2.1.5/bin/ruby
<Directory /home/deploy/apps/app/public>
PassengerEnabled On
AllowOverride All
Require all granted
Options -MultiViews
</Directory>
</VirtualHost>
After enabling second VirtualHost the first one (main app) is not working anymore. In browser I have 403 error. Same situation for second app.
Error log from main application:
[Sun Feb 15 13:29:08.596451 2015] [autoindex:error] [pid 53380] [client x.x.x.x] AH01276: Cannot serve directory /home/john/apps/main_app/public:
No matching DirectoryIndex (index.html,index.cgi,index.pl,index.php,index.xhtml,index.htm)
found, and server-generated directory index forbidden by Options directive, referer: x
After disabling second app first one is working. How can I make to work both apps in the same time?
The configurations are incorrect. The two virtual hosts are using two different Passenger versions, and loading two different Ruby versions.
<VirtualHost x.x.x.x:80>
PassengerRoot /var/lib/gems/1.9.1/gems/passenger-4.0.29
PassengerRuby /usr/bin/ruby
</VirtualHost>
vs
<VirtualHost x.x.x.x:80>
PassengerRoot /home/deploy/.rvm/gems/ruby-2.1.5#app/gems/passenger-4.0.59
PassengerRuby /home/deploy/.rvm/rubies/ruby-2.1.5/bin/ruby
</VirtualHost>

Apache Access Forbidden, Virtual host,

I'm tryig to run ruby on rails and redmine on xampp. My operating system is windows 7.
I followed this tutorial: http://nlb-creations.com/2013/06/26/installing-ruby-on-rails-and-redmine-with-xampp-on-windows-7/
When I try to access localhost:3000 I get this:
Access forbidden!
You don't have permission to access the requested directory. There is either no index document or the directory is read-protected.
This is my setup in httpd.conf:
Listen 3000
LoadModule rewrite_module modules/mod_rewrite.so
#################################
# RUBY SETUP
#################################
<VirtualHost *:3000>
ServerName rails
DocumentRoot "c:/xampp/htdocs/dev-ruby/redmine/public/"
<Directory "c:/xampp/htdocs/dev-ruby/redmine/">
Options ExecCGI FollowSymLinks
AllowOverride all
Allow from all
Order allow,deny
Require all granted
AddHandler cgi-script .cgi
AddHandler fastcgi-script .fcgi
</Directory>
</VirtualHost>
#################################
# RUBY SETUP
#################################
I tried many solutions but none of them worked. I also deleted .htaccess file but nothing changed. Any ideas please??
If your document root in C:\ disk, you should change the xampp folder (and subfolders) permissions for your user.

How to work Ruby on Rails + Passenger along with other services (like phpmyadmin/bugzilla) on CentOS 6

My requirement is to access http://myhost/ for my ROR project and access phpmyadmin and bugzilla using http://myhost/phpmyadmin/ and http://myhost/bugzilla/.
I wonder how to configure my VirtualHost and DocumentRoot, thanks for your comments!
Content of my /etc/httpd/conf/httpd.conf
LoadModule passenger_module /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.14/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.14
PassengerRuby /usr/bin/ruby
.....
.....
<VirtualHost *:80>
ServerName myhost
DocumentRoot /var/www/html/myProject/public
RailsEnv development
<Directory /var/www/html/myProject/public>
AllowOverride All
Options -MultiViews
</Directory>
</VirtualHost>
After digging the Passenger documents, I find there is a simple way to do so
<VirtualHost *:80>
ServerName myhost
DocumentRoot /var/www/html/myProject/public
RailsEnv development
<Directory /var/www/html/myProject/public>
AllowOverride All
Options -MultiViews
</Directory>
Alias /blog /var/www/html/phpmyadmin
<Location /phpmyadmin>
PassengerEnabled off
</Location>
</VirtualHost>
This will enforce Passenger to skip request under path /phpmyadmin
The easiest way, and with least amount of headaches would to just create subdomains for phpmyadmin and bugzilla. Then, just create a new virutalhost for each subdomain.
But, if your setup is necessary this seems like I possible solution.
http://macdiggs.com/2007/06/29/using-php-inside-rails-structure-on-apache/

Resources