Eric Guo's

in HTML5, JavaScript, Ruby & Rails, Python, and Cloud MES!

Ubuntu 18.04 Ruby on Rails Installation Log


Enable the Firewall

ufw app list
ufw allow ssh
ufw enable
ufw status

Install node.js

apt install nodejs
apt install npm
curl -sL -o
apt-get install -y nodejs
curl -sS | sudo apt-key add -
echo "deb stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
apt update
apt install yarn

Install rbenv

apt update
apt install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm5 libgdbm-dev
apt install git
logout # as ubuntu
git clone ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc
type rbenv
git clone ~/.rbenv/plugins/ruby-build
rbenv install -l

Install ruby 2.6.5

rbenv install 2.6.5
rbenv global 2.6.5
echo "gem: --no-document" > ~/.gemrc
gem install bundler
gem install rails
rbenv rehash

Install postgresql

apt-get install postgresql
apt-get install postgresql-server-dev-all
sudo su - postgres
createuser ubuntu --pwprompt

Install nginx

apt-get install nginx

Generate ssh key

sudo mkdir /var/www
cd /var/www
sudo mkdir cam_price
sudo chown ubuntu:ubuntu cam_price/

Install HTTPS

Largely following certbot guide

apt-get update
apt-get install software-properties-common
add-apt-repository universe
add-apt-repository ppa:certbot/certbot
apt-get update
apt-get install certbot python-certbot-nginx

Running Rails 6 App With Sqlite3 on CentOS 7


Running CentOS 7 as operation system for Rails is very stable, but such stability comes with stagnation, for example, the sqlite3 version is 3.7 instead of 3.8, so cause Rails 6 refused to run in CentOS 7 withouth install a third party sqlite3 version.

So a quickly fix is install atomic sqlite and setting the correct build options.

$HOME/.rbenv/bin/rbenv exec bundle config build.sqlite3 "--with-sqlite3-include=/opt/atomic/atomic-sqlite/root/usr/include --with-sqlite3-lib=/opt/atomic/atomic-sqlite/root/usr/lib64 --with-sqlite3-dir=/opt/atomic/atomic-sqlite/root/usr"

Maybe also need to do a patch but any way, I successfully upgrade to Rails 6.

IE 11 Iframe Weird X-Frame-Options but Working Setting


After research 1 hours, I answered in the SO

def cors_set_access_control_headers
headers["Access-Control-Allow-Origin"] = "*"
headers["Access-Control-Allow-Methods"] = "GET"
headers["Access-Control-Request-Method"] = "*"
headers["Access-Control-Allow-Headers"] = "Origin, X-Requested-With, Content-Type, Accept, Authorization"
headers["X-Frame-Options"] = "ALLOW-FROM"
headers["X-XSS-Protection"] = "0"

Prepare the 16 kHz Monaural MP3 for Wechat API Speach to Text Interface


ffmpeg -i test_voice.amr -acodec mp3 -ac 1 -ar 16000 test_voice.mp3

微信AI开放接口, require that interface.

How to install in CentOS 7 from source code

yum install nasm
cd /usr/local/src
tar -zxvf lame-3.100.tar.gz
cd lame-3.100
./configure --prefix=/usr/local
make && make install
ln -s /usr/local/lib/ /usr/lib64/
tar -jxvf ffmpeg-snapshot.tar.bz2
cd ffmpeg
./configure --prefix=/usr/local --enable-libmp3lame
make && make install

Original post

How to Resolve Rails Test:system Long Time Pending Using Chromedriver


Running rails test:system in my local dev always pending and timeout problem haunted me for a long time, finally, I know why.

Due to some change introduced in Google, every time a new chromedriver installed using brew, the first time running always need to download a file from but due to there is GFW in China, it always pending.

So resolved is quite simple, make sure you running ruby.exe(or binary of ruby) when first time can access google site and that’s it.

You need to make sure only once per every new version, that’s it!

Allow New User to Login From Remote in Percona Server


Allow remote connect

vi /etc/my.cnf # bind-address =
systemctl restart mysqld
netstat -lnp | grep mysql # confirm 3306 is listened
firewall-cmd --add-service=mysql --permanent
firewall-cmd --reload

Add user

mysql -u root -p # input password if required
CREATE DATABASE cybros_bi character set UTF8mb4 collate utf8mb4_bin;
CREATE USER 'cybros_bi'@'%' IDENTIFIED BY 'cybros_bi_password';
GRANT ALL ON cybros_bi.* TO 'cybros_bi'@'%';

Install Pentaho Data Integration on MacOS 10.14.5 Mojave


It’s a little hard to find out the root cause why out of box Pentaho Data Integration not working, any way, it’s resolved.

First need java 8 to install, because Oracle refuse to provide, need OpenJDK instead.

brew tap adoptopenjdk/openjdk
brew cask install adoptopenjdk8
brew install jenv # If also want to using other java version
cd "/Applications/Data"
cat JavaApplicationStub

Also need change JavaApplicationStub file as below. (Maybe Pentaho developer didin’t having a MBP…)

# PROG_DIR=$(cd "$(dirname "$0")"; pwd)
# PROG_DIR is in .app/Contents/MacOS
# BASE_DIR="$PROG_DIR"/../../../
cd "$BASE_DIR"
echo $BASE_DIR
. "spoon.command" "$BASE_DIR"

If you want to continue using Java 12 in system wide, install brew install jenv and running jenv local 1.8 at data-integration folder.

Using Aliyun OSS as CDN for the Rails Application


用Rails做企业官网虽然不是现在的流行方式,但是考虑到Rails的灵活性和后端开发的方便性,在某些情况下,还是相比现在最火的JAM gatsby.js更实际。


| |
<cache> <no cache>
| |
[200] <>
[Nginx location /assets]
[200] --> [CDN Cache]

配置方法也非常简单,新建一个OSS Bucket,例如上图中的名字thape-assets

最后在Rails中的 config/environments/production.rb 中,启用新的OSS地址即可。

# Enable serving of images, stylesheets, and JavaScripts from an asset server.
config.action_controller.asset_host = ''