Bitnami Ruby on Rails for AWS Cloud

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 application, change to the /home/bitnami directory and initialize a new project as below. Remember to replace the APPNAME placeholder with the actual name of your project.

$ cd /home/bitnami
$ rails new APPNAME

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

$ cd /home/bitnami/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.

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 /home/bitnami/httpd-vhosts.conf and fill it with the following content.

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

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

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

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

     $ sudo /opt/bitnami/ restart apache

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

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 /home/bitnami/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 /opt/bitnami/ stop apache
  • Once the Apache service has been stopped, modify the server configuration at /opt/bitnami/nginx/conf/nginx.conf to be similar to this.

     server {
         listen 80;
         root /opt/bitnami/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 /opt/bitnami/ stop apache
     $ sudo mv /opt/bitnami/apache2/scripts/ /opt/bitnami/apache2/scripts/
     $ sudo mv /opt/bitnami/config/monit/conf.d/apache.conf /opt/bitnami/config/monit/apache.conf.disabled
  • Restart the Nginx service to apply the new configuration:

     $ sudo /opt/bitnami/ 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://SERVER-IP/.


Bitnami Documentation