How to run composer update on PHP server?(如何在 PHP 服务器上运行作曲家更新?)
问题描述
有没有办法在我们的生产/测试环境中运行 composer update 命令?
Is there a way to run composer update command on our production/test environment?
问题是我无法访问命令行.
Problem is that i don't have access for Command Line.
推荐答案
是的.有一个解决方案.但它可能需要一些服务器配置......由于安全风险,其中一些默认情况下是禁止的!
Yes. there is a solution. but it could demands some server configuration... and some of these are forbidden by default due to security risks!!
下载 composer.phar https://getcomposer.org/download/- 这是 PHP 存档,可以通过 Phar() 提取并作为常规库执行.
download composer.phar https://getcomposer.org/download/
- this is PHP Archive which can be extracted via Phar() and executed as regular library.
创建新的 php 文件并将其放入 web 公用文件夹.即 /public/composer.php
create new php file and place it to web public folder. i.e. /public/composer.php
或在 https://github.com/下载WhiststerCZ/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);
}
提取作曲家库
if (file_exists(EXTRACT_DIRECTORY.'/vendor/autoload.php') == true) {
echo "Extracted autoload already exists. Skipping phar extraction as presumably it's already extracted.
";
}
else{
$composerPhar = new Phar("../composer.phar");
//php.ini set phar.readonly=0
$composerPhar->extractTo(EXTRACT_DIRECTORY);
}
运行 Composer 命令
running Composer Command
// 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 ComposerConsoleApplication;
use ComposerCommandUpdateCommand;
use SymfonyComponentConsoleInputArrayInput;
//Create the commands
$args = array('command' => 'update');
if(!COMPOSER_INITED) {
echo "This is first composer run: --no-scripts option is applies
";
$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()."
";
}
但是性能会更好 composer install,根据composer.lock,这是从本地环境测试的最后一个依赖配置
But Better will be performing composer install, according to composer.lock which is last dependency configuration tested from local environment
唯一的变化是
$args = array('command' => 'install');
这篇关于如何在 PHP 服务器上运行作曲家更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 PHP 服务器上运行作曲家更新?
基础教程推荐
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何替换eregi() 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
