Since we setup Ubuntu for our development environment, we also want to use it in production. This keeps your application running consistently between development and production.
The first step is to install some dependencies for Ruby:
Next we’re going to be installing Ruby using rvm:
1 2 3 4 5 6 7
The last step is to install Bundler
Phusion is the company that develops Passenger and they recently put out an official Ubuntu package that ships with Nginx and Passenger pre-installed.
We’ll be using that to setup our production server because it’s very easy to setup:
1 2 3 4 5 6 7 8 9
So now we have Nginx and passenger installed. We can manage the Nginx webserver by using the service command:
The service command also provides some other methods such as
stop that allow you to easily restart and stop your webserver.
Next, we need to update the Nginx configuration to point Passenger to the version of Ruby that we’re using. You’ll want to open up
/etc/nginx/nginx.conf in your favorite editor. I like to use vim, so I’d run this command:
Find the following lines, and uncomment them:
1 2 3 4 5 6 7
Once you’ve configured
/etc/nginx/nginx.conf , you can run
sudo service nginx restart to restart Nginx with the new Passenger configuration.
Install MySQL and PostgreSQL
Setting up your production database is pretty easy. Make sure to keep in mind that you should use a different password for your production databases.
Depending on what database you want to use, follow the steps related to the database:
All you need to do in order to install MySQL is to run the following command:
You can use the root user and password set during installation for your database or you can add a new user to MySQL.
We can install PostgreSQL like so:
Next we need to setup the postgres user:
1 2 3
The password you type in here will be the one to put in your
my_app/current/config/database.yml later when you deploy your app for the first time.
Adding The Nginx Host
In order to get Nginx to respond with the Rails app, we need to modify it’s sites-enabled.
/etc/nginx/sites-enabled/default in your text editor and we will replace the file’s contents with the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
This is our Nginx configuration for a server listening on port 80. You need to change the server_name values to match the domain you want to use and in root replace “myapp” with the name of your application.
Connect The Database
config/database.yml needs to be updated for the production database server username, password, and host. You can set host to “localhost” and you will have to create a database on the server with the same name by using command:
Setup Secret Key Base
Go to your rails app directory and run command below to generate secret key base:
/yourapp/config/secrets.yml and set production secret_key_base. Then reload Nginx using command line:
sudo service nginx reload
So far so good, That’s it!!! See ya!!! :)