有没有办法在我们的生产/测试环境中运行composer update命令?

问题是我没有命令行访问权限。

最佳答案

是的。有一个解决方案。但这可能需要一些服务器配置...
由于安全隐患,其中一些默认情况下被禁止!!

下载composer.phar https://getcomposer.org/download/
-这是PHP存档,可以通过Phar()提取并作为常规库执行。

创建新的php文件并将其放置到Web公用文件夹中。即/public/composer.php
或在https://github.com/whipsterCZ/laravel-libraries/blob/master/public/composer.php下载

配置

<?php

//TODO! Some Authorization - Whitelisted IP, Security tokens...


echo '<pre>
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/  UPDATE
                    /_/

';
define('ROOT_DIR',realpath('../'));
define('EXTRACT_DIRECTORY', ROOT_DIR. '/composer');
define('HOME_DIRECTORY', ROOT_DIR. '/composer/home');
define('COMPOSER_INITED', file_exists(ROOT_DIR.'/vendor'));

set_time_limit(100);
ini_set('memory_limit',-1);

if (!getenv('HOME') && !getenv('COMPOSER_HOME')) {
    putenv("COMPOSER_HOME=".HOME_DIRECTORY);
}

提取 Composer 库
if (file_exists(EXTRACT_DIRECTORY.'/vendor/autoload.php') == true) {
    echo "Extracted autoload already exists. Skipping phar extraction as presumably it's already extracted.\n";
}
else{
    $composerPhar = new Phar("../composer.phar");
    //php.ini set phar.readonly=0
    $composerPhar->extractTo(EXTRACT_DIRECTORY);
}

运行Composer命令
// change directory to root
chdir(ROOT_DIR);

//This requires the phar to have been extracted successfully.
require_once (EXTRACT_DIRECTORY.'/vendor/autoload.php');

//Use the Composer classes
use Composer\Console\Application;
use Composer\Command\UpdateCommand;
use Symfony\Component\Console\Input\ArrayInput;


//Create the commands
$args = array('command' => 'update');
if(!COMPOSER_INITED) {
    echo "This is first composer run: --no-scripts option is applies\n";
    $args['--no-scripts']=true; }
}
$input = new ArrayInput($args);

//Create the application and run it with the commands
$application = new Application();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
try {
    //Running commdand php.ini allow_url_fopen=1 && proc_open() function available
    $application->run($input);
    echo 'Success';
} catch (\Exception $e) {
    echo 'Error: '.$e->getMessage()."\n";
}

但是根据composer.lock的说法, Better将执行 composer install,这是从本地环境测试的最后一个依赖项配置

唯一的改变是
$args = array('command' => 'install');

关于php - 如何在PHP服务器上运行composer更新?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38396046/

10-16 00:37