Plesk and Ruby on Rails

Ruby On Rails and PleskIn 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):

ruby -v

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

In most cases JavaScript runtime and SQLite3 support will be required for your Rails applications. So, let’s install a few more packages:

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.

Plesk Ruby On Rails Installation - Add New Subdomain

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:

Plesk Ruby On Rails Installation - Web Hosting Access

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”:

Plesk Ruby On Rails Installation - Web Server Settings

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:

touch tmp/restart.txt

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.

Plesk Ruby On Rails Installation - Success!

9 Comments

  1. I get the Following error when try to install app dependencies “Could not locate Gemfile or .bundle/ directory”, any ideas?

  2. Hi Alexei,

    many thanks for your article, it was very helpful. Great Job!

    I’m facing a Problem if i use redirect_to in controllers or link_to in views and use relative paths like @entity or entity_path and not absolute paths like entity_url the links are broken.

    In case of an index page the url “domain/entity” is the current url for example. After clicking on one entry on this page, which should link to “domain/entity/2” a wrong url like “domain/entity/entity/2” would called and could not be found. This happens as mentoined with relative links. Locally everything works fine, but on passenger i’m facing different problems. One more problem is the asset pipeline. If i use the url helpfer instead of asset_url, then the asset couldn’t be found.

    Did you run in similar problems?

    Have you configured the mod_security web application firewall for apache?

    Many thanks

    Kai

    • Thank you. Primary goal of the article is to show that it’s possible to deploy Rails apps. It’s better to ask the questions related to Rails itself on specialised forums and/or mailing lists. http://guides.rubyonrails.org/ is a great place to start. There could be a lot of differences between local server and remote with passenger. Make sure that you’re running the app in the same “environment” (I mean “production”/”development”), make sure that there is no difference between app location (e.g. subdirectories and etc). For production environment use should precompile assets (RAILS_ENV=production bin/rake assets:precompile). But once again it’s better to ask all these questions on specialised forums.

    • Hello Kai,

      we have the same issue here. Local works and when we upload to server we got path issue.
      following the tutorial we stop on ” install app dependencies” for user. we had same result of
      Jono, “Could not locate Gemfile or .bundle/ directory”

      i supose to insert gems on app directory ?

  3. “Hi Alexei,
    You have shared very nice information about running ruby on rails web application on a server managed by plesk using ubuntu 14.04 server and Plesk 12.0. Thanks for sharing such a great content.”

  4. How to define my Ruby ​​on Rails project as a home page?

Add a Comment

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

GET LATEST NEWS AND TIPS

  • Yes, please, I agree to receiving my personal Plesk Newsletter! WebPros International GmbH and other WebPros group companies may store and process the data I provide for the purpose of delivering the newsletter according to the WebPros Privacy Policy. In order to tailor its offerings to me, Plesk may further use additional information like usage and behavior data (Profiling). I can unsubscribe from the newsletter at any time by sending an email to [email protected] or use the unsubscribe link in any of the newsletters.

  • Hidden
  • Hidden
  • Hidden
  • Hidden
  • Hidden
  • Hidden

Related Posts

Knowledge Base