In this guide I will show how to create a new Rails project and deploy it using Appliku

The demo project repository

You can find it on GitHub: https://github.com/appliku/railsdemo

1. Install Ruby

To install Ruby install rbenv https://github.com/rbenv/rbenv

For Mac users:

brew install rbenv ruby-build

For Linux users:

sudo apt install rbenv

For Windows users, first install Ubuntu with WSL.

Open Powershell and run:

wsl --install -d Ubuntu

Reboot your computer to finish the installation.

Then inside the Ubuntu:

sudo apt-get update
sudo apt-get install git-core zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev rbenv

Make sure rbenv is enabled in your shell configuration.

For zsh you need to add this line to your ~/.zshrc

eval "$(rbenv init - zsh)"

For bash, in ~/.bashrc:

eval "$(rbenv init - bash)"

Reopen your terminal for these changes to apply and check that you have the correct version of Ruby:

ruby -v
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin23]

Install the latest version of Ruby with rbenv, for this guide it is 3.3.0 and enable it globally. Then install the rails gem.

rbenv install 3.3.0
rbenv global 3.3.0
gem install rails

2. Creating a Rails project

Let's create a Ruby project. We'll use Postgres for database.

rails new myrailsproject -d postgresql
cd myrailsproject

Generate the main page:

rails generate controller Pages home

Edit the config/routes.rb file to set the root route to the home action:

Rails.application.routes.draw do
  root 'pages#home'
end

Edit the app/controllers/pages_controller.rb file to define the home action:

class PagesController < ApplicationController
  def home
  end
end

Create a view file for the home action at app/views/pages/home.html.erb:

<h1>Welcome to your Rails Project</h1>
<p>Deployed with Appliku</p>

3. Create Procfile

Create the Procfile in the root of the repo with the following contents:

web: bin/rails server
release: bin/rails db:migrate

4. Push Rails Project to GitHub

Create a repository on GitHub https://github.com/new, commit your changes and push you project there. image

For this example, I've created a Public repo, but for your project you most likely want to select "Private". image

Use these commands to commit and push your code, but make sure to replace the remote URL to what GitHub gives you.

git add .
git commit -m'Initial commit'
git remote add origin git@github.com:appliku/railsdemo.git
git push -u origin master

Now you can see your code is on GitHub: image

5. Create Appliku app and deploy your Rails project

Deploy your Rails app to your server with Appliku Go to Appliku dashboard To deploy your Rails app you need to have an Appliku account and have a server created.

If you do not have an account: please follow this link https://app.appliku.com/ and create an account.

If you haven't added a server: please follow the instructions in the dashboard.

Create an application from GitHub repository. Give it a name. Select repository that we've just created. Select the branch master and your server. Click "Create application".

image

Now you need to create a database. You can do it by clicking "Add Database" on the right side of the page.

image

Select Postgres 15 and click Create database image

Wait for the database to be deployed, then get back to the app overview. image

Go to Application settings.

On the "Build settings" tab set "Base Docker Image" to "Ruby 3.3 Rails".

image

Now go to the "Environment variables" tab. You will see that the DATABASE_URL is already there because we created a database.

Create a variables SECRET_KEY_BASE with some random string.

image

Click "Add",

Then add RUBY_ENV variable and set it to production. Click "add".

Then "Save and deploy" button. image

Let's go back to application overview page and open our app:

image

Congratulations, your Rails project has been deployed!

image