Stay Hungry.Stay Foolish.
centos 6部署安装phoenix程序

更新系统

sudo yum install epel-release
sudo yum update
sudo reboot

安装erlang

wget http://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm
sudo rpm -Uvh erlang-solutions-1.0-1.noarch.rpm
sudo yum install erlang

安装Elixir

cd /usr/bin
sudo mkdir elixir
cd /usr/bin/elixir
sudo wget https://github.com/elixir-lang/elixir/releases/download/v1.3.4/Precompiled.zip
sudo yum install unzip
sudo unzip Precompiled.zip

把/usr/bin/elixir/bin添加到环境变量, 这里我加入到全局的/etc/profile, 然后载入

export PATH="$PATH:/usr/bin/elixir/bin"
source /etc/profile

最后安装elixir的包管理hex

mix local.hex

安装 Phoenix

mix archive.install https://github.com/phoenixframework/archives/raw/master/phoenix_new.ez

安装nodejs

wget https://nodejs.org/dist/latest-v5.x/node-v5.12.0-linux-x86.tar.gz
sudo tar -xzvf  node-v5.12.0-linux-x86.tar.gz
sudo mv node-v5.12.0-linux-x86 /usr/local/

然后导出环境变量,我这里加入的是/etc/profile文件

export PATH="$PATH:/usr/local/node-v5.12.0-linux-x86/bin"
source /etc/profile

安装 PostgreSQL

rpm -Uvh http://yum.postgresql.org/9.5/redhat/rhel-6-x86_64/pgdg-redhat95-9.5-2.noarch.rpm
yum install postgresql95-server postgresql95

初始化postgresql

service postgresql-9.5 initdb

配置启动postgresql和开机启动

service  postgresql-9.5 start
chkconfig postgresql-9.5 on

修改postgres账户密码

su - postgres
psql
password postgres

配置postgresql连接认证方式 修改 /var/lib/pgsql/9.5/data/pg_hba.conf

local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5

把IPv4和Ipv6的连接认证方式改为md5就可以了。 然后重启下postgresql。

service  postgresql-9.5 restart

安装Phoenix application

mix deps.get
mix ecto.create && mix ecto.migrate
npm install
mix phoenix.server

ps: 上面我是在vps上测试,监听到公网地址,修改config/dev.exs

config :hello_phoenix, HelloPhoenix.Endpoint,
  http: [ip: {0,0,0,0}, port: 4000],
  debug_errors: true,

错误排查

执行mix ecto.create && mix ecto.migrate的时候会遇到错误如下

PG::Error: ERROR:  new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)

最后我找到这个文章解决了问题。

First, we need to drop template1. Templates can’t be dropped, so we first modify it so t’s an ordinary database:

UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';
Now we can drop it:

DROP DATABASE template1;
Now its time to create database from template0, with a new default encoding:

CREATE DATABASE template1 WITH TEMPLATE = template0 ENCODING = 'UNICODE';
Now modify template1 so it’s actually a template:

UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';
Now switch to template1 and VACUUM FREEZE the template:

\c template1

VACUUM FREEZE;
Problem should be resolved.
自由转载-非商用-非衍生-保持署名(创意共享3.0许可证
评论
2016-11-12 09:02:16

hello

2017-09-27 09:17:04

hello