Deploying Rails Application On Heroku
- By: Shriffle

To make your Rails app accessible online, you can deploy it using Heroku, a popular hosting service. Follow these steps to deploy your Rails app on Heroku:
1. Create a Heroku account: Start by creating a new account on Heroku's website.
2. Install the Heroku Toolbelt: Download and install the Heroku Toolbelt, which provides a command-line interface for interacting with Heroku.
3. Log in to Heroku: Open your terminal and log in to Heroku using the following command:
$ heroku login
4. Update Gemfile: Open your app's Gemfile and add the necessary gems for Heroku. Replace the existing `gem 'sqlite'` line with:
gem 'sqlite3', group: :development gem 'pg', '0.18.1', group: :production gem 'rails_12factor', group: :production
5. Install gems: In the terminal, run `bundle install` to install the updated gems specified in the Gemfile.
6. Configure database.yml: Open the `config/database.yml` file and ensure the `adapter` is set to `postgresql` for the production environment. Modify the `production` section as follows:
production: <<: *default adapter: postgresql database: db/production.sqlite3
7. Commit changes: Use Git to commit your changes:
$ git add . $ git commit -m "Heroku config"
8. Create a new Heroku app: In the terminal, create a new app on Heroku using the following command:
$ heroku create
9. Push code to Heroku: Push your code to Heroku on the `main` branch:
$ git push heroku main
10. Migrate the database: If your app uses a database, run the database migrations on Heroku using the following command:
$ heroku run rake db:migrate
11. (Optional) Seed the database: If you need to populate your database with initial data, run the database seed task on Heroku:
$ heroku run rake db:seed
12. Access your app: Obtain the URL of your deployed app using the Heroku CLI:
$ heroku apps:info
Copy the URL listed under the `Web URL` field and open it in your browser to access your deployed Rails app.
For more detailed information and advanced configurations, refer to Heroku's Rails documentation.
Note: Make sure you have a properly configured `Procfile` in your app's root directory if you need to define any custom processes or workers for your app to run correctly on Heroku.
1 Comments