Skip to content

Instantly share code, notes, and snippets.

@jlucasps
Last active April 25, 2018 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlucasps/6211983 to your computer and use it in GitHub Desktop.
Save jlucasps/6211983 to your computer and use it in GitHub Desktop.
Guide to Install ruby on rails, nginx and postgres
#update ubuntu packager
sudo apt-get update
#### Dependencies
#Install following prerequisite libraries for our environment
sudo apt-get install libpcre3-dev build-essential libssl-dev libxml2 libxml2-dev libxslt-dev ncurses-dev
#Install image processing libraries, if necessary
sudo apt-get install imagemagick libmagickcore-dev libmagickwand-dev
#Install Git
sudo apt-get install git git-core
#### Ruby Version Manager
# Install RVM
curl -L get.rvm.io | bash -s stable
# After it is done installing, load RVM.
# in case of using NON-ROOT user to install
echo '[[ -s "/home/USER/.rvm/scripts/rvm" ]] && source "/home/USER/.rvm/scripts/rvm"' >> ~/.bashrc
source ~/.rvm/scripts/rvm
# in case of using ROOT user to install
echo '[[ -s "/etc/profile.d/rvm.sh" ]] && source "/etc/profile.d/rvm.sh"' >> ~/.bashrc
source /etc/profile.d/rvm.sh
# Enter the following line to terminal
type rvm | head -1 # must return: rvm is a function
# Install RVM dependencies
rvm requirements # to show dependencies
# then install listed dependencies, it may vary on each machine
sudo apt-get install gawk libreadline6-dev libyaml-dev libsqlite3-dev sqlite3 autoconf libgdbm-dev automake bison libffi-dev
# Install Ruby
rvm install 1.9.3
# We need to tell the system to use 1.9.3 by default.
rvm use 1.9.3 --default
# Install rubygems
rvm rubygems current
# Install rails
gem install rails
# Install Passenger
gem install passenger
#### Nginx
# Install missing dependencies
sudo apt-get install libcurl4-openssl-dev
# Nginx module installation is completely interactive and it will guide you when some problem happens
rvmsudo passenger-install-nginx-module
export rvmsudo_secure_path=1
# Creating swap memory
sudo dd if=/dev/zero of=/swap bs=1M count=1024
sudo mkswap /swap
sudo swapon /swap
# Configure nginx conf file:
# The Nginx configuration file (/opt/nginx/conf/nginx.conf)
http {
...
passenger_root /usr/local/rvm/gems/ruby-1.9.3-p448/gems/passenger-4.0.10;
passenger_ruby /usr/local/rvm/wrappers/ruby-1.9.3-p448/ruby;
...
}
# Creats a server block into nginx.conf file:
server {
listen 80;
server_name www.yourhost.com;
root /somewhere/public; # <--- be sure to point to 'public'!
passenger_enabled on;
}
# Download nginx startup script
wget -O init-deb.sh http://library.linode.com/assets/660-init-deb.sh
# Move to the init.d directory and make executable
sudo mv init-deb.sh /etc/init.d/nginx
sudo chmod +x /etc/init.d/nginx
# Add nginx to the system startup
sudo /usr/sbin/update-rc.d -f nginx defaults
# In case of Perl warning about locale settings:
sudo locale-gen pt_BR.UTF-8
sudo dpkg-reconfigure locales
#### Postgres
# Add repository
sudo add-apt-repository ppa:pitti/postgresql
sudo apt-get update
sudo apt-get install postgresql
sudo apt-get install libpq-dev
# if add-apt-repository not installed
sudo apt-get install python-software-properties
# Start postgres service in case of not already started:
$ sudo /etc/init.d/postgresql start
# Change postgres password:
$ sudo -u postgres psql
# Set password
ALTER USER postgres with password 'secure-password';
# login production
ubuntu@ip-10-77-70-51:/var/www/your_app$ psql -h localhost -d database_name -U postgres -W
Password for user postgres:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment