0

I bought some hosting space where I have SSH access. Now I want to deploy a Ruby on Rails apps which works locally to one of the subdomains I made, let's call it subdomain.mywebsite.com.

I have setup SSH access via a public key, installed Ruby on Rails and Passenger on the server, and installed Capistrano locally by following the steps provided on the website and via tutorials. When I run cap production deploy the whole site is uploaded to the production server and via SSH I can see the current, releases, repo and shared folder. Unfortunately, when I go to subdomain.mywebsite.com I get a 404 - not found error.

I am new to setting up my own server and do not know what to do now. All tutorials I have found do not explain how to continue from here, and I hope someone who reads this can help me to actually being able to access the site.

Deploy.rb:

require 'capistrano'
set :stages, ["staging", "production"]
set :default_stage, "staging"
set :application, 'chiachia_store' # application name
set :repo_url, 'git@github.com:erooijak/chiachia_store.git' # your repo url
set :deploy_to, '/home/erooijak/chiachia.erooijak.simple-webhosting.eu'
set :user, "root"
set :scm, :git
set :branch, 'master'
set :keep_releases, 5
ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
set :format, :pretty
set :log_level, :debug
set :pty, true
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
set :stage, :production
role :app, %w{root@213.159.6.126}
role :web, %w{root@213.159.6.126}
role :db, %w{root@213.159.6.126}
set :puma_rackup, -> { File.join(current_path, 'config.ru') }
set :puma_state, "#{shared_path}/tmp/pids/puma.state"
namespace :deploy do

desc 'Restart application...'
task :restart do
  on roles(:app), in: :sequence, wait: 5 do
    # Your restart mechanism here, for example:
    execute :touch, release_path.join('tmp/restart.txt')
  end
 end

 desc 'Copy database.yml to correct location.'
 task :copy_databaseyml do
   on roles(:app) do
     execute :cp ,'-r', shared_path.join('config/database.yml'), 
       release_path.join('config/database.yml')
   end
 end

after :publishing, :restart

after :restart, :copy_databaseyml
end

Apache.conf:

LoadModule passenger_module /usr/lib/apache2/modules/mod_passenger.so PassengerRoot /usr/local/rvm/gems/ruby-1.9.3-p547/gems/passenger-4.0.49 PassengerRuby /usr/bin/ruby

  ServerName www.chiachia.erooijak.simple-webhosting.eu
  # !!! Be sure to point DocumentRoot to 'public'!
  DocumentRoot /home/erooijak/chiachia.erooijak.simple-webhosting.eu/current/public
  <Directory /home/erooijak/chiachia.erooijak.simple-webhosting.eu/current/public>
     # 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 effect of running this is the following:

Apache Passenger is running...

So it kind of works. Unfortunately I get a 404 error on all domains, the PHP application keeps running properly.

The passenger.3000.log has the following information:

user2609980
  • 10,264
  • 15
  • 74
  • 143
  • 1
    It's still not enough. We need to know your full deployment stack. We can see you're using puma, is there a reason? What is the webserver you're running behind? Nginx? – Marc Lainez Aug 26 '14 at 12:56
  • @mlainez, I am using puma because it was advised in a tutorial. The webserver is Phusion Passenger on Apache2 with Ruby 2.1.2 and Rails 4.0.5. – user2609980 Aug 26 '14 at 14:55
  • 1
    Can you post your apache virtual host configuration for the domain name you're trying to deploy to? We need to make sure everything is ok there. – Marc Lainez Aug 26 '14 at 14:59
  • @mlainez I posted it. And I can see that I did not make this configuration completely up to par during my late night session- I've updated it with a fresh look. – user2609980 Aug 26 '14 at 16:06
  • Btw, I want to run more than one Ruby on Rails application on this server in the future. I found some advice [Here](http://stackoverflow.com/questions/7490189/run-two-different-rails-application-on-one-dedicated-server). – user2609980 Aug 26 '14 at 16:36
  • Thanks, updated my answer. Hope it helps. I think you should start from scratch and not follow the tutorial you found. – Marc Lainez Aug 26 '14 at 16:40
  • Hi mlainez thank you and you might be right. I will follow the apache passenger tutorial. – user2609980 Aug 26 '14 at 17:01

1 Answers1

1

Why don't we start from scratch.

After reading your last comments, what you want is to be able to deploy multiple rails applications on the same server.

There are many options to do that, and depending on what you choose, configuration is going to be very different. There is a good SO answer that covers the basics you might want to read:

Ruby on Rails Server options

The stack I'm used to is Nginx/capistrano/unicorn but that depends on personal preferences and the nature of what's deployed.

Apache/Phusion passenger

The first thing to do is to configure apache for your domain. The phusion passenger documentation is a very good starting point.

You can even find a complete guide on how to deploy Rails >= 3.X apps with phusion passenger in the same documentation

If you follow carefully the instructions, you should have your app up and running without puma. They even also provide you capistrano recipes to use.

Puma

At this stage, unless you app needs high concurrency, puma is not needed. Phusion Passenger is an app server by itself, no need to add puma behind it. If you really need it for some reason, then you'll be better off switching to Nginx/Puma.

I hope the references I gave you clear things up a bit.

Community
  • 1
  • 1
Marc Lainez
  • 3,070
  • 11
  • 16
  • Thanks for your help. I did decide to continue with the original setup since I had made some successes. Now I have tweaked the deploy.rb a little bit (adding database.yml from somewhere else) and made the Phusion Passenger run. The Passenger is running, but now I get 404 errors everywhere and a 503 on a WordPress site that used to work as well (reboot fixes it). Maybe you can provide some insight, maybe not. :) Thanks a lot for your help and I will continue this tomorrow. – user2609980 Aug 26 '14 at 22:26
  • I still believe you should get rid of puma altogether, it's making everything more complex... Are you sure mod_php is still loaded? Maybe the setup you use messes up with it. – Marc Lainez Aug 26 '14 at 23:05
  • PHP site still works, and when I do passenger-status I get the above information. – user2609980 Aug 26 '14 at 23:07
  • I removed Puma and updated the script above accordingly. The server *is* running so the only thing that I think is missing is an URL to it so I can access it from a browser. – user2609980 Aug 27 '14 at 06:05
  • That means there is something wrong with your apache configuration. Are you sure mod_passenger is properly configured? Look at the doc I referenced in my answer or open a chat so we can try to figure out what's wrong. – Marc Lainez Aug 27 '14 at 13:44
  • What happens when you access to this: www.chiachia.erooijak.simple-webhosting.eu ? – Marc Lainez Aug 27 '14 at 13:57
  • I see a 404 - not found. You? :-) – user2609980 Aug 27 '14 at 18:59
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/60112/discussion-between-user2609980-and-mlainez). – user2609980 Aug 27 '14 at 19:36