Shared Server Dreamhost - ruby-on-rails

I am trying to install an app on a shared server. If i understand properly because i am using a shared server, and that Dreamhost doesn't suppose rails 3.2.8 I must use FCGI, although i am not sure how to install and to make it run properly.
From this tutorial http://wiki.dreamhost.com/Rails_3.
To my understand here what I did,
In dreamhost, activate PHP 5.x.x FastCGI and made sure Phusion Passenger is unchecked
Create an app on my localmachine
Because rails doesn't create a dispatch and access file i create the two following file in my /public folder
dispatch.fcgi
#!/home/username/.rvm/rubies/ruby-1.9.3-p327/bin/ruby
ENV['RAILS_ENV'] ||= 'production'
ENV['HOME'] ||= `echo ~`.strip
ENV['GEM_HOME'] = File.expand_path('~/.rvm/gems/ruby 1.9.3-p327')
ENV['GEM_PATH'] = File.expand_path('~/.rvm/gems/ruby 1.9.3-p327') + ":" +
File.expand_path('~/.rvm/gems/ruby 1.9.3-p327#global')
require 'fcgi'
require File.join(File.dirname(__FILE__), '../config/environment')
class Rack::PathInfoRewriter
def initialize(app)
#app = app
end
def call(env)
env.delete('SCRIPT_NAME')
parts = env['REQUEST_URI'].split('?')
env['PATH_INFO'] = parts[0]
env['QUERY_STRING'] = parts[1].to_s
#app.call(env)
end
end
Then created the file
.htaccess
<IfModule mod_fastcgi.c>
AddHandler fastcgi-script .fcgi
</IfModule>
<IfModule mod_fcgid.c>
AddHandler fcgid-script .fcgi
</IfModule>
Options +FollowSymLinks +ExecCGI
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi/$1 [QSA,L]
ErrorDocument 500 "Rails application failed to start properly"
Uploaded to a folder and pointed to the public folder in dreamhost
Made sure dispatch.fcgi has 777 for write
ssh and run the following command in the public folder : ./dispatch.fcgi
Crossing my finger but it doesn't work I get the following errors
./dispatch.fcgi: line 1: ENV[RAILS_ENV]: command not found
./dispatch.fcgi: line 1: =: command not found
./dispatch.fcgi: line 2: ENV[HOME]: command not found
./dispatch.fcgi: line 2: =: command not found
./dispatch.fcgi: line 3: syntax error near unexpected token ('
./dispatch.fcgi: line 3:ENV['GEM_HOME'] = File.expand_path('~/.rvm/gems/ruby 1.9.3-p327')'
Doing wrong??? Oh and if i go on the server i get this Rails application failed to start properly

I'm in a simlar boat. Make sure you set your username in the first line. Also the last line of the dispatch.fcgi is missing for the rvm verson. Get the last line from the other dispatch example and set your application name.
Last be sure your environment and databases files are set up properly and you have the required gems such as mysql2, fcgi and therubyracer.
I'm not done solving mine yet, but I will make a blog post once I figure out what is needed.

Related

Cannot start ruby on rails application on server but works locally, wrong environment path

I've encountered an issue that is preventing me from starting my Ruby on Rails application on our Production server despite it running correctly on both Development and Staging environments. The error message is as follows:
[ E 2021-04-26 14:53:39.4216 14896/T11 age/Cor/App/Implementation.cpp:221 ]: Could not spawn process for application /path/to/application: The application encountered the following error: No such file to load -- /path/to/application/app/config/environment.rb (LoadError)
For some reason Passenger is attempting to find the config/environment.rb inside of an app folder when instead it should just be looking for:
/path/to/application/config/environment.rb
Passenger is being configured using Apache and the site config can be seen below:
<VirtualHost *:80>
# PassengerFriendlyErrorPages on
# PassengerStartTimeout 90
ServerAdmin email#example.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
DocumentRoot /path/to/application/public
<Directory /path/to/application/public>
AllowOverride None
Options -Multiviews
Require all granted
</Directory>
</VirtualHost>
PassengerPreStart http://localhost
PassengerAppEnv production
PassengerLogFile ${APACHE_LOG_DIR}/passenger.log
The server is running Ubuntu 18.04. I've included what I think are the relevant versions below:
Ruby - 2.5.1
Ruby on Rails - 5.2.5
Passenger - 6.0.7
Does anyone know what config I may be missing that is causing Passenger to be looking in the wrong place?
look .. i read about passenger , i am beginner to ruby ;"beginner"= when i remember about ruby,python i download them and i try to compile them to exe to find out if they changed things = .exe smaller or for the another alternative of compilers i usually use ..
today's test was in ruby + apache + php 8.1 as testing a output from a http://localhost/test/ and without any compilation (this isn't the answer to your question but if anyone needs this new point of view and you use php and ruby always ..)
in windows with apache ,php ,.. and ruby installed , in your htdocs create test folder and put these into it:
index.php
<?php
// Highest priority
proc_nice(-20);
echo shell_exec('index.rb');
//system('index.rb');
?>
index.rb
#puts "Content-type: text/html\r\n"
puts "Hello World" + "<br>"
time1 = Time.new
puts "Current Time : " + time1.inspect + "<br>"
# Time.now is a synonym:
time2 = Time.now
puts "Current Time : " + time2.inspect + "<br>"
now open the browser and go to http://localhost/test/
then if you click refresh or you hit f5 key(refresh) in your bowser after the first results then the time shoul display the refresh values

configuring .htaccess file with multiple subdomains Justhost

Situation is like this :
I have hosting company justhost.com
There I have main domain and two subdomains. First subdomain is with PHP
based webpage, but second is newly created and based on ruby on
rails.
I want such thing, before I am sure that newly created application on RoR is functioning well, keep old one up and running. But somehow when I want modify .htaccess file with code for RoR (source- https://my.justhost.com/cgi/help/rails#access ).
main htacces file located on root_page :
DirectoryIndex index.html index.shtml index.xhtml index.wml index.perl index.pl index.plx index.ppl index.cgi index.jsp index.js index.jp index.php4 index.php3 index.php index.phtml index.htm home.htm default.htm index.fcgi default.html
# -FrontPage-
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthUserFile /home/ecotec11/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/ecotec11/public_html/_vti_pvt/service.grp
ErrorDocument 404 /404.shtml
AuthName ecotechno.lv
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
htacces file for RoR application:
Options -MultiViews
PassengerResolveSymlinksInDocumentRoot on
#Change to your environment
RailsEnv production
RailsBaseURI /$HOME/$USER/eco
SetEnv GEM_HOME /
This is what I get :
http://gyazo.com/291394024c60284e315b04b3b91128f4 :
It seems that project can't find installed gems or valid rails installation. I tried to update rails installation, but now when it succeded there is no change at all.
Thanks

How to install a wordpress inside a rails on heroku

I unzip and rename wp-config-sample.php => wp-config.php and conffig it.
it is exactly my file (i have no edit)
// Heroku Postgres settings
if (isset($_ENV["DATABASE_URL"])) {
$db = parse_url($_ENV["DATABASE_URL"]);
define("DB_NAME", trim($db["path"],"/"));
define("DB_USER", $db["user"]);
define("DB_PASSWORD", $db["pass"]);
define("DB_HOST", $db["host"]);
} else {
die("Cannot determine database settings from DATABASE_URL\n");
}
Then I create .htaccess (app/.htaccess) and config(i have no edit):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
Then I upload it to blog folder on heroku. And try install but it always return eror 404 (I see logs heroku) my link to install:
http://mywebsite.heroku.com/blog/wp-admin/install.php
ActionController::RoutingError (No route matches "/blog/wp-admin/install.php
Please help me install this.
Thanks so much
You can't do this - but not due to Heroku not having PHP - because it does. The Cedar stack added support for PHP Facebook applications but you are able to run Wordpress on them. See http://tjstein.com/2011/09/running-wordpress-on-heroku-and-amazon-rds/
HOWEVER You cannot mix languages in the same Heroku application, eg Rails and PHP - they would need to exist as separate Heroku applications. When the application slug is compiled the language is detected at that point.

Deploy Rails Application on Bluehost

I am trying to deploy my RoR application in Bluehost but I´m having some trouble. I want my Rails application to be accessible from a top-level domain, that is to be access once someone access my website URL. I have followed several tutorials, and tried several approaches, but I´m still getting no where. When I access my URL (http://hotelelcidacapulco.com/) I get the following message: No such file or directory - config.ru
I assume it must be a problem of the Symlink. I´ve tried different symlinks however I think it should be:
ln -s ~/path/appName/public appname so something like this:
ln -s ~/rails_apps/ElCid/public ElCid
But I get again the error message message: No such file or directory - config.ru
Again, I´m deffinitely no expert but I assume it has something to do with the symlink. I´ve been struggling a lot, and would really appreciate the help as I need to get it runnning as soon as possible.
Here are my files:
/home3/hotelelc/public_html/.htaccess File:
SetEnv GEM_HOME /home3/hotelelc/ruby/gems
<IfModule mod_passenger.c>
Options -MultiViews
PassengerResolveSymlinksInDocumentRoot on
RailsEnv production
RackBaseURI /
SetEnv GEM_HOME /home3/hotelelc/ruby/gems
</IfModule>
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)/!$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
ErrorDocument 500 "Application error Application failed to start properly"
/home3/hotelelc/.bashrc File:
export HPATH=/home3/hotelelc/
export GEM_HOME=$HPATH/ruby/gemsexport GEM_HOME=$HPATH/ruby/gems
export GEM_PATH=$GEM_HOME:/usr/lib64/ruby/gems/1.8
export GEM_CACHE=$GEM_HOME/cache
export PATH=$PATH:$HPATH/ruby/gems/bin
export PATH=$PATH:$HPATH/ruby/gems
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
Finally, this is my /config/environment.rb File:
require File.expand_path('../application', __FILE__)
ElCid::Application.initialize!
ENV['GEM_PATH'] = '/home3/hotelelc/ruby/gems:/usr/lib64/ruby/gems/1.8'
Try moving your .htaccess file to the public directory of your app instead of public_html. I believe this will be app/public/.htaccess. Hope it helps!
Yeah I know this is an old question, but for future readers.

Rails Caching - XML Files?

My Rails application is running on a VM. The VM's performance is just fine with static pages. In fact, I'm running another site using Apache virtual hosting that is just serving up static HTML files and the response is adequate. However, my Rails application that is dynamically generating XML files responds very slowly. In fact, it takes about 10 seconds or so for each XML file. These XML files that Rails generates do not change more than once a day.
What is the best practice to configure these XML files to be cached?
Edit 1:
I should mention that these XML files are not viewed by a browser. They are viewed by mobile applications in the "field." So, unfortunately sending "HTTP/1.0 304 not modified" won't work.
Edit 2:
If it matters, I'm using Phusion Passenger to host my Rails app.
If you're using rails' static page caching and serving through apache, just using an explicit xml extension on the urls would do it.
if you're only serving xml and no html you might also edit the apache conf to default to xml instead of html when looking for cached files.
cache expiry is a rather boring thing to code and test, but since you're seldom regenerating the files, you might just expire the entire cache.
Here's a trimmed selection of files and excerpts from how I handle cache in a small, seldom updated rails site:
In the controllers you want to cache
class XmlThingController < ApplicationController
caches_page :index, :show, :other_actions
In the controllers/actions that modify data that would cause changes to the xmls:
class Admin::SomeCrudController < AppplicationController
cache_sweeper :stupid_master_sweeper, :only => [ :save, :destroy ]
In 'config/environments/production.rb'
config.action_controller.page_cache_directory =
File.join(RAILS_ROOT, 'public', 'cache')
Somehere in your vhost apache conf:
# 1.4. Handle caching
# 1.4.1. prevent direct cache access
RewriteRule ^/cache - [F,L]
# 1.4.2. for index
RewriteCond %{DOCUMENT_ROOT}/cache/index.html -f
RewriteRule ^/?$ /cache/index.html [L]
# 1.4.3. for explicitly specified extensions
RewriteCond %{DOCUMENT_ROOT}/cache%{REQUEST_URI} -f
RewriteRule ^(.*)$ /cache$1 [L]
# 1.4.4. with html extension implied
RewriteCond %{DOCUMENT_ROOT}/cache%{REQUEST_URI}.html -f
RewriteRule ^(.*)$ /cache$1.html [L]
# 1.5. Finally, proxy everything else to mongrel
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://your-website-proxy%{REQUEST_URI} [P,QSA,L]
The dumb sweeper that cleans that entire cache every time it's triggered:
class StupidMasterSweeper < ActiveRecord::Observer
observe Foo, Bar # All models that affect caching here
def after_save(record); end
def after_destroy(record); end
def filter(controller)
# sweep everything.
`cd #{RAILS_ROOT} && RAILS_ENV=#{ENV['RAILS_ENV']} rake cache:clear`
end
end
lib/tasks/cache.rake
namespace :cache do
desc "Remove all cached files"
task :clear do
puts `rm -rf #{RAILS_ROOT}/public/cache/*`
end
end
If you prefer to default the default implied extension to xml, change the extension on the 1.4.2 index rule, and the following:
# 1.4.4. with html extension implied
RewriteCond %{DOCUMENT_ROOT}/cache%{REQUEST_URI}.html -f
RewriteRule ^(.*)$ /cache$1.html [L]
to:
# 1.4.4. with xml extension implied
RewriteCond %{DOCUMENT_ROOT}/cache%{REQUEST_URI}.xml -f
RewriteRule ^(.*)$ /cache$1.xml [L]
Send a "HTTP/1.0 304 not modified" HTTP status code to the client when the XML document is requested.

Resources