Content

Bitnami Ruby on Rails for Open Telekom 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> CREATE DATABASE IF NOT EXISTS DBNAME_production;
mysql> CREATE DATABASE IF NOT EXISTS DBNAME_development;
mysql> CREATE DATABASE IF NOT EXISTS DBNAME_test;
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';
mysql> FLUSH PRIVILEGES;

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:

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

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:

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/.