Table of contents
In this guide you can find how to add your own Ruby on Rails application on top of the Ruby stack or any Virtual Machine or AMI.
How to create the basic application structure?
All Ruby application are configured in a similar way in Bitnami. The following folders are into your installation directory or in "/opt/bitnami" if you are using the Virtual Machines or AMIs.
This is the basic folder structure:
- apps/ This is the folder where are all the Ruby applications (for example: apps/redmine, apps/discourse, etc). In this guide we will use "myapp" name for the folder.
- apps/myapp |- htdocs |- conf |- data (optional)
On Windows: You can create the folders manually
On OS X: On Linux: You can run the following commands:
$ mkdir /installdir/apps/myapp $ mkdir /installdir/apps/myapp/htdocs $ mkdir /installdir/apps/myapp/conf
- apps/myapp/htdocs In this folder you can find the Ruby application files. This is where you should copy the application files or your Ruby files.
On Linux: You can uncompress the application code into this folder. You can find below two examples for uncompressing a ".zip" file or a ".tar.gz" file, or clone for a git repository:
$ tar -xzvf myapp.tar.gz -C /installdir/apps/myapp/htdocs $ unzip myapp.zip -d /installdir/apps/myapp/htdocs $ cd /installdir/apps/myapp/htdocs $ git clone https://your_repository.git
- apps/myapp/conf/httpd-prefix.conf This is the Apache configuration file to configure your application at "http://example.com/myapp".
Alias /myapp/ "/installdir/apps/myapp/htdocs/public" Alias /myapp "/installdir/apps/myapp/htdocs/public" Include "/installdir/apps/myapp/conf/httpd-app.conf"
- apps/myapp/conf/httpd-app.conf. This is the main configuration file for your application. The content could be different depending on your application.
<Directory /installdir/apps/myapp/htdocs/public> Options +FollowSymLinks AllowOverride None <IfVersion < 2.3 > Order allow,deny Allow from all </IfVersion> <IfVersion >= 2.3> Require all granted </IfVersion> PassengerEnabled on SetEnv RAILS_RELATIVE_URL_ROOT "/myapp" PassengerAppRoot "/installdir/apps/myapp/htdocs" </Directory>
(If you are using the Virtual Machine or the AMI, remember that "installdir" is /opt/bitnami).
Once you have these files, you should add the following line at the bottom of the Apache configuration file "/installdir/apache2/conf/bitnami/bitnami-apps-prefix.conf".
... Include "/installdir/apps/myapp/conf/httpd-prefix.conf"
Then, restart the Apache server and you can access your application at http://example.com/myapp
sudo /installdir/ctlscript.sh restart apache
How to configure your application to be deployed in the root URL?
Bitnami applications ships "httpd-vhosts.conf" file that uses VirtualHost configuration instead of a sub-URI. You can create this file and configure your application to work in the root URL.
- apps/myapp/conf/httpd-vhosts.conf. Note you should use the server domain name.
<VirtualHost *:80> ServerName example.com DocumentRoot "/installdir/apps/myapp/htdocs/public" Include "/installdir/apps/myapp/conf/httpd-app.conf" </VirtualHost> <VirtualHost *:443> ServerName example.com DocumentRoot "/installdir/apps/myapp/htdocs/public" SSLEngine on SSLCertificateFile "/installdir/apps/myapp/conf/certs/server.crt" SSLCertificateKeyFile "/installdir/apps/myapp/conf/certs/server.key" Include "/installdir/apps/myapp/conf/httpd-app.conf" </VirtualHost>
To enable this configuration you should disable the previous "prefix" configuration and enable the "vhost" one:
... #Include "/installdir/apps/myapp/conf/httpd-prefix.conf"
... Include "/installdir/apps/myapp/conf/httpd-vhosts.conf"
Change the default configuration to deploy your application in the root URL. The "/opt/bitnami/apps/myapp/conf/httpd-app.conf" file should be similar to this:
<Directory /installdir/apps/myapp/htdocs/public> Options +FollowSymLinks AllowOverride None <IfVersion < 2.3 > Order allow,deny Allow from all </IfVersion> <IfVersion >= 2.3> Require all granted </IfVersion> PassengerEnabled on #SetEnv RAILS_RELATIVE_URL_ROOT "/myapp" PassengerAppRoot "/installdir/apps/myapp/htdocs" </Directory>
Note that Passenger configuration uses "RAILS_ENV=production" by default. If you want to deploy it using the "development" mode you can add the following to the "httpd-app.conf" file:
... PassengerEnabled on SetEnv RAILS_ENV "development" ...
Then restart the Apache server.
/installdir/ctlscript.sh restart apache
It is possible that your application requires to compile the assets before deploying it. The default command to create them is the following:
$ cd /installdir/apps/myapp/htdocs $ rake assets:precompile
If are using a virtual machine or cloud image, or in the case that you installed as root a native installer for Mac OS X or Linux, you need to give read permissions to the the apache user or group. In these installations apache is running as the daemon user.
sudo chgrp daemon /opt/bitnami/apps/myapp/htdocs/tmp /opt/bitnami/apps/myapp/htdocs/logs
|NOTE: This guide uses "/opt/bitnami" to refer to the installation directory. This is the default installation directory for Virtual Machines and Cloud Images. If you have installed your Bitnami stack in a different folder, replace "/opt/bitnami" with your installation directory in the examples. |