installing passenger on Apache2 using rvm - ruby-on-rails

I've installed Apache2 and it runs okay.
And I've installed rvm following this link.
After that, I've execute follow commands as its order. Actually some of these commands are from this link installing redmine.
rvm install 1.8.7
rvm use 1.8.7
gem install rails -v=2.3.5
gem install postgres-pr pq
gem install i18n -v=0.4.2
gem install passenger
passenger-install-apache2-module
and append this to apache2.conf
LoadModule passenger_module /home/myhome/.rvm/gems/ruby-1.8.7-p330/gems/passenger-3.0.2/ext/apache2/mod_passenger.so
PassengerRoot /home/myhome/.rvm/gems/ruby-1.8.7-p330/gems/passenger-3.0.2
PassengerRuby /home/myhome/.rvm/wrappers/ruby-1.8.7-p330/ruby
This is log for Apache after restart
[notice] Apache/2.2.16 (Ubuntu) PHP/5.3.3-1ubuntu9.3 with Suhosin-Patch Phusion_Passenger/3.0.2 configured -- resuming normal operations
But!!!, if I open my redmine root page, it just shows file list in public directory. I think Passenger may not work correctly.
Why? and how to fix this? I've tried everything what I can do for 2 days T-T

Have you added this section to apache config? It tells apache that you are using Rails application:
<VirtualHost :*80>
ServerName myapp
DocumentRoot /root-to-your-path/public
</VirtualHost>
And restarted Apache? Read more here: http://www.modrails.com/documentation/Users%20guide%20Apache.html#_deploying_a_ruby_on_rails_application

You should view the Passenger Integration guide from RVM, or the more detailed guide from Phusion (the makers of Passenger).
Note that in Phusion's guide, you should omit the --pre when installing the gem, as the guide was written when Passenger 3 was still in beta.

Related

Passenger using wrong ruby version

I'm running multiple websites on Apache with Passenger 4.0.45 on a CentOS server. I have multiple ruby versions installed too with rvm 1.25.27 and for the past 3 years I'm using Ruby 2.1.2 version.
I have now started a new application with Rails 5.1 and I've needed to install Ruby 2.4.2. After deployed my application I'm getting an Internal Server Error and here it is the error I'm getting on error log:
App 10033 stderr: /usr/local/rvm/gems/ruby-2.1.2#rails-4.0/gems/passenger-4.0.45/lib/phusion_passenger/request_handler.rb:356:in `trap'
App 10033 stderr: :
App 10033 stderr: Invalid argument - SIGKILL
App 10033 stderr: (
App 10033 stderr: Errno::EINVAL
App 10033 stderr: )
I've noticed that the ruby version that shows up is ruby-2.1.2#rails-4.0 and I think it should be 2.4.2 because is the version that I'm specifying on VirtualHost file:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /.../current/public
PassengerRuby /home/user/.rvm/wrappers/ruby-2.4.2#global/ruby
<Directory
/home/user/.../current/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
I've read about this bug on https://github.com/phusion/passenger/issues/1362 but I don't know if I can update Passenger without messing up other sites that I'm running with old versions of Ruby.
I've found the answer to my question. I will explain what I did:
rvm install 2.4.2 (Install Ruby version 2.4.2)
rvm use 2.4.2 (Use Ruby 2.4.2 version)
gem install passenger (Install Passenger gem)
passenger-install-apache2-module (This will guide you throught the installation of the Passenger module for Apache. It takes around 3 minutes)
After the installation process of the Passenger module, I've updated my httpd.conf file with new LoadModule and PassengerRoot specified by the installation summary)
rvmsudo passenger-config validate-install (Check if Passenger installed correctly)
sudo service httpd restart (Restart Apache)
After did the above commands, my new application with Rails 5.1 is working as well as every other site in the server running on lower Ruby/Rails versions.

start rails server automatically after reboot

I'd like my rails server to start automatically after every reboot, so I added the following to my .bashrc file
rvm use 1.9.2
cd /home/user/myapp
rails server
With that, the server never starts automatically after a reboot, and I have to start it manually.
Also, when I login to start the server, I see the following message
Using /usr/local/rvm/gems/ruby-1.9.2-p290
/usr/local/rvm/rubies/ruby-1.9.2-p290/bin/ruby: symbol lookup error: /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sqlite3-1.3.4/lib/sqlite3/sqlite3_native.so: undefined symbol: sqlite3_initialize
As a consequence, I need to install sqlite3 after every reboot using "gem install sqlite3" after I make myself superuser, and only then I can start the rails server without issues.
$ cat /etc/*-release
CentOS release 5.8 (Final)
$ rails -v
Rails 3.1.1
$ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]
Anyone can please help me overcome this issue? Thanks
Install Apache and Passenger
They will take care of starting your App with the server in a safer and more systematic way and what is now more or less a standard.
I had the same issue with Rails 4, Ruby 2.1 on CentOS 6. If you're not familiar with bash scripts and the rc, profiles system - it's much faster and easier to setup passenger.
Also, there are other reasons why you would go for passenger, including security and performance ( www.phusionpassenger.com )
Here is a quick how-to of what it took me to introduce the gem.
Install Apache (html daemon) and dependency packages (if you don't have them already):
yum install httpd curl-devel httpd-devel
Get Apache to start on boot:
chkconfig httpd on
Install Phusion Passenger and dependency packages:
gem install passenger
yum install curl-devel httpd-devel
Compile the environment:
passenger-install-apache2-module
Edit the Apache config file in etc/httpd/conf/httpd.conf
Uncomment the line containing NameVirtualHost *:80 towards the end
Paste the output from point 4) anywhere at the end of the file, eg:
LoadModule passenger_module /usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.41/buildout/apache2/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.41
PassengerDefaultRuby /usr/local/rvm/gems/ruby-2.1.1/wrappers/ruby
<VirtualHost *:80>
ServerName 1.2.3.4 # www.whatever.com
DocumentRoot /var/www/rails/public # the path to your rails app
<Directory /var/www/rails/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
Took me 30 minutes in total, including several trial-errors with the httpd.conf to get everything right.
Note that installation requires at least 1 GB RAM on your machine.

Passenger ('Bundler:RubyVersionMismatch')

I'm having a problem with deploying my rails app on my server. I'm deploying using Passenger for serving up pages. The following error is listed on my page when I start the server. It seems like the version of passenger I have installed is referencing ruby 1.8.7 but my app has been built in 2.0.0. I've tried removing ruby 1.8.7 and reinstalling Passenger, but no luck so far. If I run ruby -v from my directory it lists the version as 2.0.0.
Your Ruby version is 1.8.7, but your Gemfile specified 2.0.0 (Bundler::RubyVersionMismatch)
/home/ubuntu/.rvm/gems/ruby-2.0.0-p0#global/gems/bundler-1.3.4/lib/bundler/definition.rb:361:in ` validate_ruby!'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p0#global/gems/bundler-1.3.4/lib/bundler.rb:116:in `setup'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p0#global/gems/bundler-1.3.4/lib/bundler/setup.rb:17
/usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:59:in `gem_original_require'
/usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:59:in `require'
/var/lib/gems/1.8/gems/passenger- 4.0.0.rc4/lib/phusion_passenger/loader_shared_helpers.rb:212:in `run_load_path_setup_code'
/var/lib/gems/1.8/gems/passenger-4.0.0.rc4/helper-scripts/rack-preloader.rb:73:in `preload_app'
/var/lib/gems/1.8/gems/passenger-4.0.0.rc4/helper-scripts/rack-preloader.rb:127
My apache2.conf file has the following additions:
Include sites-enabled/
<ifmodule mod_ssl.c>
NameVirtualHost *:443
</ifmodule>
LoadModule passenger_module /var/lib/gems/1.8/gems/passenger 4.0.0.rc4/libout/apache2/mod_passenger.so
PassengerRoot /var/lib/gems/1.8/gems/passenger-4.0.0.rc4
PassengerRuby /usr/bin/ruby1.8
Edit: ANSWER
I was using sudo to install passenger and apache2 module. Should have just typed:
gem install passenger -pre
passenger-install-apache2-module
WITHOUT sudo.
your passenger config is pointing to ruby 1.8
LoadModule passenger_module /var/lib/gems/1.8/gems/passenger 4.0.0.rc4/libout/apache2/mod_passenger.so
PassengerRoot /var/lib/gems/1.8/gems/passenger-4.0.0.rc4
PassengerRuby /usr/bin/ruby1.8
It should probably look something like this...
LoadModule passenger_module /var/lib/gems/2.0.0/gems/passenger 4.0.0.rc4/libout/apache2/mod_passenger.so
PassengerRoot /var/lib/gems/2.0.0/gems/passenger-4.0.0.rc4
PassengerRuby /usr/bin/ruby2.0.0
Passenger installation is very helpful and it prints these lines for you on the console after successful installation. You should just copy those lines and paste them into your apache conf
You should try install passenger again.
This is why I switched from using RVM to RBENV. You won't run into this problem with RBENV. Plus its just better.
If you upgrade ruby using RVM on your production server, you'll be forced to reinstall passenger/nginx (in your case it looks like just passenger).
Huge pain, and causes server downtime.
Use RBENV instead to save yourself this headache. With RBENV/Capistrano, upgrading can simply be done via your gemfile, and the rest just works.

Using passenger to run both Rails 3.0 and Rails 3.1 app (using different rvm gemsets)

I just followed these directions for installing a new rvm gemset and installing rails-3.1.0.rc2 on my local machine. At first I was getting a Passenger error saying the rake-0.9.2 gem could not be loaded, but I found this reminding me to run "$ passenger-install-apache2-module". It installed fine prompted me to add the following to my Apache config file (/etc/apache2/httpd.conf):
LoadModule passenger_module /Users/robs/.rvm/gems/ruby-1.9.2-p180#rails-3.1/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /Users/robs/.rvm/gems/ruby-1.9.2-p180#rails-3.1/gems/passenger-3.0.7
PassengerRuby /Users/robs/.rvm/wrappers/ruby-1.9.2-p180#rails-3.1/ruby
However, there are already three lines there from a different gemset:
LoadModule passenger_module /Users/robs/.rvm/gems/ruby-1.9.2-p180#rails-3.0/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /Users/robs/.rvm/gems/ruby-1.9.2-p180#rails-3.0/gems/passenger-3.0.7
PassengerRuby /Users/robs/.rvm/wrappers/ruby-1.9.2-p180#rails-3.0/ruby
If I leave both sets of lines there uncommented (the #rails-3.1 gemset's is last), and restart Apache, my Rails 3.0 app won't start. I find myself having to comment out the rails 3.1 gemset lines, restart Apache, and then run "$ rvm use ruby-1.9.2-p180#rails.3.0". If I want to run the Rails 3.1 app, I have to do the opposite.
Is there a way to have both be able to run at the same time without these extra steps?
This article could be useful for you.
I used it as an example to setup my own development environment with nginx.
You could tell Passenger to use ruby 1.9.2 without a gemset, then in each of your apps run rvm use ruby-1.9.2-p180 and bundle install. This means your base ruby-1.9.2-p180 will have the gems for both applications, and bundler should handle limiting the gems available to your application.
End result:
ruby-1.9.2-p180 has gems for both apps
ruby-1.9.2-p180#rails-3.0 has gems for your 3.0 app
ruby-1.9.2-p180#rails-3.1 has gems for your 3.1 app
passenger is using ruby-1.9.2-p180
bundler should still limit the gems available to each application
both apps should work

Passenger / REE can't find rails, it's in the $PATH, what gives?

I've got a fresh install of Ruby EE (1.8.6-20090610) and Passenger (2.2.5) on Debian Lenny. REE is installed in /opt/ruby-enterprise and it is added to the $PATH of all users through /etc/environment, and PassengerDefaultUser is set to root. The problem is when loading a rails app, the Passenger error says the rails 2.3.3 gem is missing. However it was installed with Passenger and a rails -v as root says it's there. What could be going wrong?
Found the error:
PassengerRuby /usr/bin/ruby1.8
should have been
PassengerRuby /opt/ruby-enterprise/bin/ruby

Resources