
Ruby on Rails remains one of the most productive frameworks for building web applications. Its conventions, mature ecosystem, and focus on developer happiness have powered startups and large platforms alike. Yet moving a Rails application from your laptop to a production environment involves more than copying files to a server. You need to configure environment variables, provision a database, compile assets, run migrations, manage background jobs, and set up a reliable web server behind HTTPS. Modern Rails versions have made this significantly easier, especially with built-in tools like Kamal and improved Docker support. This guide covers the complete process of deploying a Ruby on Rails web application, along with the most popular hosting approaches and best practices for stability and security.
How AAMAX.CO Helps Businesses Launch Reliable Web Applications
A successful Rails deployment requires thoughtful architecture as well as hands-on DevOps experience. AAMAX.CO is a full-service digital marketing company providing web development, digital marketing, and SEO services to clients worldwide. Their engineers help organizations plan application infrastructure, configure secure production environments, and automate deployments so releases are predictable and stress-free. They also optimize performance and search visibility after launch, ensuring the application supports business goals. Companies seeking expert website development can trust them to deliver robust, scalable solutions built on proven frameworks.
Prepare Your Application for Production
Before deploying, review your application for production readiness:
- Use a production database: SQLite has improved greatly for production in recent Rails versions, but PostgreSQL or MySQL remain common choices for multi-server setups.
- Manage secrets securely: Use Rails encrypted credentials or environment variables and never commit the master key to version control.
- Configure production settings: Review config/environments/production.rb for logging, caching, and force_ssl.
- Pin dependencies: Commit your Gemfile.lock so production uses the exact gem versions you tested.
- Run your test suite: Ensure everything passes before shipping.
Choose a Deployment Approach
There are three common ways to deploy a Rails application, each with distinct trade-offs:
- Platform as a Service (PaaS): Providers like Heroku, Render, and Fly.io handle servers, scaling, and routing. You push code, and they build and run it.
- Containers with Kamal: Rails ships with a Dockerfile and Kamal configuration, letting you deploy containers to any Linux server with zero-downtime updates.
- Traditional VPS: Configure a server manually with Ruby, Puma, Nginx, and a database, often using Capistrano for deployments.
PaaS offers convenience, Kamal offers portability and lower cost, and a manual VPS offers maximum control.
Deploying with Kamal
Kamal is now the default deployment tool for new Rails applications. It builds a Docker image of your app, pushes it to a container registry, and runs it on your servers behind a lightweight proxy that handles SSL and zero-downtime switching. The basic workflow looks like this:
- Edit config/deploy.yml with your server IP addresses, image name, and registry credentials.
- Store secrets in the .kamal/secrets file, referencing environment variables rather than hardcoding values.
- Run kamal setup to install Docker on your servers and deploy for the first time.
- Run kamal deploy for subsequent releases.
Kamal can also manage accessories such as databases and Redis, making it possible to run a full stack on a single affordable server.
Deploying to a PaaS
On platforms like Render or Heroku, you typically connect your Git repository, specify build and start commands, and provision a managed database. A typical build command installs gems and precompiles assets, while the start command launches Puma. Release phases or pre-deploy commands can run database migrations automatically. Managed platforms also simplify scaling, logs, and SSL certificates, which is ideal for small teams without dedicated operations staff.
Deploying to a Traditional VPS
If you prefer a hands-on approach, provision an Ubuntu server, create a deploy user, and install Ruby with a version manager. Install PostgreSQL, Node.js if your asset pipeline needs it, and Nginx as a reverse proxy. Use Puma as the application server and manage it with systemd. Capistrano can automate pulling code, installing gems, precompiling assets, running migrations, and restarting services. Finally, secure the server with a firewall, SSH key authentication, and automatic security updates.
Compile Assets
Rails applications must precompile assets for production with rails assets:precompile. Modern Rails uses Propshaft and import maps by default, which simplifies this step considerably. If you use a JavaScript bundler, make sure the build runs during deployment. Serve compiled assets through a CDN or with long cache headers for the best performance.
Run Database Migrations Safely
Migrations should run as part of every deployment that changes the schema. Use rails db:migrate in a release step and design migrations to be backward compatible, especially when deploying without downtime. For example, add new columns before code depends on them and remove old columns only after code no longer references them.
Handle Background Jobs
Most production Rails apps use background jobs for emails, file processing, and integrations. Solid Queue, which ships with recent Rails versions, stores jobs in the database and removes the need for Redis in many cases. Sidekiq remains popular for high-throughput workloads. Whichever you choose, run workers as separate processes and monitor them alongside your web servers.
Secure and Monitor Your Application
Enable HTTPS everywhere with force_ssl and automatic certificates. Keep Ruby, Rails, and gems updated, and use tools like Brakeman and bundler-audit to catch vulnerabilities. Set up error tracking, uptime monitoring, and performance monitoring so you can detect issues before users report them. Regular automated database backups are essential.
Conclusion
Deploying a Ruby on Rails web application has never been more accessible. Prepare your app for production, choose between a PaaS, Kamal containers, or a traditional VPS, and automate asset compilation, migrations, and background workers. With proper security and monitoring in place, your Rails application will be ready to serve users reliably and scale as your business grows.