3 m read

Deploying Ruby on Rails Applications

Preparation for Deployment

Begin the process of deploying ruby applications by ensuring that “passenger” is in your app’s Gemfile. This step is crucial as Passenger serves as your app’s server in production.

You also need to make sure that your Ruby app has access to a database. This tutorial uses SQLite for demonstration purposes, but you can opt for your preferred database type.

Removing Unnecessary Gems

Some gems might be unsuitable or unnecessary when deploying Ruby apps. Gems like “unicorn” or “thin” may require removal from your Gemfile.

Setting User Accounts

For security purposes, it’s advisable to run each app under its own user account. Make sure that the user account also has your SSH key installed.

Storing the App’s Code

When it comes to storing your application’s code, it’s essential to select a suitable location. A recommended option would be /var/www/myapp/code.

Setting the Secret Key

From Rails 4 onwards, the secret key is stored in config/secrets.yml. Obtain the secret key with the command $bundle exec rake secret.

Running the Passenger

Passengers can start your app in a production environment. Set the passenger to run on port 80, which is the standard HTTP port.

Compiling Assets

Get Passenger to compile assets for the Ruby asset pipeline. If you encounter issues viewing your app’s HTML, this could be due to the DNS not being set up properly. In such instances, use your server’s IP address as the server name.

Using Git to Transfer

When it comes to transferring your application’s code to the server, leveraging a Git repository can streamline the process. Simply create a repository and push your app’s code there. This approach not only facilitates easy transfer but also provides version control benefits.

Run the Bundle

Next, run bundle install –deployment –without development test -j 2 in your app’s directory to ensure all necessary gems are installed. Note that different apps may depend on different services such as Postgres or Redis.

Switching Back to Admin Account

After logging into your app’s user account to set up the environment, switch back to the admin account for full privileges.

Server Starting Procedures

Ensure that Passenger Standalone begins on system boot. This is crucial for automatic app activation when the system restarts. If issues persist in viewing your app’s HTML, it most likely is a DNS settings issue. If faced with this issue, use your server’s IP address as the server name.

Replacing Ruby Version

Replace ‘2.3.3’ with the Ruby version you want your app to run under. This flexibility allows you to control the Ruby environment according to your app’s requirements.

Getting Familiar with Passenger

It’s beneficial to understand what Phusion Passenger does and how it operates. This 5-minute tutorial can guide you to start your application in a Passenger server, in development mode. This prior experience can ease your deployment process later.

Combining Passenger with Other Servers

You might want to deploy your app to production with Passenger, possibly in combination with Nginx or Apache. This guide demonstrates how to set up a Ruby on Rails 6 environment, create a simple view, and deploy it to Render.

Integrating Postgres Database

The application can be configured to use a Render Postgres database. This is advantageous as Postgres offers a robust and reliable database system for app deployment.

Initial Rails Setup

You will first need to create a new Ruby on Rails application. This can be achieved with a series of commands that generate a new project. You will also need to create a new Ruby controller using command-line generator functions.

Conclusion

In conclusion, deploying ruby applications involves several stages starting from preparation, running the passenger, and getting familiar with the passenger.

It requires accurate configurations, proper understanding, and synchronization with other tools like databases and servers. More details from the previous article can be found here.

Benji

Leave a Reply