Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alias not working #36

Open
celorodovalho opened this issue Dec 15, 2017 · 1 comment
Open

Alias not working #36

celorodovalho opened this issue Dec 15, 2017 · 1 comment

Comments

@celorodovalho
Copy link

I have a hostgator shared account.
In my .bashrc i have:

alias php='/opt/php71/bin/php'
alias composer='/home/XXX/bin/composer.phar'

In webconsole, when I try to run:

php -v

I got:

Content-Type: application/json
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: x-requested-with, content-type

{"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"Parse error","data":null}}

or when I try to run:

composer -v

I got:

sh: composer: command not found
@celorodovalho
Copy link
Author

celorodovalho commented Dec 15, 2017

I must to do that in function "execute_command":

// Command execution
function execute_command($command) {
    $descriptors = array(
        0 => array('pipe', 'r'), // STDIN
        1 => array('pipe', 'w'), // STDOUT
        2 => array('pipe', 'w')  // STDERR
    );
	$preCommand = [
		'export HOME=/home/XXX'
	];
	$commands = [
		'php' => '/opt/php71/bin/php',
		'composer.phar' => '/opt/php71/bin/php /home/XXX/bin/composer.phar',
		'composer' => '/opt/php71/bin/php /home/XXX/bin/composer.phar',
	];
	foreach ($commands as $key => $cmd) {
		$command = preg_replace('/(^|\s)('.$key.')($|\s)/i', '$1'.$cmd.'$3', $command);
	}
	$preCommand = implode(' && ', $preCommand).' && ';

    $process = proc_open($preCommand.$command . ' 2>&1', $descriptors, $pipes);
    if (!is_resource($process)) die("Can't execute command.");

    // Nothing to push to STDIN
    fclose($pipes[0]);

    $output = stream_get_contents($pipes[1]);
    fclose($pipes[1]);

    $error = stream_get_contents($pipes[2]);
    fclose($pipes[2]);

    // All pipes must be closed before "proc_close"
    $code = proc_close($process);

    return $output;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant