> ## Documentation Index
> Fetch the complete documentation index at: https://help.noxity.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy Rails

> Run a Rails app on the Ruby Selector. Bundler in deployment mode, asset precompilation, restart.

Rails comes with a `config.ru` already wired for Rack. The deployment loop is: install gems, precompile assets, run migrations, restart.

For the underlying tool, see [Ruby](/web-hosting/virtual-containers/ruby).

## Before you begin

* A Ruby app created in cPanel.
* A Rails app at the application root, with `Gemfile`, `config.ru`, and `config/environment.rb`.
* The Ruby version Passenger ships matches what your `Gemfile` declares. Check with `ruby --version` over SSH.

## Deploy the app

<Steps>
  <Step title="Add the linux platform to your lockfile">
    From your dev machine:

    ```bash theme={}
    bundle lock --add-platform x86_64-linux
    git add Gemfile.lock && git commit -m "Add linux platform"
    ```
  </Step>

  <Step title="Install gems">
    Click **Run Bundle Install** in the cPanel app management page. Or from SSH:

    ```bash theme={}
    cd ~/myapp
    bundle config set deployment 'true'
    bundle install
    ```
  </Step>

  <Step title="Precompile assets">
    Over SSH:

    ```bash theme={}
    cd ~/myapp
    RAILS_ENV=production bundle exec rake assets:precompile
    ```

    If memory is tight, precompile on a dev machine and rsync `public/assets/` up.
  </Step>

  <Step title="Run migrations">
    ```bash theme={}
    RAILS_ENV=production bundle exec rake db:migrate
    ```
  </Step>

  <Step title="Restart">
    Click **Restart**, or `touch ~/myapp/tmp/restart.txt`.
  </Step>
</Steps>

## Set the secret base

Rails 5 and later require `SECRET_KEY_BASE` in production. Add to **Environment variables** in the cPanel UI:

```
SECRET_KEY_BASE=<generate with `bundle exec rake secret`>
```

Restart so the value picks up.

## Common issues

<AccordionGroup>
  <Accordion title="503: Could not find gem 'rails X.Y.Z'">
    `bundle install` ran against a different Ruby. Confirm with `bundle env` over SSH and re-run `bundle install` after activating the right Ruby.
  </Accordion>

  <Accordion title="Asset precompilation OOMs">
    Build assets locally, rsync `public/assets/` and `public/packs/` up. Skip the server-side precompile.
  </Accordion>

  <Accordion title="Database connection refused">
    Use the cPanel database hostname (`localhost` typically works for MySQL on the same account). Username and database name come from the cPanel **MySQL Databases** page.
  </Accordion>

  <Accordion title="ActiveJob or Sidekiq processes get killed">
    Long-running workers exceed the LVE NPROC ceiling. Move them to cron-driven one-shot jobs on a Basic plan, or upgrade.
  </Accordion>
</AccordionGroup>

## Need a hand?

<CardGroup cols={2}>
  <Card title="Open a ticket" icon="life-ring" href="https://members.noxity.io/submitticket.php">
    Best for anything that needs an account check or a config change on our end.
  </Card>

  <Card title="Live chat" icon="messages" href="https://noxity.io/contact">
    Faster for quick questions during business hours.
  </Card>
</CardGroup>
