Ruby on Rails configuration on a production server

Ruby on Rails, 2015-06-17 00:03:58 UTC

This tutorial is based on my experience on the Ubuntu-Apache server.

To configure it, first you must have Phusion Passenger on your machine and follow these steps;

1. Create a virtual host configuration file in "/etc/apache2/sites-available" folder

$ sudo nano /etc/apache2/sites-available/

Add these lines.

<VirtualHost *:80>
    DocumentRoot /home/your_name/sites/app_name/public

        RailsEnv production

        <Directory /home/your_name/sites/app_name/public>
                # This relaxes Apache security settings.
                AllowOverride all

                # MultiViews must be turned off.
                Options -MultiViews

                # Uncomment this if you're on Apache >= 2.4:
                #Require all granted

2. Create symlinks with this command

$ sudo a2ensite

3. Add production secret_key_base value in "app_root/config/secret.yml".


secret_key_base: 30aadec77130c9b0dbaf090682c5c9c10ac03d15f90ceeb3c16b0c3ee6f7173ca5997f950bac6a70826d14599a820e20156073515dc8b3f1d17404c6ea98885c

4. Change the database configuration in "app_root/config/database.yml".

5. If the application using devise, change devise configuration in "app_root/config/initializers/devise.rb".
The most important thing of this section is uncommented config.secred_key and configuring cofig.mail_sender into your mail

6. Configuring "app_root/config/environments/production.rb" file.

If you have checked the HTML code in the development compare to the production, you must see a lot of different especially in assets path. If you don't configure these, your UI will messed up.

Uncomment this line into the file to configuring assets in production;

config.assets.compile = true

7. Configuring assets in "app_root/config/initializers/assets.rb" file.

Add this line

Rails.application.config.assets.precompile = ['*.js', '*.css', '*.css.erb']

If you have custom assets to compile, you can add this line;

Rails.application.config.assets.precompile += %w( custom_assets.js )

8. Restart the server.

$ sudo service apache2 restart

9. Every change that you have made to your production server, just restart to make it works.