问题描述
想知道是否可以通过一个PHP包装器从浏览器中执行 composer
,因为我没有访问服务器的shell访问权限。
是的,您可以运行Composer与一个小的PHP包装。所有Composer源代码都可以在Phar文件中使用,所以它可以被提取,然后你可以设置一个InputInterface来替换Composer,期望命令通过命令行传递。
如果您按如下所示设置目录结构:
./ project
。 /project/composer.json
./project/composer.lock
./project/webroot/composerExtractor.php
./project/var/
将下面的代码放入composerExtractor.php,然后从Web浏览器运行它,Composer应该将所有的库下载到:
./ project / vendors /
$ b b
以及在该目录中生成类加载器文件。
composerExtractor.php
<?php
define('EXTRACT_DIRECTORY',../var/extractedComposer);
if(file_exists(EXTRACT_DIRECTORY。'/ vendor / autoload.php')== true){
echo提取的自动加载已存在。跳过phar提取可能已经提取。
}
else {
$ composerPhar = new Phar(Composer.phar);
//php.ini设置phar.readonly必须设置为0
$ composerPhar-> extractTo(EXTRACT_DIRECTORY);
}
//这需要phar已成功提取。
require_once(EXTRACT_DIRECTORY。'/ vendor / autoload.php');
//使用Composer类
使用Composer \Console\Application;
使用Composer\Command\UpdateCommand;
使用Symfony \Component\Console\Input\ArrayInput;
//更改webroot,以便不在
中创建供应商文件//一个intahwebz可见的地方
chdir('../' );
//创建命令
$ input = new ArrayInput(array('command'=>'update'));
//创建应用程序并使用命令
$ application = new Application()运行它。
$ application-> run($ input);
?>
虽然这是可能的,但这不是一个好主意,但如果你不能使用
我强烈建议您至少为自己或您的办公室获取一个静态IP地址,然后将访问权限限制为您自己的IP,如以及可能删除此脚本在服务器上运行后,以防止意外再次运行。
Wondering if it's possible to execute composer
from the browser with a little PHP wrapper as I don't have access to shell access to the server.
Not sure if you can do this with cURL?
Yes you can run Composer with a little PHP wrapper. All of the Composer source code is available in the Phar file, so it can be extracted and then you can run it after setting up an InputInterface to replace Composer expecting the commands to be passed in via the command line.
If you setup your directory structure like this:
./project
./project/composer.json
./project/composer.lock
./project/webroot/composerExtractor.php
./project/var/
Put the code below into composerExtractor.php and then run it from a web-browser, Composer should download all the libraries into:
./project/vendors/
As well as generating the class-loader files in that directory as well.
composerExtractor.php
<?php
define('EXTRACT_DIRECTORY', "../var/extractedComposer");
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 setting phar.readonly must be set to 0
$composerPhar->extractTo(EXTRACT_DIRECTORY);
}
//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;
// change out of the webroot so that the vendors file is not created in
// a place that will be visible to the intahwebz
chdir('../');
//Create the commands
$input = new ArrayInput(array('command' => 'update'));
//Create the application and run it with the commands
$application = new Application();
$application->run($input);
?>
Although this is possible, it's not a fantastic idea but may be necessary if you can't use a host that gives you ssh access.
I'd strongly recommend at least getting a static IP address for yourself or your office and then restricting access to just your own IP, as well as probably deleting this script after it's run on the server to prevent it being accidentally run again.
这篇关于在浏览器中使用PHP脚本运行composer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!