Skip to content

Instantly share code, notes, and snippets.

@ppworks
Created February 26, 2012 13:11
Show Gist options
  • Save ppworks/1916622 to your computer and use it in GitHub Desktop.
Save ppworks/1916622 to your computer and use it in GitHub Desktop.
install_rails_application_on_ubuntu

vim

sudo aptitude install vim-nox

sshd

sudo vim /etc/ssh/sshd_config
Port 2222
PermitRootLogin no
PasswordAuthentication no

に変更する

sudo /etc/init.d/ssh restart

locale

sudo aptitude install locale
sudo aptitude install language-pack-ja-base

nginx

sudo aptitude install python-software-properties pkg-config
sudo add-apt-repository "deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main"
sudo aptitude update
sudo aptitude install nginx

sudo cp /etc/nginx/nginx.conf .

sudo mkdir /tmp/nginx 
sudo chown www-data /tmp/nginx

mysql5.1

sudo aptitude install mysql-server-5.1 libmysqld-dev
sudo vim /etc/mysql/my.cnf
[client]
default-character-set   = utf8

[mysqld]
skip-name-resolve
default-character-set   = utf8
log-bin=/var/log/mysql/mysql-slow.log
log-bin-index=bin.index
log_slow_queries        = /var/log/mysql/mysql-slow.log
long-query-time=1
log-queries-not-using-indexes
log-slow-admin-statements

[mysqldump]
default-character-set   = utf8

[mysql]
default-character-set   = utf8

rvm

サービス動かしたいユーザーでやると良いです。www-dataとか?


sudo aptitude install build-essential bison openssl\
libreadline6 libreadline6-dev curl git-core zlib1g\
zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 \
libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev

sudo bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
echo 'source /usr/local/lib/rvm' >> ~/.zshrc # if you use bash, write into ".bashrc".
rvmsudo rvm install ruby-1.8.7-head
rvm use ruby-1.8.7-head --default
rvm gemset create your_service
rvm gemset list_all
rvm use 1.8.7-head@your_service
rvm current # 確認
sudo vim /etc/rvmrc
export rvm_trust_rvmrcs_flag=1

を追加

bundler

さきほど作ったrvm gemsetをuseした状態でbundlerは最低限入れておく。


gem install bundler —no-ri —no-rdoc

nginx

unicornは後述のようにcapistranoで起動させます。
nginxで、動かすサービスのforward proxyの設定をします。
以下は一例。


upstream your-service-backend {
server localhost:3000;
}

server {
listen 80;
server_name yourservice.example.com;

location ~ ^/(_|assets|javascripts|images|stylesheets|uploads)/(.*)$ { root /path/to/your/service/current/public; gzip_static on; # to serve pre-gzipped version; expires max; add_header Cache-Control public; access_log off; } proxy_buffer_size 64k; proxy_buffers 16 64k; location / { proxy_pass http://your-service-backend; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }

}


local

capistranoの設定は以下が参考になります。

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