start rails server automatically after reboot - ruby-on-rails

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.

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.

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

installing passenger on Apache2 using rvm

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.

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

How to install Redmine on Fedora 11 linux?

I would like to install REDMine on my LINUX LAMP.
First i need to install ROR.
http://www.redmine.org
Provide steps if anybdoy has done installation
If you actually looked, you would have found that the instructions are on the redmine website: http://www.redmine.org/wiki/1/RedmineInstall
Given that no truly reliable installation instructions can be found around (Fedora or other distribution that is), I will hereby detail the installation steps that worked for me. The website instructions are pretty reliable, but this is the most straightforward approach. I assume that you already have Apache2 and MySql, and installed Redmine 1.2.1 on a given $REDMINE_HOME.
This procedure was tested on Ubuntu 11.04, but given the packages involved, it should not be a problem replicating the procedure with success under Fedora. I will try to be as generic as possible.
Ruby:
Install ruby, rubygems, rake and the development mysql client library (libmysqlclient-dev on Ubuntu); a working ruby version is the 1.8.7 as of Sep '11
gem install rails -v=2.3.11
gem install i18n -v=0.4.2
gem install mysql
MySql:
Perform the following list of commands:
create database redmine character set utf8;
create user 'redmine'#'localhost' identified by 'my_password';
grant all privileges on redmine.* to 'redmine'#'localhost';
Redmine configuration:
Create a $REDMINE_HOME/config/database.yml file with at least the following profile:
production:
adapter: mysql
database: redmine
host: localhost
username: redmine
password: my_password
In $REDMINE_HOME, run
rake generate_session_store
rake db:migrate RAILS_ENV=production
rake redmine:load_default_data RAILS_ENV=production
Now running ruby script/server -e production should have you access Redmine at "0.0.0.0:3000".
Apache2:
Install the Apache2 Passenger mod (libapache2-mod-passenger in Ubuntu)
Assuming you provided a symbolic link to $REDMINE_HOME/public from /var/www/redmine, the virtual host should read something like this:
<VirtualHost *:80>
DocumentRoot /var/www
Options Indexes ExecCGI FollowSymLinks
RailsBaseURI /redmine
<Directory /var/www/redmine>
Options -MultiViews
</Directory>
</VirtualHost>
Eclipse Mylyn integration:
Go to $REDMINE_HOME/vendor/plugins and run
git clone git://redmin-mylyncon.git.sourceforge.net/gitroot/redmin-mylyncon/redmine-mylyn-connector
(Re)start the server, and in Redmine under Administration/Plugins the Mylyn Connector Plugin should be listed
Again in Redmine, under Administration/Settings/Authentication, check the "Enable REST web service" field
In Eclipse, install the Eclipse connector via its update site
http://redmin-mylyncon.sourceforge.net/update-site/N/

Resources