Skip to content

Instantly share code, notes, and snippets.

@jeanfbrito
Forked from josemarluedke/server.md
Last active September 30, 2018 18:18
Show Gist options
  • Save jeanfbrito/4031477 to your computer and use it in GitHub Desktop.
Save jeanfbrito/4031477 to your computer and use it in GitHub Desktop.
Ubuntu with Nginx + Ruby 1.9.3 + PostgreSQL 9.1 + Passenger + Papistrano

Ubuntu with Nginx + Ruby 1.9.3 + PostgreSQL 9.1 + Passenger + Papistrano

Update the system

sudo apt-get update

Install some dependencies

sudo apt-get install build-essential zlib1g-dev libssl-dev libreadline-dev libyaml-dev libcurl4-openssl-dev curl git-core python-software-properties libsqlite3-0 libsqlite3-dev sqlite3

Install the Ruby 1.9.3 from source

cd /tmp/	
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz
tar -xvzf ruby-1.9.3-p194.tar.gz
cd ruby-1.9.3-p194/
./configure
make
sudo make install
echo "gem: --no-ri --no-rdoc" >> ~/.gemrc
sudo gem install bundler

Install Vim editor

apt-get install vim

Move in the text with the arrow keys.

To start to edit press the key (I)(i).

To save and exit the file press (Esc) and write ":wq".

":" for command, "w" for write and "q" to quit.

Install the PostgreSQL 9.1

sudo apt-get install postgresql-9.1 postgresql-server-dev-9.1
gem install pg

Add an user for deploy in your postgres

sudo -u postgres createuser some_user
cd /etc/init.d/
sudo -u postgres psql template1
template1=# ALTER USER some_user WITH PASSWORD 'some_password';

To exit the postgres console, press Control + D.

Now you need edit this file: vim /etc/postgresql/9.1/main/pg_hba.conf

Where is the 'postgres' your replace by some_user, will be something like that:

# Database administrative login by Unix domain socket
local   all             some_user 			peer

And restart your postgres

sudo service postgresql restart

Install the Memcached

sudo apt-get install memcached libmemcached-dev
gem install dalli

Install the Imagemagick

sudo apt-get install imagemagick libmagickwand-dev
gem install rmagick mini_magick

Install the Phusion Passenger

gem install passenger
sudo chown -R `whoami` /opt
passenger-install-nginx-module --auto-download --auto

Create a user for deploy

sudo adduser deploy

Nginx

vim /opt/nginx/conf/nginx.conf

server {
        listen 80;
        server_name www.example.com;
        location / {
                root /home/deploy/www/application_name/current/public;
                passenger_enabled on;
                rails_env production;
        }
}

Nginx as a service

wget -O init-deb.sh http://library.linode.com/assets/660-init-deb.sh
sudo mv init-deb.sh /etc/init.d/nginx
sudo chmod +x /etc/init.d/nginx
sudo /usr/sbin/update-rc.d -f nginx defaults

Now you can do something like that:

sudo service nginx start
sudo service nginx stop
sudo service nginx restart

Capistrano

In your local app add gem 'capistrano' in your Gemfile

In your application dirictory:

bundle install
capify .

This will create the files Capfile and config/deploy.rb where settings are stored deploy, as well as tasks. Replace this files by gist:3868139 and edit with your data.

Create the database.yml for your server configuration in:

/home/deploy/database.yml

Still in your local app and run this:

cap deploy:setup

This will create the directories in your server.

Now you can make deploy of your application:

cap deploy	
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment