6 months ago
adduser appdev
adduser appdev sudo
vim /etc/ssh/sshd_config

update PasswordAuthentication from no to yes to allow new user login with password

service ssh restart

on local machine

ssh-copy-id appdev@mzctjkj.com
ssh appdev@mzctjkj.com
vim /etc/ssh/sshd_config

update PasswordAuthentication from yes to no to secure your linux server
and update PermitRootLogin from yes to no

sudo service ssh restart
sudo apt-get update
sudo apt-get upgrade

install tool

sudo apt-get install build-essential git-core curl libssl-dev libreadline5 libreadline-gplv2-dev zlib1g zlib1g-dev libcurl4-openssl-dev libxslt-dev libxml2-dev libffi-dev git vim

install rvm without root user

\curl -sSL https://get.rvm.io | bash
source ~/.rvm/scripts/rvm

install ruby now

rvm install 2.3.1

update gem source from default to china mirror

gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
gem sources -l

$## confirm there is only one gems.ruby-china.org
gem install bundler
gem install passenger
bundle config mirror.https://rubygems.org https://gems.ruby-china.org
rvmsudo passenger-install-nginx-module

选择Ruby & NodeJS

再选择选项1. Yes: download, complie and install Nginx for me. (recommended)

选择安装目录, 可以直接按回车,使用默认安装目录[/opt/niginx]

install nginx with passenger now

git clone git://github.com/jnstq/rails-nginx-passenger-ubuntu.git
sudo mv rails-nginx-passenger-ubuntu/nginx/nginx /etc/init.d/nginx
sudo chown root:root /etc/init.d/nginx
sudo vim /lib/systemd/system/nginx.service
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
ExecStartPre=/opt/nginx/sbin/nginx -t
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID

restart nginx to verify

sudo /etc/init.d/nginx restart

enable auto start up for nginx

sudo systemctl enable nginx.service

install rails

gem install rails -v 5.1.4

install nodejs

sudo apt-get install npm

install PostgreSQL

sudo apt-get install postgresql postgresql-contrib libpq-dev
gem install pg

update postgre password

sudo -u postgres psql
\password postgres

leave by


let rails know how to connect database

sudo vim /etc/postgresql/9.5/main/pg_hba.conf

update all md5 to peer

sudo /etc/init.d/postgresql reload

now the machine is running


    listen       80;
    server_name  mzctjkj.com;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    root /home/appdev/wechat/public;
    passenger_enabled on;

    location ~/muyushi{
            root /home/appdev/;

setup a wechat rails server

mkdir your_app
cd your_app
git init
git remote add template https://github.com/goofansu/wechat-starter.git
git fetch template
git checkout -b master template/master
bundle install
rake db:create
bundle exec rake db:create RAILS_ENV=production

generate secret

rake secret

copy generated secret into config/secret

bundle exec rake db:migrate RAILS_ENV=production

create config/application.yml

wechat_app_id: "AppID"
wechat_secret: "AppSecret"
wechat_token:  "Token"
wechat_encoding_aes_key: "EncodingAESKey"
wechat_trusted_domain_fullname: "http://your_dev.proxy.qqbrowser.cc"


default: &default
  appid:  "AppID"
  secret: "AppSecret"
  token:  "Token"
  access_token: "/var/tmp/wechat_access_token"
  jsapi_ticket: "/var/tmp/wechat_jsapi_ticket"

  <<: *default
  encrypt_mode: false 
  encoding_aes_key: "EncodingAESKey"
  trusted_domain_fullname: "http://your_dev.proxy.qqbrowser.cc"
bundle exec rake assets:precompile db:migrate RAILS_ENV=production


default: &default
  adapter: postgresql
  encoding: unicode
  # For details on connection pooling, see Rails configuration guide
  # http://guides.rubyonrails.org/configuring.html#database-pooling
  host : localhost
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: postgres
  password: postgres

  <<: *default
  adapter: postgresql
  database: wechat_starter_production
  host : localhost
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: postgres
  password: postgres

open yourhost.com in wechat client

← 数字货币买入指南 02 how to host a singe page application with nginx →