Wiki
Clone wikiThingyanServer / get_started
更新
-
路径
# 服务器 ~/server -> ~/apps/spree/htdocs # Apache log ~/server.logs -> /opt/bitnami/apache2/logs # Apache config ~/htdocs -> /opt/bitnami/apache2/htdocs # Control script ~/ctlscript.sh -> /opt/bitnami/ctlscript.sh
-
生产服务器 设定环境变量
export RAILS_ENV=production
-
更新代码
git pull
-
更新gem
bundle install
或
bundle install --deployment
-
安装Spree Plugins或Railties
bin/rails g spree_plugin_name:install
- 安装plugin会修改文件,复制migration并运行,也可选择否,然后与当前app下的migration一起运行
复制Engine下的migration文件到当前db/migrate
bin/rake railties:install:migrations
- 安装plugin会修改文件,复制migration并运行,也可选择否,然后与当前app下的migration一起运行
-
更新数据库
bin/rake db:migrate
-
生产服务器 清空缓存。如果更新了页面内容数据,需要清除对应页面缓存。重启后需设置tmp权限
bin/rake tmp:cache:clear
-
生产服务器 编译静态文件
bin/rake assets:precompile
-
如果编译遇到权限问题,bitnami说明
sudo chown -R bitnami:daemon tmp sudo chmod -R 775 tmp
问题:运行apache用户为daemon,rails app通过phusion passenger运行,用户为bitnami,所以对于apache服务器运行时生成的文件需要给bitnami写权限
-
重启服务器
bin/rails server -b ip_address
或
sudo /opt/bitnami/ctlscript.sh restart apache
本地开发环境
bin/rails server bin/rails server -b ip_address redis-server /usr/local/etc/redis.conf bin/rails console
日志
Production
-
Apache日志
error_log
cd /opt/bitnami/apache2/logs tail -r -n100 error_log tail -f -n100 error_log | less -r
-
Rails app日志
production.log
cd ~/server/log tail -f -n100 production.log | less -r
-
打印日志
# in config/environments/production.rb # Set to :debug to see everything in the log. # Use Rails.logger.debug to log config.log_level = :debug
Development
- 本地开发环境,错误日志直接打印输出,
p
puts
搭建
本地
-
安装工具
-
Bundler (与 Python Virtual ENV 一样)
sudo gem install bundler
-
brew install imagemagick
-
-
git clone git@bitbucket.org:phantomex/thingyanserver.git
-
bundle config mirror.https://rubygems.org https://ruby.taobao.org
设置bundler读取Gemfile时的gem source mirror -
bundle install --path vendor/bundle --without=production
,运行过一次--path
,以后的bundle命令都不用在指明--path了,会默认使用第一次的设置- 问题1:在MAC上,安装nokogir出错,提示找不到libxml2;参考SO
- 如果安装了xcode或command line tools,则libxml2的头文件在
/usr/include/libxml2
;如果没有,brew install libxml2
,安装后路径在/usr/local/opt/libxml2/include/libxml2
- 设置bundler
bundle config build.nokogiri --use-system-libraries --with-xml2-include=/usr/include/libxml2/
或brew安装路径 - 再次运行
bundle install --without=production
- 如果安装了xcode或command line tools,则libxml2的头文件在
- 问题2: 如果安装mysql2出错,则没有执行参数
--without=production
。或brew install mysql
- 问题3:由于国内网络环境问题,可能taobao源也不稳定,会有timeout现象,可以用香港VPN或其他网络
- 可选
bundle exec rake rails:update:bin
将当前环境命令放入./bin
中,可替代bundle exec
- 问题1:在MAC上,安装nokogir出错,提示找不到libxml2;参考SO
-
安装数据
bin/rake db:bootstrap
- 如果导入图片有问题,检查ImageMagick的安装和依赖是否有问题,如:
brew install freetype
- 如果导入图片有问题,检查ImageMagick的安装和依赖是否有问题,如:
-
bin/rails server
启动服务器,打开localhost:3000
- 问题1:如果网页没有样式,则需重新安装Spree
bin/rails g spree:install --migrate=false --sample=false --seed=false bin/rails g spree_api_extend:install # if spree_api_extend installed bin/rake db:bootstrap
- 问题1:如果网页没有样式,则需重新安装Spree
服务器部署
-
Rails命令需设置环境变量
export RAILS_ENV=production
-
更新bundle gem
bundle install --deployment
-
Precompile assets
RAILS_ENV=production bin/rake assets:precompile
-
如果有新gem需要安装
RAILS_ENV=production bin/rails g spree_api_extend:install
-
Migrate
bin/rake railties:install:migrations bin/rake db:migrate
- 如果失败,可能需要更改
./tmp/cache
文件夹权限sudo chmod -R 777 ./tmp/cache
- 如果失败,可能需要更改
-
重启服务器
sudo /opt/bitnami/ctlscript.sh restart apache
-
如果需要重建数据
bin/rake db:drop db:create bin/rails g spree_api_extend:install bin/rake db:bootstrap # 或 bin/rake db:reset bin/rake spree_sample:load
设置服务器
需要对服务器进行设置才能正常操作数据
由于商店设在缅甸,所以需要设置服务器才能正常运行,部分设置已写在设置代码中,界面部分也需要进行相应设置,才能与代码逻辑相匹配
- 进入admin
- 进入configurations
- General Settings
- Tax Categories 增加 Default
- Zones 增加 Myanmar
- Tax Rates 增加 Myammar
- Payment Methods 增加 'Cash on Delivery' 类型为 'Spree::PaymentMethod::Check'
- Shipping Methods 增加 UCS
- Roles 增加 'staff_product' 'staff_order'
将Sample中商品的价格转换为设定货币MMK
- 'bin/rails runner script/change_sample_product_currency.rb'
创建和升级Spree
新建 Rails Spree App
按照spree的Developer Guide 和 Github README来安装
安装最新版的spree,3.0.1,和对应的rails 4.2.1
-
安装工具文件,ImageMagick, Buby, RVM, Bundler, Rails
- 安装bundler
sudo gem install bundler
- 安装rails
sudo gem install rails
- 安装ImageMagick
brew install imagemagick
- 安装bundler
-
建立rails app
rails new Server
-
Gemfile在最新版本 rails 4.2.1 默认生成的基础上(rails new),增加以下gem
# Custom Gems gem 'tzinfo-data' # Spree gem 'spree', github: 'spree/spree', branch: '3-0-stable' gem 'spree_gateway', github: 'spree/spree_gateway', branch: '3-0-stable' gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '3-0-stable'
-
安装Gem
bundle install --path vendor/bundle
-
更新bundler bin
$ bundle config --delete bin $ bundle exec rake rails:update:bin # 增加新gem后 $ bundle binstubs [gem-name]
-
更新权限,bitnami说明
- 更改
./tmp/cache
文件夹权限sudo chmod -R 777 ./tmp/cache
, 否则migrate可能失败 - 更改
./public/spree/
文件夹权限sudo chmod 775 ./public; sudo chmod -R 775 ./public/spree
, 否则商品图片上传失败
- 更改
更换地址
-
申请证书
- 申请域名,设置 DNS
- acme.sh
$ acme.sh --issue --standalone -d lafrecona.ml -d www.lafrecona.ml --server letsencrypt --insecure $ acme.sh --install-cert -d lafrecona.ml \ --cert-file /home/bitnami/spree/conf/certs/cert.pem \ --key-file /home/bitnami/spree/conf/certs/key.pem \ --fullchain-file /home/bitnami/spree/conf/certs/fullchain.pem
-
服务器地址
$ vi /opt/bitnami/apps/spree/conf/httpd-vhosts.conf edit ServerName / ServerAlias / Certs
-
数据库地址
$ vi ~/server/config/database.yml edit host eg. host: fungo-spree-db.cqdjyn1h648e.ap-southeast-1.rds.amazonaws.com
-
Redis地址
$ vi ~/server/config/redis.yml edit host
-
可选更新Bitnami导航链接
$ vi /opt/bitnami/apache2/htdocs/applications.html edit line 34: href="" $ vi /opt/bitnami/apps/spree/htdocs/config/routes.rb edit line 4: redirect('')
安装spree
-
设置数据库,文件
config/database.yml
-
安装spree
$ bin/rails g spree:install --migrate=false --sample=false --seed=false $ bin/rake db:bootstrap
Updated