Are you looking to set up a Ruby on Rails application on your Ubuntu server with nginx and Passenger? Look no further, as this guide will walk you through the steps to get your application up and running smoothly.
Step 1: Update your system
Before installing any new software, it’s crucial to update your system’s package list. This ensures you have the latest software repositories available to you.
sudo apt update
sudo apt upgrade
Step 2: Install Ruby and Rails
Next, we need to install Ruby and Rails on your Ubuntu server. Run the following commands to install Ruby using RVM (Ruby Version Manager) and Rails:
sudo apt install curl gnupg -y
\curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm install 2.7.2
gem install rails
Step 3: Install nginx
Now, we’ll install nginx as our web server. Run the following command to install nginx on your Ubuntu server:
sudo apt install nginx -y
Step 4: Install Passenger
Passenger is a web server application that works well with Ruby on Rails applications. Install Passenger using the following command:
sudo apt install -y dirmngr gnupg
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
sudo apt-get install -y apt-transport-https ca-certificates
sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger focal main > /etc/apt/sources.list.d/passenger.list'
sudo apt-get update
sudo apt-get install -y libnginx-mod-http-passenger
Step 5: Configure nginx with Passenger
Finally, we need to configure nginx to work with Passenger. Edit the nginx configuration file at /etc/nginx/nginx.conf
and add the following lines within the http
block:
passenger_root /usr/share/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /home/<your_user>/.rvm/gems/ruby-2.7.2/wrappers/ruby;
Save the file and restart nginx with the following command:
sudo systemctl restart nginx
That’s it! You now have Rails and nginx running seamlessly on your Ubuntu server with Passenger. Your Rails application should be accessible through your server’s IP address or domain name. Happy coding!