Plesk and Ruby on Rails
In this article I’ll try to explain how to run Ruby on Rails applications on a server managed by Plesk. Plesk itself does not support modern Rails apps natively. But this doesn’t mean that you cannot deploy Ruby On Rails apps to Plesk hosting.
We will use an Ubuntu 14.04 server and Plesk 12.0 for our experiments. I assume that you will get this configuration somehow. It’s possible to deploy Rails apps on different OS and using different Plesk version, but all further commands will rely on Ubuntu 14.04 and Plesk 12.0 capabilities.
First of all let’s check whether Ruby is available (log in to the server via SSH, switch to root user and type):
Expected output if Ruby is installed:
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
If Ruby is not installed, you need to install it first (overview of RVM or rbenv is out of the scope of this article):
apt-get install ruby
Rails requires an application server. One of the popular options is to use Phusion Passenger. So let’s install it:
apt-get install libapache2-mod-passenger
Each application depends on a lot of gems and some of them requires compilation. To be ready for that need to install development tools:
apt-get install build-essential ruby-dev
apt-get install nodejs libsqlite3-dev
To manage app dependencies, you need to install bundler:
gem install bundler
The next step is to create a domain in Plesk for Ruby On Rails application. Let it be subdomain in our case. The document root should point to the “public” directory. Its parent will be the root directory of the application.
I recommend that you clean up newly created ror/public directory (remove a default site stub). You can do it via file manager, FTP or SSH. It’s more convenient to work via SSH under a particular user (not root), so let’s enable SSH access for the subscription:
Everything is almost ready to start the deployment of Rails application. There are several different options how to do it, but this is beyond the scope of this article. Let’s assume that app code was copied to the server somehow (via FTP or SSH). The destination directory should be “ror” in our case (not “ror/public”).
After that, you need to log in via SSH under a user (“domuser” in our case) and install app dependencies. The user can’t write to the system-wide directory where gems are located, so let’s install them to a local directory for app. Go to the app root directory (“ror” in our case) and execute:
bundle install --path vendor/bundle
Additional preparations can be app specific. A typical step is to prepare database configuration (file config/database.yml) and initialize the database:
bundle exec rake db:setup
Or, in case of production version:
RAILS_ENV=production bundle exec rake db:setup
If the app should be started in a development environment (in terms of Rails app), then you need to tell somehow about the environment to the application server. To do this, go to Websites & Domains > particular domain > Web Server Settings and define a special directive in the “Additional directives for HTTP” field – “RailsEnv development”:
If you are familiar with Rails apps development, you probably already know that the application server requires restart in some cases. For example after updating the code in a production environment, you need to restart the application server. Passenger provides a rather easy way to accomplish this task: “touch” tmp/restart.txt file inside app root directory. It’s possible to do it via file manager inside Plesk (“Change Timestamp” operation, create that file first if it is absent) or by using the following command:
The final step is to check that our application is up and running. The first request may take several seconds, but subsequent requests will be served much faster. This is due to the nature of application server, which will start apps on the first request. Open your domain in a browser and check the app.
Oh no, sorry about that!
Let us know how we can do better below
Tell us how we can improve this post?