Ruby on Rails is one of the most popular frameworks for building modern web applications. When paired with Passenger and Nginx, you get a production-ready deployment stack that is simple, secure, and high-performance.
In this guide, we’ll walk through the process of setting up a fresh Ruby on Rails application to deploy Ruby on Rails and running it with Passenger on Ubuntu 24.
Steps to Deploy Rails with Passenger
1. Update and Install Dependencies
Make sure your system is up to date and install essential packages:
#apt update
#apt upgrade
#sudo apt install git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev
#apt install ruby gem ruby-dev
Install Nginx:
#apt-get install nginx
2. Install Passenger
Add the Phusion Passenger repository and install Passenger:
#apt-get install dirmngr gnupg apt-transport-https ca-certificates curl
#curl https://oss-binaries.phusionpassenger.com/auto-software-signing-gpg-key.txt | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/phusion.gpg >/dev/null
#sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger noble main > /etc/apt/sources.list.d/passenger.list'
#apt-get update
#apt-get install libnginx-mod-http-passenger
Validate Passenger installation:
#/usr/bin/passenger-config validate-install
And select apache from the shown list
3. Create a Rails Application
Set up your working directory and install Rails:
#mkdir -p /var/www
#cd /var/www
#apt install ruby-bundler libsqlite3-dev
#rails new app_name
#cd app_name
For security, you should avoid running your Rails application as the root user. Instead, create a dedicated system user that owns your Rails application files and runs Passenger.
Create a new user:
#adduser deploy
Set ownership of your Rails app directory:
#chown -R deploy:deploy /var/www/app_name
Switch to the new user before running Rails commands:
#su deploy -
$cd /var/www/app_name
Install the gems:
$bundle install
4. Configure the Database
Create and migrate the database:
$rake db:create
$rake db:setup
$rake db:migrate
5. Configure Nginx for Rails
Create a new Nginx server block for your Rails app:
#vim /etc/nginx/sites-enabled/rails.conf
Add the following configuration:
passenger_log_level 5;
server {
listen 80;
server_name www.example.com;
root /var/www/app_name/public;
index index.htm index.html;
passenger_enabled on;
}
Restart Nginx:
#systemctl restart nginx
6. Add a Root Route
Set a root route in your Rails app:
#vim /var/www/app_name/config/routes.rb
Add:
root "home#index"
Generate a controller and view:
#rails generate controller Home index
Restart passenger:
#touch tmp/restart.txt
Conclusion
You’ve now successfully deployed a Ruby on Rails application with Passenger and Nginx on Ubuntu 24. With Passenger managing your application processes, you get a streamlined and reliable production setup. From here, you can continue building your Rails application, configure your domain, and set up SSL for a fully secure deployment.
If you’re planning to deploy Ruby on Rails with Passenger on Ubuntu 24, expert guidance can make the process smoother and more reliable. At Skynats, we specialize in application deployment, DevOps practices, and comprehensive server management services to ensure your Rails apps run securely and efficiently.
Need assistance with deployment or server optimization? Contact Skynats today for expert support!