Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Fresh Ubuntu 13.10/Ruby/Rails/Nginx/Passenger Install

linux ubuntu ruby rails nginx passenger

  • Please log in to reply
2 replies to this topic

#1 xExekut3x

xExekut3x

    Passenger

  • Members
  • 5 posts

Posted 16 November 2013 - 02:39 AM

Well, I was going to post, but this editor is whack.. soon to come, I guess.

#2 xExekut3x

xExekut3x

    Passenger

  • Members
  • 5 posts

Posted 16 November 2013 - 03:21 AM

$ADMIN = your rails user
$RUBYPATH = your path to ruby
$PASSPATH = your path to passenger
  • Intsall Ubuntu 13.10. Basic install with just an SSH server.
  • Configure /etc/network/interfaces && /etc/hosts && /etc/hostname

  • sudo /etc/init.d/networking restart
    sudo /etc/init.d/hostname restart
    sudo sh -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main' > /etc/apt/sources.list.d/pgdg.list"
    wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
    sudo apt-get update
    sudo apt-get upgrade -y
    sudo reboot

  • sudo apt-get install -y ntp ntpdate nodejs sshguard curl libcurl4-openssl-dev python-pip python-dev git subversion gawk libreadline6-dev libyaml-dev \
    libsqlite3-dev sqlite3 autoconf libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
    sudo apt-get install -y postgresql-common -t saucy
    sudo apt-get install -y postgresql-9.2 libpq-dev
    \curl -L https://get.rvm.io | bash -s stable
    sudo reboot

  • source ~/.rvm/scripts/rvm
    rvm get stable
    rvm requirements
    rvm install 2.0.0-p247
    rvm use 2.0.0-p247 --default
    rvm rubygems current
    echo "gem: --no-ri --no-rdoc" > ~/.gemrc
    gem install rails passenger bundler
    chmod o+x /home/${ADMIN}/.rvm/gems/${RUBYPTH}/gems/${PASSPTH}
    chmod o+x /home/${ADMIN}/.rvm/gems/${RUBYPTH}/gems
    chmod o+x /home/${ADMIN}/.rvm/gems/${RUBYPTH}
    chmod o+x /home/${ADMIN}/.rvm/gems
    chmod o+x /home/${ADMIN}/.rvm
    chmod o+x /home/${ADMIN}
    rvm get head
    export rvmsudo_secure_path=1
    rvmsudo passenger-install-nginx-module
    wget -O init-deb.sh http://library.linode.com/assets/660-init-deb.sh
    sudo reboot

  • 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
  • Configure /opt/nginx/conf/nginx.conf

  • sudo /etc/init.d/nginx start

  • rails new *project name*
    cd *project name*
  • # Configure /path/to/Gemfile

  • bundle install
Almost got it the way I wanted with the editor. New here and it's quite confusing, plus I've had a few to drink. But this is basically what I use to get a Ruby on Rails server up and running with Nginx and Passenger on Ubuntu 13.04. It appears to have worked on 13.10 except running "rails server" doesn't work... maybe I missed something. If you have any corrections or additions, please let me know.

#3 xExekut3x

xExekut3x

    Passenger

  • Members
  • 5 posts

Posted 18 November 2013 - 07:22 PM

Got the script working now. It will get a functioning rails app server up in no time.
 

#!/bin/bash
# Will be prompted twice - for Java and PostgreSQL user password
RAILSUSER=${USER}
SQLADMIN=${RAILSUSER}
SQLPASS='sqlpassword'
# GitHub Info
USERNAME='First Last'
USEREMAIL='urgitemail@example.com'
GITPASS='gitpassword'
BACKUPS='/home/'${RAILSUSER}'/file-backups/'
RAILSAPP='AppName'
CPUCORES='1'
DOMAIN='example.com'
HOSTNAME='srv1'
FQDN=${HOSTNAME}'.'${DOMAIN}
NGINXPTH='/opt/nginx/'
RUBYVERSION='2.0.0-p247'
PASSVERSION='4.0.24'
# Public Key Info
KEY=${FQDN} #Key name
COUNTRY='US'
STATE='Alaska?'
CITY='Somewhere'
ORG='Organization'
NAME=${FQDN} #Common Name
EMAIL=${USEREMAIL}
ADDRESS='10.0.0.2'
NETMASK='255.255.255.224'
NETWORK='10.0.0.0'
BROADCAST='10.0.0.31'
GATEWAY='10.0.0.1'
DNSSRV='8.8.8.8 8.8.4.4'
HOST=${ADDRESS}' '${FQDN}' '${HOSTNAME}
#------------------------------------------------------
cd ~/
clear
sudo mkdir -p ${BACKUPS}
sudo cp /etc/network/interfaces ${BACKUPS}interfaces.orig
sudo chattr +i ${BACKUPS}interfaces.orig
sudo tee /etc/network/interfaces > /dev/null << EOF
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address ${ADDRESS}
netmask ${NETMASK}
network ${NETWORK}
broadcast ${BROADCAST}
gateway ${GATEWAY}
dns-nameservers ${DNSSRV}
EOF
sudo service networking restart
sudo cp /etc/hosts ${BACKUPS}hosts.orig
sudo chattr +i ${BACKUPS}hosts.orig
sudo tee /etc/hosts > /dev/null << EOF
127.0.0.1 localhost.localdomain localhost
${HOST}
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
EOF
sudo sh -c "echo ${FQDN} > /etc/hostname"
sudo service hostname restart
sudo apt-get install -y -qq software-properties-common
sudo add-apt-repository -y ppa:chris-lea/node.js
sudo add-apt-repository -y ppa:git-core/ppa
sudo add-apt-repository -y ppa:webupd8team/java
sudo sh -c "echo deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main > /etc/apt/sources.list.d/pgdg.list"
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update -qq
sudo apt-get upgrade -y -qq
sudo apt-get install -y -qq ntp ntpdate unzip curl libcurl4-openssl-dev nodejs postgresql-9.3 libpq-dev git-core
sudo apt-get install -y -qq oracle-java7-installer
sudo apt-get install -y -qq oracle-java7-set-default
\curl -L get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
echo "source ~/.rvm/scripts/rvm" >> ~/.bashrc
rvm requirements
rvm install ${RUBYVERSION}
rvm use ${RUBYVERSION} --default
rvm rubygems current
echo "gem: --no-ri --no-rdoc" > ~/.gemrc
gem install rails
gem install passenger
gem install bundler
chmod o+x /home/${RAILSUSER}/.rvm/gems/ruby-${RUBYVERSION}/gems/passenger-${PASSVERSION}
chmod o+x /home/${RAILSUSER}/.rvm/gems/ruby-${RUBYVERSION}/gems
chmod o+x /home/${RAILSUSER}/.rvm/gems/ruby-${RUBYVERSION}
chmod o+x /home/${RAILSUSER}/.rvm/gems
chmod o+x /home/${RAILSUSER}/.rvm
chmod o+x /home/${RAILSUSER}
rvm get head
export rvmsudo_secure_path=1
rvmsudo passenger-install-nginx-module --auto --prefix=${NGINXPTH} --auto-download
sudo wget -O /etc/init.d/nginx http://library.linode.com/assets/660-init-deb.sh
sudo chmod +x /etc/init.d/nginx
sudo /usr/sbin/update-rc.d -f nginx defaults
sudo cp ${NGINXPTH}conf/nginx.conf ${BACKUPS}nginx.conf.orig
sudo chattr +i ${BACKUPS}nginx.conf.orig
sudo tee ${NGINXPTH}conf/nginx.conf > /dev/null << EOF
worker_processes ${CPUCORES};
events {
worker_connections 1024;
}
http {
passenger_root /home/${RAILSUSER}/.rvm/gems/ruby-${RUBYVERSION}/gems/passenger-${PASSVERSION};
passenger_ruby /home/${RAILSUSER}/.rvm/wrappers/ruby-${RUBYVERSION}/ruby;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name _;
root /home/${RAILSUSER}/${RAILSAPP}/public;
passenger_enabled on;
}
server {
listen 443;
server_name _;
root /home/${RAILSUSER}/${RAILSAPP}/public;
passenger_enabled on;
ssl on;
ssl_certificate /etc/ssl/nginx/${FQDN}.crt;
ssl_certificate_key /etc/ssl/nginx/${FQDN}.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_set_header X-Forwarded-Proto https;
}
}
}
EOF
sudo mkdir -p /etc/ssl/nginx
sudo openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=${COUNTRY}/ST=${STATE}/L=${CITY}/O=${ORG}/CN=${NAME}/emailAddress=${EMAIL}" -out /etc/ssl/nginx/${KEY}.crt -keyout /etc/ssl/nginx/${KEY}.key
sudo chmod 600 /etc/ssl/nginx/${KEY}.key
sudo service nginx start
rails new ${RAILSAPP} -d postgresql
cd ${RAILSAPP}
cat << 'EOF' > Gemfile
source 'https://rubygems.org'
gem 'rails', '~> 4.0.1'
#gem 'sqlite3'
gem 'pg'
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '~> 2.3.1'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'
gem 'scrypt', '~> 1.2.0'
gem 'yui-compressor', '~> 0.12.0'
gem 'twitter', '~> 4.8.1'
gem 'bootstrap-sass', '~> 3.0.2.0'
gem 'font-awesome-rails'
gem 'rails-backbone'
gem 'google-code-prettify-rails', '~> 1.1.0'
group :doc do
gem 'sdoc', require: false
end
EOF
tee config/database.yml > /dev/null << EOF
development:
adapter: postgresql
encoding: unicode
database: ${RAILSAPP}_development
pool: 5
timeout: 5000
username: ${SQLADMIN}
password: ${SQLPASS}

test:
adapter: postgresql
encoding: unicode
database: ${RAILSAPP}_test
pool: 5
timeout: 5000
username: ${SQLADMIN}
password: ${SQLPASS}

production:
adapter: postgresql
encoding: unicode
database: ${RAILSAPP}_production
pool: 5
username: ${SQLADMIN}
password: ${SQLPASS}
EOF
sudo -u postgres createuser -dEsP --replication ${SQLADMIN}
bundle install
rails g backbone:install
rails generate controller home index
rake db:create:all
rake db:migrate
tee app/assets/javascripts/application.js > /dev/null << EOF
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require underscore
//= require backbone
//= require backbone_rails_sync
//= require backbone_datalink
//= require backbone/web_app
//= require bootstrap
//= require_tree .
EOF
tee app/assets/stylesheets/application.css > /dev/null << EOF
/*
*= require_self
*= require_tree .
*/
@import "font-awesome";
@import "bootstrap";
@import "bootstrap/theme";
EOF
mv app/assets/stylesheets/application.css app/assets/stylesheets/application.css.scss
tee config/routes.rb > /dev/null << EOF
WebApp::Application.routes.draw do
get "home/index"
root 'home#index'
end
EOF
git config --global color.ui true
git config --global user.name ${USERNAME}
git config --global user.email ${USEREMAIL}
ssh-keygen -f ~/.ssh/id_rsa -t rsa -N ${GITPASS} -C ${USEREMAIL} -q
sudo reboot

Then run this, if you want.

#!/bin/bash
cd ~/
clear
rvmsudo passenger-memory-stats
java -version
echo 'Copy the key below into GitHub.'
echo 'Run> ssh -T git@github.com'
cat ~/.ssh/id_rsa.pub






Also tagged with one or more of these keywords: linux, ubuntu, ruby, rails, nginx, passenger

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users