Bobcares

Deploy rails application on linode | All about

by | Nov 26, 2022

Let’s work on how to Deploy rails application on linode by our Server Management Services. We Bobcares respond to all your queries, no matter how simple.

Deploy rails application on linode setup

Deploy rails application on linode

Installing Ruby Enterprise Edition, Apache, MySQL, and Passenger for deploying Rails 3.0 applications. Get a Linode, and set it up with Ubuntu. Once the Linode is formatted, boot it and continue on. Set up an ‘A’ record in DNS, that points to the IP of your Linode.

 

Initially login to the server by SSH access.

ssh root@your_ip
 

Next, Add a user.

 
adduser deploy
 

Further, Add the user to the SUDOERS list with visudo.

 
# User privilege specification
root    ALL=(ALL) ALL
deploy   ALL=(ALL) ALL
 

Change the default SSH port and disallow root access. vim /etc/ssh/sshd_config

 
# What ports, IPs and protocols we listen for
Port 16888

...
PermitRootLogin no
 

Log out and reboot your Linode via the console. Do not attempt to restart SSHD while connected.

 

Now Test the new settings – Log back in using: "ssh deploy@your_ip -p 16888" and log out again.

 

Create your authorized keys file:

 
mkdir ~/.ssh
touch ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
 

Now Logout and upload your public key.

 
cat ~/.ssh/id_rsa.pub | ssh deploy@your_ip -p 16888 'cat >> .ssh/authorized_keys'
 

This looks a little complex. But we’re just printing out the SSH key, piping the output to SSH, and directing it into  authorized_keys on the remote server. By this way you can turn it into a script and use this to add multiple keys.

 

Log back in and you’re set with keys.

 

Installing Ruby

 

Here we will use Ruby Enterprise Edition through RVM.

 
  • Install RVM $> bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
 
  • Install some required libraries to allow for RVM to build REE $> sudo apt-get install build-essential patch zlib1g-dev libssl-dev libreadline5-dev
 
  • rvmsudo rvm install ree
 
  • rvm gemset use global gem install bundler
 
  • set default ruby rvmsudo rvm –default use ree
 

Installing MySQL for Rails

 

We install MySQL with the package manager:

 
sudo apt-get install mysql-server libmysqlclient-dev
gem install mysql
 

Now log into MySQL with mysql -u root -p and create a user.

 
create user 'rails'@'localhost' identified by 'rails';
create databse projects_production;
grant all on projects_production.* to 'rails'@'localhost';
 

These permissions are not the greatest. They could be hardened. But you have to make sure you don’t tighten them too much to the point where you can’t run migrations. Read a good MySQL book.

 

Configuring Apache and Passenger

 
rvm use ree
rvm gemset use global
rvmsudo gem install passenger
sudo apt-get install libcurl4-openssl-dev apache2-prefork-dev  libapr1-dev  libaprutil1-dev

rvmsudo /usr/local/rvm/gems/ree-1.8.7-2011.03@global/bin/passenger-install-apache2-module
 

Follow the instructions.

 

CD to /etc/apache2/conf.d and add a file called “passenger.conf” which has the below contents:

 

LoadModule passenger_module /usr/local/rvm/gems/ree-1.8.7-2011.03@global/gems/passenger-3.0.7/ext/apache2/mod_passenger.so PassengerRoot /usr/local/rvm/gems/ree-1.8.7-2011.03@global/gems/passenger-3.0.7 PassengerRuby /usr/local/rvm/wrappers/ree-1.8.7-2011.03@global/ruby

 

Create a new vhost

 
sudo vim /etc/apache2/sites-available/demo.napcs.com
 

Put this code in the file:

 
ServerName demo.napcs.com DocumentRoot /var/www/demo.napcs.com/current/public
AllowOverride all
Options -MultiViews
 

Then enable the site.

 
sudo a2ensite demo.napcs.com
sudo /etc/init.d/apache2 restart
 

And give the deploy user permissions to the /var/www root folder:

 
sudo chown -R deploy:deploy /var/www 
 

Again, not the best approach, but an acceptable one.

 

We’re done with the server setup.

 

Preparing Your Rails app

 

Create the Rails 3 application. We’ll do a simple one with a single table.

 
rails new demo
cd demo
rails g scaffold projects name:string description:text
rake db:migrate
rm public/index.html
 

Add a root route to config/routes.rb

 
root :to => "projects#index"
 

Add the mysql2 gem to your Gemfile and get the sqlite3 one only in dev mode. Specify the version numbers for the gems.

 
group :development do                                                                                                                                                                                
  gem 'sqlite3', '1.3.3'
end

group :production do
  gem 'mysql2', '0.2.7'
end
 

Thenbundle.

 

[Looking for a solution to another query? We are just a click away.]

 

Conclusion

To sum up, you have seen how to deploy the rails application on Linode. Linode does not manage software and systems updates for Marketplace Apps. It is up to the user to perform routine maintenance on software deployed in this fashion.

 

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.