/ php

php-deployer

部署

自动部署

让部署变得简单:我们应该只执行一个简单的命令就能部署。
让部署的结果可预知:如果出错了,部署过程会终止,现有的代码基(?)不会受到影响。
让部署可逆:应该有个简单的命令可以回滚到之前稳定的代码基(?)。

自动部署应用软件:

  • deploy
  • capistrano
  • phing

deploy (使用中)

https://github.com/deployphp/deployer

部署实例:https://deployer.org/blog/how-to-deploy-laravel

composer global require deployer/deployer

进入项目根目录:

dep init
  Welcome to the Deployer config generator  
                                            


 This utility will walk you through creating a deploy.php file.
 It only covers the most common items, and tries to guess sensible defaults.
 
 Press ^C at any time to quit.

 Please select your project type [Common]:
  [0 ] Common
  [1 ] Laravel
  [2 ] Symfony
  [3 ] Yii
  [4 ] Yii2 Basic App
  [5 ] Yii2 Advanced App
  [6 ] Zend Framework
  [7 ] CakePHP
  [8 ] CodeIgniter
  [9 ] Drupal
  [10] TYPO3

查看可用命令:

dep
deploy [-p|--parallel] [-l|--limit LIMIT] [--no-hooks] [--log LOG] [--roles ROLES] [--hosts HOSTS] [-o|--option OPTION] [--] [<stage>]
dep list

dep my_task

dep deploy main

dep deploy --hosts domain.com
dep deploy --roles app

部署新版本

新增部署:

# 默认发布当前 branch
dep deploy

vagrant@homestead:~/code/yii2-cms$ dep deploy
✈︎ Deploying master on www.yii2-cms.com
✔ Executing task deploy:prepare
✔ Executing task deploy:lock
✔ Executing task deploy:release
➤ Executing task deploy:update_code
Connection to www.yii2-cms.com closed.
✔ Ok
✔ Executing task deploy:vendors
✔ Executing task deploy:init
✔ Executing task deploy:shared
✔ Executing task deploy:run_migrations
✔ Executing task deploy:symlink
✔ Executing task deploy:unlock
✔ Executing task cleanup
Successfully deployed!
# 查看详细过程
dep deploy -vvv

# 部署指定branch
dep deploy --branch=develop

# 部署指定tag
dep deploy --tag="v0.1"

# 部署指定commit
dep deploy --revision="5daefb59edbaa75"

显示当前应用发布版本:

dep config:current

部署失败,清理到 release 文件夹:

dep cleanup

回滚部署

dep rollback

进入远程服务器

dep ssh

显示所有配置信息

dep config:dump

显示 host 列表

dep config:hosts

404

failed (13: Permission denied)
权限问题

dep deploy:writable

文档概要

Download a new version of code using Git. If you are using Git version 2.0 and git_cache config is turned on, this task will use files from the previous release, so only changed files will be downloaded.

远程服务器:

git --version
git version 1.8.3.1

补充文档:
http://www.karan.org/blog/2017/08/31/git-2-on-centos-linux-7/
https://www.cnblogs.com/mawang/p/6749396.html

capistrano (未使用)

Linux 需要安装 ruby 和 gem:

gem install capistrano

进入项目的最顶层目录:

cap install

这个命令会创建一个名为 Capfile 的文件

  • staging - 过渡环境
  • production - 生产环境

http://capistranorb.com/documentation/getting-started/structure/