nativeInstallerredmine

Deploy a new Rails application

Before running the commands shown on this page, you should load the Bitnami stack environment by executing the installdir/use_APPNAME script (Linux and MacOS) or by clicking the shortcut in the Start Menu under “Start -> Bitnami APPNAME Stack -> Application console” (Windows). On OS X VMs, the installation directory is /opt/bitnami and OS X VM users can click the “Open Terminal” button to run commands. Learn more about the Bitnami stack environment and about OS X VMs.

There are different ways to deploy a Rails application.

Use 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>
              <IfVersion >= 2.3>
              Require all granted
              </IfVersion>
              RailsEnv development
              PassengerEnabled on
              PassengerAppRoot "installdir/APPNAME/"
          </Directory>
      </VirtualHost>
    

    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 installdir/apache2/conf/bitnami/bitnami-apps-vhosts.conf file and add the following line at the end of the file:

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

      $ sudo installdir/ctlscript.sh 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.

Use Apache with Puma

For Windows users, we recommend using Puma as a service.

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

      DocumentRoot "installdir/APPNAME/public/"
      <Directory "installdir/APPNAME/public/">
          Options -MultiViews
          allow from all
      </Directory>
      RewriteEngine On
      RewriteRule ^/(.*)$ balancer://appcluster%{REQUEST_URI} [P,QSA,L]
      <Proxy balancer://appcluster>
          BalancerMember http://127.0.0.1:3000
      </Proxy>
    

    Remember to replace the APPNAME placeholder with the correct directory for your Rails application.

  • Edit the installdir/apache2/conf/bitnami/bitnami-apps-prefix.conf file and add the following line at the end of the file:

      Include installdir/httpd-prefix.conf
    
  • To enable the required modules, edit the installdir/apache2/conf/httpd.conf file and uncomment the following lines:

      LoadModule lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so
      LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so
      LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
      LoadModule proxy_http_module modules/mod_proxy_http.so
      LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
    
  • Restart the Apache server with manager-windows.exe tool.

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

NOTE: Remember that you need to serve your application with Puma. Execute the command below in the directory of your Rails application.

    $ bundle exec puma -e production -p 3000

Use 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/ctlscript.sh 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/ctlscript.sh stop apache
      $ sudo mv installdir/apache2/scripts/ctl.sh installdir/apache2/scripts/ctl.sh.disabled
      $ 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/ctlscript.sh 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/.

Last modification April 15, 2021