Am sorry for the noobness for this,
I am developing a ruby on rails application on my ubuntu 14.04.
As for development, i'm starting my application using ruby script/server.
Ruby -v 1.8.7
Rails -v 2.3.14
MySql
Now my question is how to deploy this on production?
Am planning to use Ubuntu 14.04 Server as well.
I read about the Phusion Passenger but I did not understand what is that for.
I was hoping to make the ubuntu server as a localhost. So that if I point to the browser like myrailsapp, my application will be available (Normally I will use script/server). Do I have to use the script/server command everytime the server will restart?
Please tell me if im on the right track.
------------ I follow a tutorial --------------
I follow a tutorial like this one but I can't figure out how to make a virtual host working I created a virtual host like this:
/etc/hosts
0.0.0.0 example.com
/opt/nginx/conf/nginx.conf
server {
listen 80;
server_name example.com;
passenger_enabled on;
location / {
root /opt/nginx/html/ror/blog/public;
}
}
On my browser i get 403 Forbidden And do i have to start my rails app like script/server?
Try following
http://www.codesapling.com/blog/2014/04/12/set-up-guide-for-rails-server-on-ubuntu/
or
http://codebeerstartups.com/2012/10/complete-guide-to-setup-a-rails-server/
PS : May be the links outdated but help you getting started.
No you dont need to run script/server every time.
set-up your Rails-App in the server, install rails version with the command
sudo gem install rails -v 2.3.1
now install Passenger and Nginx Web Server
sudo apt-get install libssl0.9.8
sudo passenger-install-nginx-module
follow the onscreen instructions, it would show you the ways to install missing packages.
After the missing packages are installed, run the above command again.
Enter choice 1
Press enter when asked for default path (/opt/nginx)
After completion nginx
Configuring Web Server at
cd /opt/nginx/conf/
Related
I have a ROR app (version 6.1.4.1) with Ruby 2.7.4 on a Raspberry Pi 4 with 4 GB RAM and a 32 GB SD card. I installed Passenger 6.0.12 using the tarball installation and am running it with nginx. passenger start in the app directory works successfully, but when I try running it as with nginx (/opt/nginx/sbin/nginx) on port 80, I get the above error when visiting the site.
I'm accessing the app via IP address, which is configured in the nginx.conf and the app is installed in /home/pi/src/bogie_can. There is a .bundle directory with a config file in the app directory, and that's where the gems are installed. I'm running the app in "development" mode, which is configured in the server section of the nginx.conf file using passenger_app_env.
The specific error is that the app cannot find racc-1.5.2. The Bundler info is #<struct Bundler::Settings::Path explicit_path="/home/pi/src/bogie_can/.bundle", system_path=false, default_install_uses_path=false>.. So, we note that the .bundle path is correct and in the .bundle/ruby/2.7.0/gems/ directory, racc-1.5.2 is indeed installed and owned by the user "pi".
I've cleared out old bundle installations and tried switching the app user from pi to root (which was nobody) and back. Also, I'm using rbenv, so I also ran rbenv rehash after the fresh bundle install. I've also carefully reviewed the "Detailed diagnostics" from the Passenger error page (which is super helpful!) and do not see anything that is obviously wrong.
Using the Passenger error page as a guide, it seems that:
The gems are indeed installed as needed
The user, either root or pi, have permissions to access the gems
pi is a reasonable user to run the app
The passenger_root and passenger_ruby are coming from the passenger-config about subcommands and are verified as well.
At this point, there must be some configuration I've overlooked or gotten wrong and I would greatly appreciate some questions and pointers.
I found the root cause of the problem.
I had set passenger_ruby to the result of passenger-command about ruby-command, which gave me:
passenger-config was invoked through the following Ruby interpreter:
Command: /usr/bin/ruby2.7
Version: ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [arm-linux-gnueabihf]
To use in Apache: PassengerRuby /usr/bin/ruby2.7
To use in Nginx : passenger_ruby /usr/bin/ruby2.7
To use with Standalone: /usr/bin/ruby2.7 /usr/src/passenger-6.0.12/bin/passenger start
The following Ruby interpreter was found first in $PATH:
Command: /home/pi/.rbenv/shims/ruby
Version: ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [arm-linux-gnueabihf]
To use in Apache: PassengerRuby /home/pi/.rbenv/shims/ruby
To use in Nginx : passenger_ruby /home/pi/.rbenv/shims/ruby
To use with Standalone: /home/pi/.rbenv/shims/ruby /usr/src/passenger-6.0.12/bin/passenger start
I was using /usr/bin/ruby2.7 and having the problem with racc not being found. I switched it to use the rbenv shim and Passenger was able to correctly find all the gems in the [APP_ROOT]/.bundle/ directory
I also cleared out the default nginx installation, which was still trying to be started with nginx.service and then added my own /etc/init.d/nginx script and added it to the init.d database so that it now starts with the OS.
I have just built a RackSpace cloud server with Ubuntu 12 LTS and performed a "standard" Ruby on Rails installation. I created a user (bob) and added it to the sudu group.
I then logged out of root and logged in as bob. Then issued sudo su from the /home/bob directory. I then installed everything needed to run the Rails Application 'as root'.
I then installed the Rails code in /home/bob and passenger started up when I issued:
RAILS_ENV=production passenger start -p 3000
however, since I want to run multiple Rails applications on this server, I then created another directory /home/bob/newapp and installed Rails code there. (ideally I would want to put all the different Rails applications in their own subdirectory below /home/bob)
When I issue the command (shown below) from /home/bob/newapp
RAILS_ENV=production passenger start -p 3000
I get
passenger: command not found
why is passenger only accessible from /home/bob ?
NEWS: just discovered, passenger is 'available' until the moment I complete the edit of the content of /config/database.yml thus as long as I do NOT edit the database.yml file, passenger will start. After I edit database.yml the "passenger: command not found" appears. How bizarre is that?
SNAP: looks like when I installed passenger it used Ruby-2.1.1 however the old application wants ruby-1.9.3-p194. I need to figure out how to get passenger to run with ruby 1.9.3 or install a second version of passenger (???)
More News:
Thank you,Hongli, for your response. I followed your links/suggestion to read the passenger documentation. I had read it before without recognizing the needed information. This time I found the "magical" command:
rvm-exec ruby-version ruby -S (eg: rvm-exec ruby-1.9.3-p194 ruby -S )
this has turned out to be very helpful, although I did end up following a process which has resulted in two different version of passenger being installed.
Read the About environment variables section of the Phusion Passenger manual to learn what "command not found" errors are, why they occur, and what you can generally do about them.
In your case, entering /home/bob automatically makes RVM change your PATH to include a specific Ruby version's bin directory. Read the When the system has multiple Ruby interpreters section of the Phusion Passenger manual to learn how to deal with that.
The article Hongli suggested I read definitely moved me in the correct direction.
The use of: rvm-exec 'ruby-version' ruby -S allows me to get passenger started, provided a version of passenger has been installed using the version of ruby required by the Rails application.
Thus if I load up a Rails application built with ruby-1.9.3-p194, I will need a version of passenger installed with the same version of ruby.
If I load up another Rails application built with ruby-1.9.3-p286, I will need a version of passenger installed with that version of ruby.
Then starting each version of passenger can be accomplished with the rvm-exec command with the appropriate ruby version.
Perhaps there is a more elegant solution, but the above works for me.
I have done a Phusion Passenger setup on Ubuntu 10.04, with Apache2. Whenever I restart the Apache server I got the following error message, and the Rails application is not running.
[error] *** Passenger could not be initialized because of this error: Unable to start the Phusion Passenger watchdog because its executable (/usr/lib/phusion-passenger/agents/PassengerWatchdog) does not exist. This probably means that your Phusion Passenger installation is broken or incomplete, or that your 'PassengerRoot' directive is set to the wrong value. Please reinstall Phusion Passenger or fix your 'PassengerRoot' directive, whichever is applicable.
I ran into the same problem when compiling from source, but it was intermittent, which was really frustrating (I think it has to w/ Rails environments). We couldn't use the passenger-install-apache2-module/passenger-install-nginx-module scripts, because we needed a customized nginx installation.
I finally fixed the problem by going to whatever the passenger-config --root is, then running: rake nginx.
Update February 2016 (by Passenger author):
The officially supported method to compile PassengerAgent (without also compiling Nginx, as passenger-install-nginx-module does) is with this command:
passenger-config compile-agent
Passenger 5.0.26 and later will automatically detect the error described in this StackOverflow question, and will automatically suggest running the above command.
I've just hit this error myself and struggled to find a good answer, so here's my writeup.
In my setup I'm going for Ubuntu, Apache2, the latest Passenger and Rails 2.3.
Install Ruby and Rubygems NB: make (very) sure your gem -v is correct, if it's wrong you'll do all this twice
sudo gem install passenger
cd /usr/lib
wget http://rubyforge.org/frs/download.php/76005/passenger-3.0.12.tar.gz
tar zxvf passenger-3.0.12.tar.gz
cd passenger-3.0.12
./bin/passenger-install-apache2-module
Add export PATH=/var/lib/gems/1.8/bin:$PATH to ~/.bashrc
ln -s /usr/lib/passenger-3.0.12 /usr/share/phusion-passenger # => this fixes a world of hurt to do with PassengerWatchdog. NB: PassengerWatchdog doesn't come down with apt-get which is why we grabbed the binaries.
ln -s /usr/lib/passenger-3.0.12 /usr/lib/phusion-passenger # => similar issues.
This is from memory following thrashing it through for the last day and a half, I'll tidy up when I have to go through it again.
Try to install passenger module by running script passenger-install-apache2-module .
I had same problem but on nginx; I installed passenger via gem and then recompiled nginx manually with passenger module - this caused error described by you. After running passenger-install-nginx-module such error disappeared.
It had been a while since I had restarted nginx and in the meantime the path to passenger had changed. I looked in the nginx.conf to see what the passenger_root was set to and realized that it was the old value:
http {
passenger_root /home/nginx/rails_app/myapp/shared/bundle/ruby/1.9.1/gems/passenger-enterprise-server-3.0.17;
There are often two places to change:
server {
listen 8888;
root /home/nginx/rails_app/myapp/current/public;
I restarted nginx and the error was gone.
I had the same issue on my Nginx-Server.
In my case, the passenger_root directory was not correct, because of gem update.
[1] On Linux, i searched the passenger Directory with the following Command:
find / -name PassengerWatchdog
[2] Now i changed my 'passenger_root' Value to this Directory.
[3] And restart the Server.
suvankar, Maybe you should change your Passenger Path too.
I want to map:
www.example.com
in my host file, how can I start 'rails server' so it uses this domain?
Edit the hosts file (instructions for OSX Snow Leopard)
sudo nano /etc/hosts
Add a line 127.0.0.1 www.example.com
Refresh DNS settings with sudo dscacheutil -flushcache
Start rails on the correct port
rails server will now work on http://www.example.com:3000/. To get rid of :3000, start Rails with: sudo rails server --port=80 (or rvmsudo if you are using RVM)
For production use, you might want to see Kevins answer.
I'd recommend setting up Passenger on either Nginx or Apache to do this. Doing a quick search on your operating system should come up with a tutorial on how to set everything up correctly.
I'm trying to get started writing some Ruby on Rails apps and have been successful with Mongrel but, I'd like to deploy my apps to my Apache 2.2 instance on Windows? All the tutorials I've found seem out of date and are for older versions of Apache/Rails.
Does anyone know of a good, current tutorial for configuring Apache 2.2 for Ruby on Rails apps?
EDIT: At least until there's a Phusion Passenger for Win, Apache + Mongrel is the way to go. You can use Apache + FastCGI without Mongrel, but under real loads you will get (more) zombie processes and (more) memory leaks.
You could also look at proxying to Thin in the same way as detailed below. However, I've had some instabilities with Thin on Win, even though it's appreciably quicker. AB (Apache Benchmark) is your friend here!
Configuring Apache + Mongrel on Windows is not significantly different from *nix.
Essentially, you need to proxy requests coming into Apache to Mongrel. What this boils down to is something like this:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
<VirtualHost localhost:80>
ServerName www.myapp.comm
DocumentRoot "C:/web/myapp/public"
ProxyPass / http://www.myapp.com:3000/
ProxyPassReverse / http://www.myapp.com:3000/
ProxyPreserveHost On
</VirtualHost>
Stick this in your httpd.conf (or httpd-vhost.conf if you're including it).
It assumes you're going to run mongrel on port 3000, your Rails root is in C:\web\myapp, and you'll access the app at www.myapp.com.
To run the rails app in production mode:
mongrel_rails start -p 3000 -e production
And away you go (actually mongrel defaults to port 3000 so you could skip -p 3000 if you want).
The main difference is that you cannot daemonize mongrel on Windows (i.e. make it run in the background). Instead you can install it as a service using the mongrel_service gem.
Also, running a cluster is more complicated and you won't be able to use Capistrano. Let me know if you want more info.
I'm new to RoR and have been attempting the same thing on Windows Server 2008, here are some additional notes on getting mongrel going as a service:
if you get compilation errors when installing mongrel_service:
gem install mongrel_service
try using a binary instead by specifying your platform:
gem install mongrel_service --platform x86-mswin32
Additionally, to actually install the service you need to run this command in your RoR's app directory:
mongrel_rails service::install --name MyApp -e production -p 3001 -a 0.0.0.0
(or to remove:
mongrel_rails service::remove --name MyApp
)
Then you should be able to start/stop the app "MyApp" in your windows services control panel.
Hope that helps someone.
At the moment Mongrel does not work properly with Ruby 1.9 and will throw a "msvcrt-ruby18.dll not found" error when executing the command mongrel_rails.
Thin in this case seems to be the only option for now.
I just wanted to add this article to the list. It explains how to have Apache serve ruby files without the need to install any other applications.
http://editrocket.com/articles/ruby_apache_windows.html
You might want to try Bitnami RubyStack