Nginx – Unicorn setup for rails appliaction

————install nginx————
sudo apt-get install nginx
————start start————-
sudo service nginx start

others commands:
sudo service nginx restart
sudo service nginx stop

————install unicorn————
* add unicorn to your gem file

gem ‘unicorn’
bundle

————-setup unicorn————-

**1 add file to your application in config/unicorn.rb

cmd: vim config/unicorn.rb

**2 copy the folling template to the same file
https://github.com/defunkt/unicorn/blob/master/examples/unicorn.conf.rb

**3 edit the following changes to the same file
*1 working_directory – change the working directory to your application from root path
eg: working_directory “/home/vagrant/code/application”

*2 listen – change the listen socket to your application socket
eg: listen “/tmp/unicorn.application_name.sock”, :backlog => 64

*3 listen port – change the listening port to the port which you have open eg 8080
eg: listen 8080, :tcp_nopush => true

*4 pid – change the pid to your application pid
eg: pid “/home/vagrant/code/application_name/tmp/pids/unicorn.pid”

*5 stderr_path, stdout_path – change the log files
stderr_path “/home/vagrant/code/application_name/log/unicorn.log”
stdout_path “/home/vagrant/code/application_name/log/unicorn.log”

—————setup nginx—————–
note: change the application name to your app name

**1 open the nginx config file in vim
cmd: sudo vim /etc/nginx/sites-available/default

**2 add the following code to the file above server

upstream billing{
server unix:/tmp/unicorn.application_name.sock fail_timeout=0;
}
**3

vagrant – chef

————-vagrant 1.6.5———————
wget https://dl.bintray.com/mitchellh/vagrant/vagrant_1.6.5_x86_64.deb
sudo dpkg -i vagrant_1.6.5_x86_64.deb

—————vagrant tutorial—————
https://docs.vagrantup.com

http://www.vagrantbox.es/
—————-chef solo———————–
wget https://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/12.04/x86_64/chefdk_0.3.4-1_amd64.deb
sudo dpkg -i chefdk_0.3.4-1_amd64.deb

make your cookbooks under

chef-repo/cookbooks/

—————chef tutorial——————
https://www.getchef.com/download-chef-client/
http://learn.getchef.com/ubuntu/make-your-recipe-more-manageable/

http://leopard.in.ua/2013/02/17/chef-server-getting-started-part-1/

————–chef market———————
https://supermarket.getchef.com/cookbooks?utf8=%E2%9C%93&q=mysql

Vagrant

Vagrant

Vagrant is a tool for building and distributing development environments.

Development environments managed by Vagrant can run on local virtualized platforms such as VirtualBox or VMware, in the cloud via AWS or OpenStack, or in containers such as with Docker or raw LXC.

Vagrant provides the framework and configuration format to create and manage complete portable development environments. These development environments can live on your computer or in the cloud, and are portable between Windows, Mac OS X, and Linux.

http://railscasts.com/episodes/292-virtual-machines-with-vagrant?autoplay=true

—————————————

Setup

sudo apt-get install virtualbox

sudo apt-get install vagrant

vagrant init

————-

goto vagrant file name change

config.vm.box = “stockvm”

—————-

vagrant up

vagrant ssh

Your done with the vagrant creation.

MySQL and PostgreSQL Database Setup

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:

Installing MySQL

All you need to do in order to install MySQL is to run the following command:

sudo apt-get install mysql-server mysql-client libmysqlclient-dev

You can use the root user and password set during installation for your database or you can add a new user to MySQL.

Installing PostgreSQL

Postgres 9.3 is available in the Ubuntu repositories and we can install it like so:

sudo apt-get install postgresql postgresql-contrib libpq-dev

Next we need to setup our postgres user:

sudo su - postgres
createuser --pwprompt
exit

The password you type in here will be the one to put in your my_app/current/config/database.ymllater when you deploy your app for the first time.