Bitnami Ruby on Rails

NOTE: Before running the commands shown on this page, you should load the Bitnami stack environment by executing the installdir/use_APPNAME script (Linux and Mac OS X) or by clicking the shortcut in the Start Menu under "Start -> Bitnami APPNAME Stack -> Application console" (Windows). Learn more.

Rails is a popular Model-View-Controller framework for Web application development, favoring convention over configuration. It is open source and freely usable under the MIT License.

How to create a new MySQL database for a Rails application?

To create a new MySQL database for a Rails application:

  • Start the MySQL command line client, as shown below. Enter the password for the MySQL root user.

     $ mysql -u root -p
  • At the MySQL prompt, run the following commands. Remember to replace the DBNAME, APPNAME and PASSWORD placeholders with actual values for your database name, application name and database user password.

     mysql> GRANT ALL PRIVILEGES on DBNAME_test.* to 'APPNAME'@'localhost' identified by 'PASSWORD';
     mysql> GRANT ALL PRIVILEGES on DBNAME_production.* to 'APPNAME'@'localhost';
     mysql> GRANT ALL PRIVILEGES on DBNAME_development.* to 'APPNAME'@'localhost';
  • Edit the config/database.yml file in your Rails project directory and update the database configuration. You can also copy the database.yml file from a sample or fresh project and modify the database details as needed:

       adapter: jdbc
       driver: com.mysql.jdbc.Driver
       url: jdbc:mysql://localhost:3306/DBNAME_development
       username: APPNAME
       password: PASSWORD
       adapter: jdbc
       driver: com.mysql.jdbc.Driver
       url: jdbc:mysql://localhost:3306/DBNAME_test
       username: APPNAME
       password: PASSWORD
       adapter: jdbc
       driver: com.mysql.jdbc.Driver
       url: jdbc:mysql://localhost:3306/DBNAME_production
       username: APPNAME
       password: PASSWORD

How to create a new Rails application?

To create a new Rails project, load the Bitnami console, change to the installdir directory and initialize a new project as below. Remember to replace the APPNAME placeholder with the actual name of your project.

$ cd installdir
$ ./rubyconsole
$ rails new APPNAME

Next, start the Rails server by running the following command:

$ cd installdir/APPNAME
$ bundle exec rails s

This will start the Rails server for your application on port 3000. Find more information about how to access the application using your Web browser.

If you see an error on Linux stating "Could not find a JavaScript runtime", you must add the rubyracer gem (already included in the Bitnami Ruby Stack) into the Gemfile, as below:

gem 'sqlite3'
gem 'therubyracer'

How to deploy a new Rails application?

There are different ways to deploy a Rails application.

Using Apache with Passenger

The most common way to deploy a Rails application is with Apache and Passenger. Follow the steps below:

  • Create a new file at installdir/httpd-vhosts.conf and fill it with the following content.

    <VirtualHost *:80>
       ServerName HOST_NAME
       DocumentRoot "installdir/APPNAME/public/"
        <Directory "installdir/APPNAME/public/">
            Options -MultiViews
            <IfVersion < 2.3 >
            Order allow,deny
            Allow from all
            <IfVersion >= 2.3>
            Require all granted
            RailsEnv development
            PassengerEnabled on
            PassengerAppRoot "installdir/APPNAME/"

    Remember to replace the HOST_NAME placeholder with the host name of your cloud server and the APPNAME placeholter with the correct directory for your Rails application.

  • Next, edit the installdir/apache2/conf/bitnami/bitnami-apps-vhosts.conf file and add the following line to the end of the file:

     Include installdir/httpd-vhosts.conf
  • Restart the Apache server.

     $ sudo installdir/ restart apache

After restarting Apache, the application should be accessible by browsing to http://localhost.

NOTE: Remember that you might need to adjust the permissions of your application directory and sub-directories to make them accessible to the user that the Apache server runs as - for example, with the command sudo chown bitnami:daemon installdir/APPNAME.

Using Nginx with Passenger

Follow these steps:

  • To configure Nginx to run at port 80, stop the Apache service. To do this, run the command below:

     $ sudo installdir/ stop apache
  • Once the Apache service has been stopped, modify the server configuration at installdir/nginx/conf/nginx.conf to be similar to this.

     server {
         listen 80;
         root installdir/APPNAME/public;
         passenger_enabled on;
         rails_env development;
    NOTE: The configuration above runs Passenger in development mode because, by default, Passenger starts in production mode which requires a secret to be configured. Using development mode bypasses this requirement and lets you test that everything is working correctly. When deploying to production, remember to change this value and provide a secret.
  • Before restarting Nginx to apply this configuration, disable Apache as shown below:

     $ sudo installdir/ stop apache
     $ sudo mv installdir/apache2/scripts/ installdir/apache2/scripts/
     $ sudo mv installdir/config/monit/conf.d/apache.conf installdir/config/monit/apache.conf.disabled
  • Restart the Nginx service to apply the new configuration:

     $ sudo installdir/ restart nginx

With this, your Ruby on Rails application will run at the root of your domain through the default HTTP port (80). You should now be able to access your Ruby on Rails applications with Nginx and Passenger on http://localhost/.

NOTE: When running the commands shown on this page, replace the installdir placeholder with the full installation directory for your Bitnami stack.

How to create an Aptana RadRails development environment on Windows?

Follow these steps to create an Aptana RadRails development environment on Windows with the Bitnami Ruby Stack. This environment includes the Ruby, Rails, ImageMagick and other libraries and provides visual debugging.

  1. Download and install the Bitnami Ruby Stack native installer for Windows. In this example, we'll assume the Bitnami Ruby Stack is installed in the C:\rubystack directory.

  2. Download and install Aptana RadRails.

  3. Within Aptana, select the "Window -> Preferences -> Ruby -> Installed Interpreters" menu item. Click the "Add" button and enter C:\rubystack\ruby in the "RubyVM home directory" field. Click "OK" to save your changes.

[![Aptana with Ruby configuration](/images/img/components/rails/aptana-1-d1399692.png){: .img-medium}](/images/img/components/rails/aptana-1-d1399692.png)
  1. In the resulting list, select the Ruby VM you just added as the default interpreter.
[![Aptana with Ruby configuration](/images/img/components/rails/aptana-2-4675aea2.png){: .img-medium}](/images/img/components/rails/aptana-2-4675aea2.png)
  1. Within Aptana, select the "Window -> Preferences -> Ruby -> Rake" menu item. Enter C:\rubystack\ruby\bin\rake in the "rake path" field. Click "OK" to save your changes.
[![Aptana with Ruby configuration](/images/img/components/rails/aptana-3-c134bdc1.png){: .img-medium}](/images/img/components/rails/aptana-3-c134bdc1.png)
  1. Within Aptana, select the "Window -> Preferences -> Rails" menu item. Enter C:\rubystack\ruby\bin\rails in the "rails path" fields. Click "OK" to save your changes.
[![Aptana with Ruby configuration](/images/img/components/rails/aptana-4-c58abcd1.png){: .img-medium}](/images/img/components/rails/aptana-4-c58abcd1.png)
| NOTE: Remember to update the directory paths in Steps 3, 5 and 6 to reflect the correct installation directory for your system.
  1. Within Aptana, select the "Window -> Preferences -> Ruby -> Debugger" item. Select the "Use ruby-debug library" option.
[![Aptana with Ruby configuration](/images/img/components/rails/aptana-5-366b6994.png){: .img-medium}](/images/img/components/rails/aptana-5-366b6994.png)
  1. Open a new Windows command prompt (type command or cmd in the Windows Start Menu or Start screen search box). Change to the Bitnami Ruby Stack installation directory and run the following commands to install the ruby-debug-ide gem.

    use_ruby.bat gem install ruby-debug-ide

[![Aptana with Ruby configuration](/images/img/components/rails/aptana-6-69224487.png){: .img-medium}](/images/img/components/rails/aptana-6-69224487.png)
| NOTE: In case you see SSL-related errors, edit the file *C:\rubystack\ruby\lib\ruby\2.0.0\rubygems\defaults.rb* and replace all instances of the URL ** with **. Then, try installing the gem again.
  1. Open the Windows Control Panel and select the "System" icon. In the resulting "System Properties" dialog box, select the "Advanced -> Environment Variables" option. Make the following changes:
* In the "System variables" section, select the PATH variable, click "Edit..." and prepend the following paths to it:
      C:\rubystack\sqlite;C:\rubystack\subversion\bin;C:\rubystack\imagemagick;C:\rubystack\php;C:\rubystack\mysql\bin;C:\rubystack\ruby\bin;. Then, click "OK" to save your changes.

  [![Aptana with Ruby configuration](/images/img/components/rails/aptana-7-5503cb22.png){: .img-medium}](/images/img/components/rails/aptana-7-5503cb22.png)

* In the "System variables" section, click "New...*. Click "OK" to save your changes.

  [![Aptana with Ruby configuration](/images/img/components/rails/aptana-8-61065bd3.png){: .img-medium}](/images/img/components/rails/aptana-8-61065bd3.png)
  1. Restart Aptana.

You should now be able to add or start Ruby servers through Aptana, in debug mode or otherwise.