apt-get update && apt-get dist-upgrade
apt-get install open-vm-tools # VMware VMs Only
sh -c 'echo vm.swappiness=5 > /etc/sysctl.conf' # Prod Env
rebootSome of these packages may already be installed
apt-get install openssh-server mercurial make binutils bison gcc \
build-essential git-core curl zlib1g-dev openssl libssl-dev libreadline-dev \
libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev \
software-properties-common wget dnsutils vim zip unzip screen tmux htop \
libffi-dev redis-server imagemagick ntp ufw sudo dirmngr libxrender1Install postfix SMTP server (Choose internet site configuration and use the server's domain name)
apt-get install postfixEdit postfix config file
vim /etc/postfix/main.cfSet inet_interfaces to be loopback-only
inet_interfaces = loopback-only
Add the deploy user (Production Env - VPS only, otherwise this is done during install)
adduser deployAdd deploy user to sudo group
gpasswd -a deploy sudoOpen the sshd config
vim /etc/ssh/sshd_configChange from Port 22 to Port 2012 or another non-standard port
Port 2012
Disable root login
PermitRootLogin no
Restart SSH
service ssh restart
SSH w/ deploy user
ssh -p 2012 deploy@SERVER_IP_ADDRESSEnable bash color prompt
vim ~/.bashrcUncomment this line
force_color_prompt=yes
Reload w/ changes
exec $SHELLGenerate an SSH keypair used for deployments
ssh-keygen -t rsa -C "[email protected]"Copy the output of this command and paste into the deploy keys section of the github repo settings
cat ~/.ssh/id_rsa.pubCheck to make sure SSH to github works with your key
ssh -T [email protected]Create the authorized_keys file
touch ~/.ssh/authorized_keysEnable SSH
sudo ufw allow 2012/tcpEnable HTTP
sudo ufw allow 80/tcpEnable SSL/TLS
sudo ufw allow 443/tcpEnable firewall rules
sudo ufw enableSet timezone
sudo dpkg-reconfigure tzdataSSH w/ deploy user
ssh -p 2012 deploy@SERVER_IP_ADDRESSPaste your public key into the authorized_keys file (at bottom if others already exist)
vim ~/.ssh/authorized_keysExit the old SSH session and reconnect, you shouldn't need to type server password any longer
exit
ssh -p 2012 deploy@SERVER_IP_ADDRESSsudo apt-get install postgresql-9.6 libpq-devAdd postgres user and set password (use same username as your linux user)
sudo -u postgres createuser myuser -s
sudo -u postgres psql
postgres=# \password myuser
Create your app's production database on server
createdb myappname_production
Install rbenv, ruby-build and ruby 2.5.3
cd
git clone git://github.com/sstephenson/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL
rbenv install 2.5.3
rbenv global 2.5.3
ruby -vTell RubyGems to not install documentation for each gem
echo "gem: --no-ri --no-rdoc" > ~/.gemrcInstall bundler and rails
gem install bundler
gem install rails
gem install aws-sdk # optional
gem install colorize # optional
rbenv rehashInstall stable version of node
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.4/install.sh | bash
exec $SHELL
nvm install stable
nvm use stable
nvm alias default stableMake the current version of node available system-wide at /usr/local/bin/node
n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/localAdd Phusion APT repo and install nginx and passenger
See https://www.phusionpassenger.com/library/install/nginx/install/oss/stretch/ if any issues with installation.
sudo apt-get install -y dirmngr gnupg nginx
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
sudo apt-get install -y apt-transport-https ca-certificates
# Add our APT repository
sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger stretch main > /etc/apt/sources.list.d/passenger.list'
sudo apt-get update
# Install Passenger + Nginx module
sudo apt-get install -y libnginx-mod-http-passengerEdit nginx.conf
sudo vim /etc/nginx/nginx.confUncomment server_tokens_off
server_tokens off;Save and then edit /etc/nginx/conf.d/mod-http-passenger.conf and change the passenger_ruby path
##
# Phusion Passenger config
##
# Uncomment it if you installed passenger or passenger-enterprise
##
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /home/deploy/.rbenv/shims/ruby;Restart ngnix
sudo service nginx restartOpen the nginx default site config
sudo vim /etc/nginx/sites-available/defaultComment out these two lines
# listen 80 default_server;
# listen [::]:80 default_server ipv6only=on;Create an nginx conf for the app
sudo vim /etc/nginx/sites-available/myappnameAdd the following server block
server {
listen 80 default_server;
server_name www.mydomain.com;
passenger_enabled on;
root /home/deploy/myappname/current/public;
}Enable the new nginx conf
sudo ln -s /etc/nginx/sites-available/myappname /etc/nginx/sites-enabled/myappnameRestart nginx
sudo service nginx restartEdit the logrotate config
sudo vim /etc/logrotate.confAt bottom of file add the following block:
/home/deploy/myappname/current/log/*.log {
daily
missingok
rotate 7
compress
delaycompress
notifempty
copytruncate
}
Test with:
sudo /usr/sbin/logrotate -f /etc/logrotate.confThe wkhtmltopdf packge available in debian repo is version with unpatched QT. You most likely want version with patched QT, so download the precompiled binaries for Linux from https://wkhtmltopdf.org/downloads.html, extract them and cp the binaries in bin folder to /usr/bin/
At the time of writing, the latest version is 0.12.4 which has an issue fetching remote images over https, so you will need to install libssl1.0-dev
sudo apt-get install libssl1.0-devMore details here: https://agdeveloper.com/post/debian_wkhtmltopdf/
Setup Sidekiq as a systemd service so it can be started at boot
sudo apt-get install python-all-dev python-dev python3-pip\
libaio-dev libbz2-dev libjpeg62-turbo-dev libpcre3-dev libexpat1-dev \
liblzma-dev libevent-dev binutils libproj-dev xsltproc docbook-xsl\
docbook-mathml libgeos-dev libgeos-3.5.1 postgresql-9.6-postgis-2.3\
libgdal-dev python3-gdal python3-numpy gdal-bin postgresql-9.6-postgis-scriptsAdd to .bashrc
export CPLUS_INCLUDE_PATH=/usr/include/gdal
export C_INCLUDE_PATH=/usr/include/gdalMake sure rgeo witll be able to find geos
sudo ln -s /usr/lib/x86_64-linux-gnu/libgeos-3.5.1.so /usr/lib/libgeos.so
# uninstall rgeo first if it was previously installed
gem install rgeo
rbenv rehashPython libs
sudo pip3 install matplotlib
sudo pip3 install pyproj
sudo pip3 install rasterio
sudo pip3 install fiona- Install prerequisite packages
sudo apt-get install libaio1 libaio-dev - Download the Oracle Instant Client Basic and Instant Client SDK packages - Get the latest 11.x versions for Linux x86-64
- Create the directory /usr/share/oracle and extract the OIC zip files directly into the root of this directory
- Inside of the /usr/share/oracle directory, create this symlink
sudo ln -s libclntsh.so.11.1 libclntsh.so - Create a LD_LIBRARY_PATH config file
sudo vim /etc/ld.so.conf.d/oic.conf - Add this line to the file and save it
/usr/share/oracle - Update the LD_LIBRARY_PATH
sudo ldconfig
rvm
https://www.phusionpassenger.com/library/install/nginx/install/oss/rubygems_rvm/