{"id":15308189,"url":"https://github.com/yidas/deployer-php-cli","last_synced_at":"2025-04-15T00:54:50.203Z","repository":{"id":52656746,"uuid":"57264781","full_name":"yidas/deployer-php-cli","owner":"yidas","description":"CI/CD Deployment tool written in PHP supported for popular frameworks (Yii2, Laravel, CI3)  ","archived":false,"fork":false,"pushed_at":"2022-10-07T08:14:35.000Z","size":190,"stargazers_count":12,"open_issues_count":0,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-15T00:54:45.171Z","etag":null,"topics":["ci-cd","continuous-delivery","continuous-integration","deployment","php-cli","rsync"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yidas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-28T02:38:16.000Z","updated_at":"2022-12-21T03:11:58.000Z","dependencies_parsed_at":"2022-08-25T00:50:47.819Z","dependency_job_id":null,"html_url":"https://github.com/yidas/deployer-php-cli","commit_stats":null,"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yidas%2Fdeployer-php-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yidas%2Fdeployer-php-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yidas%2Fdeployer-php-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yidas%2Fdeployer-php-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yidas","download_url":"https://codeload.github.com/yidas/deployer-php-cli/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248986280,"owners_count":21194025,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ci-cd","continuous-delivery","continuous-integration","deployment","php-cli","rsync"],"created_at":"2024-10-01T08:14:25.982Z","updated_at":"2025-04-15T00:54:50.186Z","avatar_url":"https://github.com/yidas.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Deployer PHP-CLI\n================\n\nCI/CD Deployment tool written in PHP supported for popular frameworks\n\n[![Latest Stable Version](https://poser.pugx.org/yidas/deployer-php-cli/v/stable?format=flat-square)](https://packagist.org/packages/yidas/deployer-php-cli)\n[![License](https://poser.pugx.org/yidas/deployer-php-cli/license?format=flat-square)](https://packagist.org/packages/yidas/deployer-php-cli)\n\nFEATURES\n--------\n\n- *Deploy to **multiple** servers by **projects/groups***\n\n- ***Yii2, Laravel, Codeigniter3** Frameworks support*\n\n- ***Pipeline support** for Git, Composer, test and customized tasks*\n\n- ***CI/CD** automation solution*\n\nHelping developers to deploy codes from local instance to remote instances.\n\n---\n\nOUTLINE\n-------\n\n* [Demonstration](#demonstration)\n* [Requirements](#requirements)\n* [Installation](#installation)\n  - [Composer Installation](#composer-installation)\n  - [Wget Installation](#wget-installation)\n    - [Make Command](#make-command)\n  - [Startup](#startup)\n  - [Upgrade](#upgrade)\n* [Configuration](#configuration)\n  - [Project Setting](#project-setting)\n  - [Config Options](#config-options)\n    - [Git](#git)\n    - [Composer](#composer)\n    - [Test](#test)\n    - [Tests](#tests)\n    - [Rsync](#rsync)\n    - [Commands](#commands)\n  - [Example](#example)\n* [Usage](#usage)\n  - [Interactive Project Select](#interactive-project-select)\n  - [Non-Interactive Project Select](#non-interactive-project-select)\n  - [Skip Flows](#skip-flows)\n  - [Revert \u0026 Reset back](#revert--reset-back)\n* [Implementation](#implementation)\n  - [Permissions Handling](#permissions-handling)\n* [CI/CD](#cicd)\n  - [Webhook](#webhook)\n    - [PHP Web Setting](#php-web-setting)\n    - [Gitlab](#gitlab)\n* [Additions](#additions)\n  - [Rsync without Password](#rsync-without-password)\n  - [Save Binary Encode File](#save-binary-encode-file)\n  - [Yii2 Deployment](#yii2-deployment)\n  - [Minify/Uglify by Gulp](#minifyuglify-by-gulp)\n  \n---\n\nDEMONSTRATION\n-------------\n\n![Basic Flow](https://www.plantuml.com/plantuml/proxy?src=https://raw.githubusercontent.com/yidas/deployer-php-cli/master/img/sequence-diagram.plantuml)\n\n### Command Line\n\nDeploy local project to remote servers by just executing the deployer in command after installation:\n\n```\n$ deployer\n```\n\n\u003e Alternatively, you could call the original bootstrap: `$ ./deployer`, `$ php ./deployer`\n\nThe interactive result could like be:\n```\n$ deployer\n\nYour available projects in configuration:\n  [0] your.project.com\n  [1] second.project.com\n  [2] other.site.com\n\n  Please select a project [number or project, Ctrl+C to quit]:0\n\nSelected Project: your.project.com\nSuccessful Excuted Task: Git\nSuccessful Excuted Task: Composer\nSuccessful Excuted Task: Composer\nSuccessful Excuted Task: Test UnitTest\nSuccessful Excuted Task: Commands before: Minify assets\nSuccessful Excuted Task: Deploy to 127.0.0.11\nSuccessful Excuted Task: Deploy to 127.0.0.12\nSuccessful Excuted Task: Deploy\nSuccessful Excuted Task: Commands after: Email notification\n```\n\nOr you could run by non-interactive mode with the same purpose:\n\n```\n$ deployer --project=\"your.project.com\"\n```\n\n---\n\nREQUIREMENTS\n------------\n\nThis library requires the following:\n\n- PHP(CLI) 5.4.0+\n- RSYNC\n\n---\n\nINSTALLATION\n------------\n\n### Composer Installation\n\nUsing Composer by `sudoer` or `root` to install is the easiest way with auto-installer:\n\n```\ncomposer create-project --prefer-dist yidas/deployer-php-cli\n```\n\n### Wget Installation\n\nYou could see [Release](https://github.com/yidas/deployer-php-cli/releases) for picking up the package with version, for example:\n    \n```\n$ wget https://github.com/yidas/deployer-php-cli/archive/master.tar.gz -O deployer-php-cli.tar.gz\n```\n\nAfter download, uncompress the package:\n\n```\n$ tar -zxvf deployer-php-cli.tar.gz\n```\n\n\u003e In addition, you can rename the unzipped folder by  `mkdir deployer-php-cli \u0026\u0026 tar -zxvf deployer-php-cli.tar.gz --strip-components 1 -C deployer-php-cli`\n\n#### Make Command\n\nTo make a command for deployer, if the package folder is `deployer-php-cli` then create a symbol by following command: \n\n```\n$ sudo chmod +x $(pwd -L)/deployer-php-cli/deployer\n$ sudo ln -s $(pwd -L)/deployer-php-cli/deployer /usr/bin/deployer\n```\n\n### Startup\n\nAfter installation, you could start to set up the `config.inc.php` for deployer, and enjoy to use:\n\n```\n$ deployer\n```\n\n### Upgrade\n\nTo upgrade, you could re-install the deployer and copy the old `config.inc.php` to the new one, for example:\n\n```\n$ cp ./deployer-php-cli/config.inc.php ./\n$ rm -r deployer-php-cli\n$ composer create-project --prefer-dist yidas/deployer-php-cli\n$ mv ./config.inc.php ./deployer-php-cli\n```\n\n---\n\nCONFIGURATION\n-------------\n\n### Project Setting:\n\nYou need to set up the projects configuration such as servers, source and destination in `config.inc.php` file:\n\n```php\n\u003c?php\n\nreturn [\n    // This project config processes deployment only for simple usage\n    'default' =\u003e [\n        'servers' =\u003e [\n            '127.0.0.1',\n        ],\n        'source' =\u003e '/home/user/project',\n        'destination' =\u003e '/var/www/html/prod/',\n    ],\n];\n```\n\n\u003e You could refer [config.inc.php](https://github.com/yidas/deployer-php-cli/blob/master/config.inc.php) file as an example..\n\n### Config Options:\n\nConfiguration provides many features' setting, you could customize and pick up the setting you need.\n\n|Key|Type|Description|\n|:-|:-|:-|\n|**servers**|array|Distant server host list|\n|**user**|array\\|string|Local/Remote server user, auto detect current user if empty|\n|**source**|string|Local directory for deploy, use `/` as end means `*` |\n|**destination**|string|Remote path for synchronism|\n|**exclude**|array|Excluded files based on sourceFile path|\n|verbose|bool|Enable verbose with more infomation or not|\n\n#### Git\n\nTo use Git into deploy task, you need to init or clone Git to the source directory at the first time:\n\n```\n$ git clone git@gitlab.com:username/project-to-deploy.git sourceDir\n```\n\n|Key|Type|Description|\n|:-|:-|:-|\n|enabled|bool|Enable git or not|\n|checkout|bool|Execute git checkout -- . before git pull  |\n|branch|string|Branch name for git pull, pull default branch if empty  |\n|submodule|bool|Git submodule enabled |\n\n#### Composer\n\nTo use Composer into deploy task, make sure that there are composer files in the source directory.\n\n|Key|Type|Description|\n|:-|:-|:-|\n|enabled|bool|Enable Composer or not|\n|path|string|Composer executing relative path which supports multiple array paths|\n|command|string|Update command likes `composer update`|\n\n#### Test\n\nTo use Test into deploy task, make sure that there are test configuration in the source directory.\n\n|Key|Type|Description|\n|:-|:-|:-|\n|enabled|bool|Enable Test or not|\n|name|string|The test name for display|\n|type|string|Test type, support `phpunit`.|\n|command|string|The test bootstrap command supported relative filepath such as `./vendor/bin/phpunit`|\n|configuration|string|The test configuration file supported relative filepath such as `./phpunit.xml`|\n\n#### Tests\n\nFor multiple test tasks, using array to declare each [test options](#test):\n\n```php\nreturn [\n    'default' =\u003e [\n        'tests' =\u003e [\n            [\n                'name' =\u003e 'Test Task 1',\n                // ...\n            ],\n            [\n                'name' =\u003e 'Test Task 2',\n                // ...\n            ],\n        ],\n        // ...\n```\n\n#### Rsync\n\n|Key|Type|Description|\n|:-|:-|:-|\n|enabled|bool|Enable rsync or not|\n|params|string|Addition params of rsync command|\n|timeout|int|Timeout seconds of each rsync connections|\n|sleepSeconds|int|Seconds waiting of each rsync connections|\n|identityFile|string|Identity file path for appling rsync|\n\n#### Commands\n\nCommands provides you to customize deploy tasks with many trigger hooks.\n\n|Key|Type|Description|\n|:-|:-|:-|\n|init|array|Addition commands triggered at initialization|\n|before|array|Addition commands triggered before deploying|\n|after|array|Addition commands triggered after deploying|\n\n### Example\n\n* Copy `project` directory form `/var/www/html/` to destination under `/var/www/html/test/`:\n\n```php\n'source' =\u003e '/var/www/html/project',\n'destination' =\u003e '/var/www/html/test/',\n```\n\n* Copy all files (`*`) form `/var/www/html/project/` to destination under `/var/www/html/test/`:\n\n```php\n'source' =\u003e '/var/www/html/project/',\n'destination' =\u003e '/var/www/html/test/',\n```\n\n---\n\nUSAGE\n-----\n\n```\nUsage:\n  deployer [options] [arguments]\n  ./deployer [options] [arguments]\n\nOptions:\n  -h, --help            Display this help message\n      --version         Show the current version of the application\n  -p, --project         Project key by configuration for deployment\n      --config          Show the seleted project configuration\n      --configuration\n      --skip-git        Force to skip Git process\n      --skip-composer   Force to skip Composer process\n      --git-reset       Git reset to given commit with --hard option\n  -v, --verbose         Increase the verbosity of messages\n```\n\n### Interactive Project Select\n\n```\n$ deployer\n\nYour available projects in configuration:\n  [0] default\n  [1] your.project.com\n\n  Please select a project [number or project, Ctrl+C to quit]:your.project.com\n\nSelected Project: your.project.com\nSuccessful Excuted Task: Git\nSuccessful Excuted Task: Composer\nSuccessful Excuted Task: Deploy to 127.0.0.11\nSuccessful Excuted Task: Deploy\n```\n\n### Non-Interactive Project Select\n\n```\n$ deployer --project=\"your.project.com\"\n```\n\n### Skip Flows\n\nYou could force to skip flows such as Git and Composer even when you enable then in config.\n\n```\n$ deployer --project=\"default\" --skip-git --skip-composer\n```\n\n### Revert \u0026 Reset back\n\nYou could reset git to specified commit by using `--git-reset` option when you get trouble after newest release.\n\n```\n$ deployer --project=\"default\" --git-reset=\"79616d\"\n```\n\n\u003e This option is same as executing `git reset --hard 79616d` in source project.\n\n---\n\nIMPLEMENTATION\n--------------\n\nAssuming `project1` is the developing project which you want to deploy.\n\nDevelopers must has their own site to develop, for example:\n\n```\n# Dev host\n/var/www/html/dev/nick/project1\n/var/www/html/dev/eric/project1\n```\n\nIn general, you would has stage `project1` which the files are same as production:\n\n```\n# Dev/Stage host\n/var/www/html/project1\n```\n\nThe purpose is that production files need to be synchronous from stage:\n\n```\n# Production host\n/var/www/html/project1\n```\n\nThis tool regard stage project as `source`, which means production refers to `destination`, so the config file could like:\n\n```php\nreturn [\n    'project1' =\u003e [\n        ...\n        'source' =\u003e '/var/www/html/project1',\n        'destination' =\u003e '/var/www/html/',\n        ...\n```\n\nAfter running this tool to deploy `project1`, the stage project's files would execute processes likes `git pull` then synchronise to production.\n\n\n### Permissions Handling\n\n##### 1. Local and Remote Users\n\nYou could create a user on local for runing Deployer with `umask 002`. It will run process by the local user you set even you run Deployer by root:\n\n```php\nreturn [\n    'project1' =\u003e [\n         'user' =\u003e [\n            'local' =\u003e 'deployer',\n            'remote' =\u003e 'deployer',\n        ],\n        ...\n```\n\n##### 2. Application File Permissions\n\nDeployer uses `rsync` to deploy local source project to remote ***without*** `--no-perms`, which means that the source files' permission would keep on remote, but the files' owner would re-generate by remote user including `root` with `--no-owner --no-group`.\n\nOn the remote user, you could set the user's default groud ID to `www-data` in `/etc/passwd`, which the ***local user*** generates `664/775` mod files to deploy for ***remote*** `www-data` access. \n\n\u003e For local user, `umask 002` could be set in `~/.bashrc` or global. Note that the permission need to apply for source files such as init from Git clone.\n\n---\n\nCI/CD\n-----\n\n### Webhook\n\nDeployer provides webhook feature for triggering project deployment by any webhook service such as Gitlab.\n\nTo use webhook, you need add webhook setting into the projects you needed in `config.inc.php`:\n\n```php\nreturn [\n    'project' =\u003e [\n        // ...\n        'webhook' =\u003e [\n            'enabled' =\u003e true,\n            'provider' =\u003e 'gitlab',\n            'project' =\u003e 'yidas/deployer-php-cli',\n            'token' =\u003e 'da39a3ee5e6b4b0d3255bfef95601890afd80709',\n            'branch' =\u003e 'release',\n            'log' =\u003e '/tmp/deployer-webhook-project.log'\n        ],\n    ],\n];\n```\n\n|Key|Type|Description|\n|:-|:-|:-|\n|enabled|bool|Enable Webhook or not|\n|provider|string|Webhook provider such as `gitlab`|\n|project|string|Provider's project name likes `username/project`|\n|token|string|Webhook secret token|\n|branch|string|Listening branch for push event|\n|log|bool\\|string|Enabled log and specify the log file|\n\n#### PHP Web Setting\n\nDeployer need a user to excute deployment, and the user is usually not the PHP web user.\n\nFor PHP-FPM, you could add a new PHP pool socket with the current user setting for the webhook site, for example `/etc/php/fpm/pool.d/deployer.conf`:\n\n```php\n[deployer]\n\nuser = deployer\ngroup = www-data\n\nlisten = /run/php/php7.0-fpm_deployer.sock\n```\n\nThen give the new socket to the webhook server setting, for Nginx eaxmple `/etc/nginx/site-enabled/webhook`:\n\n```nginx\nserver_name webhook.your.com;\nroot /srv/deployer/deployer-php-cli/webhook;\n\nlocation ~ \\.php$ {                                     \n    include snippets/fastcgi-php.conf;                  \n    fastcgi_param SCRIPT_FILENAME $request_filename;    \n    fastcgi_pass unix:/run/php/php7.0-fpm_deployer.sock;\n}                                                                                                               \n```\n\nAfter a successful webhook, Deployer would prepare to process while responding the status and the result url for checking the deployment result. \n\n\u003e Note: The `PATH` environment variable between Shell and PHP should be set to the same to prevent any unexpected problems.\n\n#### Gitlab\n\n- Prividor key: `gitlab`\n\nAccording to above Nginx website setting, the webhook URL could be `https://webhook.your.com/gitlab`. After setting `config.inc.php` and setting up scecret token, you could give a push event to go!\n\n\u003cimg src=\"https://raw.githubusercontent.com/yidas/deployer-php-cli/dev_webhook/img/cicd-gitlab-webhook.png\" /\u003e\n\n\u003e Note: Default setting is listen `release` branch's push event to trigger.\n\nTo browse the web page for result log report, enter the same webhook URL with `log` and `token` parameters to access.\nFor example: `https://webhook.your.com/gitlab?log={project-name}\u0026token={project-token}`\n\n---\n\nADDITIONS\n---------\n\n### Rsync without Password:  \n\nYou can put your local user's SSH public key to destination server user for authorization.\n```\n.ssh/id_rsa.pub \u003e\u003e .ssh/authorized_keys\n```\n\n### Save Binary Encode File:  \n  \n  \nWhile excuting script, if you get the error like `Exception: Zend Extension ./deployer does not exist`, you may save the script file with binary encode, which could done by using `vim`:\n\n```\n:set ff=unix\n```\n\n### Yii2 Deployment\n\nFor `yii2-app-advanced`, you need to enable Composer and set yii2 init command in `config.inc.php`:\n\n```php\n'composer' =\u003e [                     \n    'enabled' =\u003e true,          \n],                                  \n'commands' =\u003e [\n    'before' =\u003e [\n        'yii2 init prod' =\u003e './init --env=Production --overwrite=All',\n    ],\n],\n```\n\n### Minify/Uglify by Gulp\n\n#### 1. Install NPM, for Debian/Ubuntu:\n\n```\napt-get install npm\n```\n\n#### 2. Install Gulp by NPM\n\n```\nnpm install -g gulp\n```\n\n#### 3. Create Gulp Project\n\n```\ncd /srv/tools/minify-project\nnpm init\nnpm install gulp --save-dev\ntouch gulpfile.js\n```\n\n#### 4. Set Gulp with packages\n\nPackage: [gulp-uglify](https://www.npmjs.com/package/gulp-uglify)\n\n```\n$ npm install gulp-uglify --save-dev\n$ npm install pump --save-dev\n```\n\n`gulpfile.js`:\n\n```javascript\nvar gulp = require('gulp');\nvar uglify = require('gulp-uglify');\nvar pump = require('pump');\nvar assetPath = '/srv/your.project.com/assets/js';\n\ngulp.task('compress', function (callback) {\n  pump([\n        gulp.src(assetPath+'/**/*.js'),\n        uglify(),\n        gulp.dest(assetPath)\n    ],\n    callback\n  );\n});\n```\n\n#### 5. Set Gulp Process into Deployer\n\n```\n'source' =\u003e '/srv/project',\n'commands' =\u003e [                                                    \n    'before' =\u003e [                                                  \n        'Minify inner JS' =\u003e [                                     \n            'command' =\u003e 'cd /srv/tools/minify-project; gulp compress',                                                 \n        ],                                                          \n    ],                                                             \n],  \n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyidas%2Fdeployer-php-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyidas%2Fdeployer-php-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyidas%2Fdeployer-php-cli/lists"}