Skip to content

Instantly share code, notes, and snippets.

@edrush
Last active May 17, 2016 06:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edrush/9d9a43a7d072ea812e56927021f349e9 to your computer and use it in GitHub Desktop.
Save edrush/9d9a43a7d072ea812e56927021f349e9 to your computer and use it in GitHub Desktop.
Script that installs composer and runs composer install (e.g. if you don't have console access to your server).
<?php
error_reporting(E_ERROR);
ini_set('display_errors', 1);
define('SOURCE_DIR', '..');
define('HOME_DIR', '/');
define('COMPOSER_HOME_DIR', HOME_DIR . 'composer/');
// define if you need access to a private repository on github
// define('OAUTH_TOKEN', '1234');
chdir(SOURCE_DIR);
if (is_readable('composer.json')) {
$output = array();
putenv('COMPOSER_HOME=' . COMPOSER_HOME_DIR);
putenv('HOME=' . HOME_DIR);
if (!is_readable(HOME_DIR.'composer.phar')) {
chdir(HOME_DIR);
copy('https://getcomposer.org/installer', 'composer-setup.php');
if (hash_file('SHA384', 'composer-setup.php') === '92102166af5abdb03f49ce52a40591073a7b859a86e8ff13338cf7db58a19f7844fbc0bb79b2773bf30791e935dbd938') {
echo 'Installer verified. Things look pretty good. Just as Xima. After finishing - call this script again to install vendors...</br></br>';
// composer-setup.php will terminate request...
require_once 'composer-setup.php';
} else {
unlink('composer-setup.php');
exit ('Installer corrupt');
}
}
if (is_readable(HOME_DIR.'composer-setup.php')) {
unlink(HOME_DIR.'composer-setup.php');
}
if (defined('OAUTH_TOKEN')) {
exec('php_cli ' . HOME_DIR . 'composer.phar config -g github-oauth.github.com ' . OAUTH_TOKEN, $output);
}
putenv('COMPOSER_DISCARD_CHANGES=true');
$command = 'php_cli '.HOME_DIR.'composer.phar install';
$output[] = '<i>'.$command.'...</i>';
exec($command, $output);
$output[] = '';
$command = 'php_cli '.HOME_DIR.'composer.phar show';
$output[] = '<i>'.$command.'...</i>';
exec($command, $output);
echo implode('<br/>'.PHP_EOL, $output);
echo '<br/><br/>';
// remove oauth token for security reasons every time
if (defined('OAUTH_TOKEN')) {
unlink(COMPOSER_HOME_DIR . 'auth.json');
}
echo 'Done.';
} else {
echo 'No composer.json found.';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment