Skip to content

Instantly share code, notes, and snippets.

@Jellyfishboy
Last active November 1, 2016 14:59
Show Gist options
  • Save Jellyfishboy/5f1fa76c0998c379c6595c1f2d98b4cb to your computer and use it in GitHub Desktop.
Save Jellyfishboy/5f1fa76c0998c379c6595c1f2d98b4cb to your computer and use it in GitHub Desktop.
Nginx + Postgresql + rbenv + Rails + Redis + Memcached + Monit || Linux server setup

Update server

sudo yum update

Install system monitoring

sudo yum install htop

Install web server

sudo yum install nginx

Assign basic HTML web server config

cd /etc/nginx/sites-available

sudo vim template

server {
        listen       80;
        server_name  example.com www.example.com;
        root /home/ubuntu/examplecom;
        index index.html;

        location / {
                try_files $uri $uri/ /index.html?$args;
        }

        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
              root /usr/share/nginx/www;
        }
}

sudo ln -s /etc/nginx/sites-available/template /etc/nginx/sites-enabled/template

Install database

sudo yum install postgresql postgresql-contrib

Install Git

sudo yum git

Install memcached server

sudo yum memcached

Install Redis server

sudo yum install gcc
cd /home/ec2-user
wget -c http://download.redis.io/redis-stable.tar.gz 
tar xvzf redis-stable.tar.gz
cd redis-stable
make && make install
utils/install_server.sh (exec path /usr/local/bin/redis-server)

Install image processor

sudo yum install ImageMagick

Install monit

sudo yum install monit

Add user for deploys

sudo adduser deploy
sudo passwd deploy

Grant deploy user sudo access

sudo visudo

deploy ALL=(ALL) NOPASSWD: ALL

Temporarily allow password auth for deploy user

sudo vim /etc/ssh/sshd_config

Match User deploy
    PasswordAuthentication yes
    
sudo service sshd restart

Remove after deploy user has set up ssh key

Now Login as deploy user

Set database user password and privileges

sudo -u postgres psql

CREATE USER "deploy";

ALTER USER "deploy" WITH PASSWORD 'new_password';

ALTER USER "deploy" CREATEDB;

Create SSH key

cd ~/.ssh
mkdir .ssh
chmod -R 700 .ssh
sudo vim authorized_keys (copy the public key on your local machine into this file)

sudo service sshd restart

Install Ruby with rbenv

sudo yum install openssl-devel readline-devel zlib-deve

cd

git clone git://github.com/sstephenson/rbenv.git .rbenv

echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile

echo 'eval "$(rbenv init -)"' >> ~/.bash_profile

git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bash_profile

source ~/.bash_profile 

rbenv install -v 2.3.0

rbenv global 2.3.0

rbenv rehash

ruby -v

Set up ruby gems

echo "gem: --no-document" > ~/.gemrc

gem install bundler

gem install rails

gem install whenever

rbenv rehash

rails -v

Install nodejs and npm

sudo yum install gcc-c++
cd /home/deploy
wget http://nodejs.org/dist/v7.0.0/node-v7.0.0.tar.gz
tar xzvf node-v* && cd node-v*
./configure
make
make install
sudo ln -s /usr/local/bin/npm /usr/bin/npm
sudo ln -s /usr/local/bin/node /usr/bin/node

Install Bower

sudo npm install -g bower

bower -v

Grant nginx user access to read deploy directory

sudo gpasswd -a nginx deploy
chmod g+x /home/deploy && chmod g+x /home/deploy/apps && chmod g+x /home/deploy/apps/app_name/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment