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
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_ipNext, Add a user.
adduser deployFurther, Add the user to the SUDOERS list with
.visudo# User privilege specification root ALL=(ALL) ALL deploy ALL=(ALL) ALLChange the default SSH port and disallow root access.
vim /etc/ssh/sshd_config# What ports, IPs and protocols we listen for Port 16888 ... PermitRootLogin noLog 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:
and log out again."ssh deploy@your_ip -p 16888"Create your authorized keys file:
mkdir ~/.ssh touch ~/.ssh/authorized_keys chmod 600 ~/.ssh/authorized_keysNow 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
on the remote server. By this way you can turn it into a script and use this to add multiple keys.authorized_keysLog 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 mysqlNow log into MySQL with
and create a user.mysql -u root -pcreate 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-moduleFollow the instructions.
CD to
and add a file called “passenger.conf” which has the below contents:/etc/apache2/conf.dLoadModule 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.comPut this code in the file:
ServerName demo.napcs.com DocumentRoot /var/www/demo.napcs.com/current/public
AllowOverride all
Options -MultiViewsThen enable the site.
sudo a2ensite demo.napcs.com sudo /etc/init.d/apache2 restartAnd give the
user permissions to thedeployroot folder:/var/wwwsudo chown -R deploy:deploy /var/wwwAgain, 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.htmlAdd a root route to
config/routes.rbroot :to => "projects#index"Add the
gem to your Gemfile and get the sqlite3 one only in dev mode. Specify the version numbers for the gems.mysql2group :development do gem 'sqlite3', '1.3.3' end group :production do gem 'mysql2', '0.2.7' endThen
.bundle[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.