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/app_name.com
Add these lines.
<VirtualHost *:80> ServerName app_name.com DocumentRoot /home/your_name/sites/app_name/public #SET YOUR ENVIRONMENT HERE 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 </Directory> </VirtualHost>
2. Create symlinks with this command
$ sudo a2ensite app_name.com
3. Add production secret_key_base value in "app_root/config/secret.yml".
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.