Using Databases with Ruby on Rails
To use a PostgreSQL database with your Rails project:
- 1
Create a new PostgreSQL database and make a note of the following:
- The database name
- The database user name
- The database user password
- 2
SSH into your Rails application's shell user account and run the following commands to install the PostgreSQL dependencies for Ruby (substituting
myapp
with your Rails application name andmyproject
with your Rails project name):export APPDIR=$HOME/apps/myapp export PROJECTDIR=$APPDIR/myproject export GEM_HOME=$APPDIR/env export PATH=/usr/pgsql-11/bin/:$PROJECTDIR/bin:$GEM_HOME/bin:$PATH gem install pg
- 3
Configure your project environment's
database.yml
section as follows:production: <<: *default adapter: postgresql database: your_database_name username: your_database_user_name password: your_database_user_password
Opalstack uses MariaDB for MySQL-compatible database services. To use a MariaDB database with your Rails project:
- 1
Create a new MariaDB database and make a note of the following:
- The database name
- The database user name
- The database user password
- 2
SSH into your Rails application's shell user account and run the following commands to install the PostgreSQL dependencies for Ruby (substituting
myapp
with your Rails application name andmyproject
with your Rails project name):export APPDIR=$HOME/apps/myapp export PROJECTDIR=$APPDIR/myproject export GEM_HOME=$APPDIR/env export PATH=$PROJECTDIR/bin:$GEM_HOME/bin:$PATH gem install mysql2
- 3
Configure your project environment's
database.yml
section as follows:production: <<: *default adapter: mysql2 database: your_database_name username: your_database_user_name password: your_database_user_password
The CentOS operating system used by Opalstack includes a version of SQLite that is too old to be compatible with most current web applications. To work around this, Opalstack maintains a recent version of SQLite in the /opt
directory on web servers.
Note: Rails applications installed via our installer use an environment variable in the start
script which allows them to use the newer version of SQLite when they are running. However, when you are working with your Rails application at the command line you must configure the environment manually by setting the LD_LIBRARY_PATH
variable as shown below.
To use a SQLite database with your Rails project:
- 1
SSH into your Rails application's shell user account and configure your shell environment to recognize the updated
export LD_LIBRARY_PATH=/opt/lib
- 2
Configure your project environment's
database.yml
section as follows, substitutingdb/production.sqlite3
with the path to your SQLite database file:production: <<: *default adapter: sqlite3 database: db/production.sqlite3