Skip to content

Latest commit

 

History

History
203 lines (154 loc) · 5.62 KB

File metadata and controls

203 lines (154 loc) · 5.62 KB
title excerpt updated
Install Rails on your POWER web hosting plan
Find out how to install Rails on your POWER web hosting plan
2021-02-04

Objective

You've subscribed to a Web POWER web hosting plan to deploy Ruby applications, and you want to deploy Rails{.external} on it.

This guide will explain how to do it.

Find out how to install Rails on your POWER web hosting plan.

Requirements

If you have just started to use your Web POWER web hosting plan, we suggest to have a look at our Getting started with a POWER web hosting plan guide before going further.

Instructions

Let's suppose you have the default configuration for Ruby hosting:

  • Runtime: Ruby 2.6
  • Entrypoint: config.ru
  • DocumentRoot: www
  • Environment: development

[!alert]

Be careful, Rails depends on the environment (RAILS_ENV).

[!primary]

To verify your configuration, you can use the Retrieve active configuration API endpoint.

Connect via SSH to your POWER web hosting.

Delete your DocumentRoot to initiate it with rails (don't forget to export your gempath or your bundle install will fail):

rm -rf www
gem env gempath
export GEM_HOME=$(gem env gempath | cut -d ':' -f1)
export RAILS_ENV=${OVH_ENVIRONMENT}
rails new www
cd www/
rails  webpacker:install

Now whitelist your domain name in www/config/environments/development.rb:

Rails.application.configure do
  # Whitelist one hostname
  config.hosts << "your-domain.ovh"

Deactivate check_yarn_integrity check under section development in www/config/webpacker.yml:

development:
  <<: *default
  compile: true

  # Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
  check_yarn_integrity: false

Then restart your instance and your Rails will be online.

Rails{.thumbnail}

Now let's generate a Hello World with Rails:

export SPRING_SERVER_COMMAND="$HOME/www/bin/spring server"
rails generate controller demo index

Create the template app/views/demo/index.html.erb:

vim app/views/demo/index.html.erb
&lt;h1>Hello World&lt;/h1>
&lt;p>Hello World from Rails&lt;/p>

Build the Hello World:

./bin/webpack

After another restart, your Hello World will be available in https://yourdomain.ovh/demo/index.html.

Rails{.thumbnail}

Terminal output:

~ $ rm -rf www

~ $ gem env gempath
/homez.41/powerlp/.gem/ruby/2.6.0:/usr/local/ruby2.6/lib/ruby/gems/2.6.0

~ $ export GEM_HOME=$(gem env gempath | cut -d ':' -f1)

~ $ export RAILS_ENV=${OVH_ENVIRONMENT}

~ $ rails new www
      create
      create  README.md
      create  Rakefile
      create  .ruby-version
[...]
Fetching webpacker 4.3.0
Installing webpacker 4.3.0
Bundle complete! 17 Gemfile dependencies, 75 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
         run  bundle binstubs bundler
[...]   
Installing all JavaScript dependencies [4.3.0]
         run  yarn add @rails/[email protected] from "."
yarn add v1.22.10
[...]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
└─ [email protected]
Done in 6.19s.
Webpacker successfully installed 🎉 🍰

~ $ cd www/

~/www $ rails  webpacker:install
   identical  config/webpacker.yml
Copying webpack core config
       exist  config/webpack
   identical  config/webpack/development.js
   identical  config/webpack/environment.js
   identical  config/webpack/production.js
   identical  config/webpack/test.js
[...]
info Direct dependencies
└─ [email protected]
info All dependencies
└─ [email protected]
Done in 3.81s.
Webpacker successfully installed 🎉 🍰

~/www $ export SPRING_SERVER_COMMAND="$HOME/www/bin/spring server"

~/www $ rails generate controller demo index
Running via Spring preloader in process 11410
      create  app/controllers/demo_controller.rb
       route  get 'demo/index'
      invoke  erb
      create    app/views/demo
      create    app/views/demo/index.html.erb
      invoke  test_unit
      create    test/controllers/demo_controller_test.rb
      invoke  helper
      create    app/helpers/demo_helper.rb
      invoke    test_unit
      invoke  assets
      invoke    scss
      create      app/assets/stylesheets/demo.scss

~/www $ vim app/views/demo/index.html.erb
&lt;h1>Hello World&lt;/h1>
&lt;p>Hello World from Rails&lt;/p>

~/www $ ./bin/webpack
Hash: 15d1bb7b54cf6326b9ba
Version: webpack 4.44.2
Time: 1102ms
[...]

~/www $ mkdir -p tmp

~/www $ touch tmp/restart.txt

More information on Rails

To get more information on Rails, go to the official documentation site.

Go further

Join our community of users on https://community.ovh.com/en/.

Join our Discord on our web-hosting-power channel to discuss directly with the team and other users of this lab.