Last active
February 15, 2018 12:34
-
-
Save breim/a731fda8bf70b6003cef to your computer and use it in GitHub Desktop.
Deploy rails 4 with postgresql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### ssh to root in terminal with your server ip | |
| ssh root@123.123.123.123 | |
| ### Create new user | |
| adduser deploy | |
| ### Set new users privileges | |
| visudo | |
| ### Find user privileges section | |
| # User privilege specification | |
| root ALL=(ALL:ALL) ALL | |
| ### Add your new user privileges under root & cntrl+x then y to save | |
| deploy ALL=(ALL:ALL) ALL | |
| ### Configure SSH | |
| nano /etc/ssh/sshd_config | |
| ### Find and change port to one that isn't default(22 is default: choose between 1025..65536) | |
| Port 22 # change this to whatever port you wish to use | |
| Protocol 2 | |
| PermitRootLogin no | |
| ### Add to bottom of sshd_config file after changing port (cntrl+x then y to save) | |
| UseDNS no | |
| AllowUsers deploy | |
| ### Reload ssh | |
| service ssh restart | |
| # se der erro reinicia a maquina ... sudo reboot now | |
| ### Don't close root! Open new shell and ssh to vps with new username(remember the port, or you're locked out!) | |
| ssh deploy@123.123.123.123 | |
| ### Update packages on virtual server | |
| sudo apt-get update | |
| # General dependencies | |
| sudo apt-get install htop curl git git-svn gitk ssh libssh-dev nodejs imagemagick libmagickwand-dev libav-tools redis-server libhiredis-dev -y | |
| ### install latest stable version of rvm | |
| command curl -sSL https://rvm.io/mpapis.asc | gpg --import - | |
| curl -L https://get.rvm.io | bash -s stable | |
| source ~/.rvm/scripts/rvm | |
| rvm requirements | |
| rvm install 2.2.4 | |
| gem install rails | |
| ### Install PG, mysql is for newbies | |
| sudo apt-get install postgresql postgresql-contrib postgresql-server-dev-9.5 | |
| ### Como estamos falando de uma máquina de desenvolvimento, vamos criar um superuser: | |
| sudo su postgres | |
| createuser -P -s -e deploy | |
| ### Você deve editar o arquivo pg_hba.conf com sudo nano /etc/postgresql/9.5/main/pg_hba.conf e faça o final dele estar assim: | |
| # Database administrative login by Unix domain socket | |
| local all postgres trust | |
| # TYPE DATABASE USER ADDRESS METHOD | |
| # "local" is for Unix domain socket connections only | |
| local all all trust | |
| # IPv4 local connections: | |
| host all all 127.0.0.1/32 trust | |
| # IPv6 local connections: | |
| host all all ::1/128 trust | |
| # Allow replication connections from localhost, by a user with the | |
| # replication privilege. | |
| #local replication postgres peer | |
| #host replication postgres 127.0.0.1/32 md5 | |
| #host replication postgres ::1/128 md5 | |
| ### Install git | |
| sudo apt-get install git git-svn gitk ssh libssh-dev | |
| ### Install passenger | |
| sudo apt-get install libcurl4-openssl-dev | |
| gem install passenger | |
| sudo chown -R `whoami` /opt | |
| ### IMPORTANT, if your droplet have <= 1024mb ram you need swap memory, its get local HDD and add to ram. | |
| ### Passenger need more 1024 to install, this trick solve it on smallest droplets. | |
| # Allocate memory 1024mb | |
| sudo dd if=/dev/zero of=/swap bs=1M count=1024 | |
| sudo mkswap /swap | |
| sudo swapon /swap | |
| #### Install passenger | |
| passenger-install-nginx-module --auto-download --auto | |
| # Unallocate memory | |
| sudo swapoff /swap | |
| ### Nginx conf | |
| sudo nano /opt/nginx/conf/nginx.conf | |
| ### Add woner to repo | |
| sudo chown -R deploy /opt | |
| ### Fazer nginx iniciar sozinho quando restartar a maquina | |
| 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 | |
| ### Comands to nginx | |
| sudo service nginx start | |
| sudo service nginx stop | |
| sudo service nginx restart | |
| # Usefull commands | |
| sudo nano /opt/nginx/conf/nginx.conf | |
| passenger-config restart-app | |
| # Limpa os assets | |
| RAILS_ENV=production rake assets:precompile | |
| rake assets:clobber | |
| rake assets:clean |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment