yii2sshconsole Provides a console controller which is able to execute console commands.

  1. Requirements
  2. Usage
  3. Example
  4. Links

Requirements

  • Yii2 of course
  • PHP >= 5.4

Usage

Example

<?php namespace app\commands;

	use \yii2sshconsole\Controller;

	class DeployController extends Controller
	{
		public $defaultAction = 'exec';

		public function actionExec()
		{
			$this->auth('example.com', [
				'username' => 'myusername',
				'password' => 'mypassword', // optional
			]);

			// Or via private key
			/*
			$this->auth('example.com', [
				'username' => 'myusername',
				'key' => '/path/to/private.key',
				'password' => 'mykeypassword', // optional
			]);
			*/

			$output = $this->run('echo "test"');
			echo 'Output: ' . $output; // Output: test

			$output = $this->run([
				'cd /path/to/install',
				'./put_offline.sh',
				'git pull -f',
				'composer install',
				'./yii migrate --interactive=0',
				'./build.sh',
				'./yii cache/flush',
				'./put_online.sh',
			]);

			// Or via callback
			$this->run([
				'cd /path/to/install',
				'./put_offline.sh',
				'git pull -f',
				'composer install',
				'./yii migrate --interactive=0',
				'./build.sh',
				'./yii cache/flush',
				'./put_online.sh',
			], function($line) {
				echo $line;
			});
		}
	}

And then in the local console:

./yii deploy

Links

2 0
3 followers
0 downloads
Yii Version: 2.0
License: MIT
Category: Console
Developed by: thelfensdrfer
Created on: Apr 25, 2014
Last updated: 4 years ago

Related Extensions