我正在寻找如何设置主机用户并从 env 传递
这不起作用 - 需要字符串而不是函数
host('51.38.98.87')
->stage('production')
->user( function(){return getenv('PRODUCTION_USER'); )
->pass( function(){return getenv('PRODUCTION_PASS'); )
->port(22)
在 Symfony 4 中,我使用 env 并且不想在 ~/.ssh/config 中设置主机
更新1:
<?php
namespace Deployer;
use Symfony\Component\Dotenv\Dotenv;
require 'recipe/symfony.php';
require_once 'vendor/autoload.php';
$dotenv = new Dotenv();
$dotenv->load(__DIR__.'/.env');
然后
dep 部署生产
得到
dep deploy production
[Error] Class 'Symfony\Component\Dotenv\Dotenv' not found
#0 phar:///usr/local/bin/dep/src/Deployer.php(325): require()
#1 [internal function]: Deployer\Deployer::Deployer\{closure}()
#2 phar:///usr/local/bin/dep/src/Deployer.php(326): call_user_func(Object(Closure))
#3 phar:///usr/local/bin/dep/bin/dep(119): Deployer\Deployer::run('6.3.0',
更新 2
composer.json 有 symfony/dotenv
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.0",
"symfony/browser-kit": "^4.0",
"symfony/css-selector": "^4.0",
"symfony/debug-pack": "*",
"symfony/dotenv": "^4.0",
"symfony/maker-bundle": "^1.0",
"symfony/phpunit-bridge": "^4.0",
"symfony/profiler-pack": "*",
"symfony/web-server-bundle": "^4.0"
},
但仍然
namespace Deployer;
use Symfony\Component\Dotenv\Dotenv;
require 'vendor/autoload.php';
require 'recipe/symfony.php';
$dotenv = new Dotenv();
$dotenv->load(__DIR__.'/.env');
给我
Class 'Symfony\Component\Dotenv\Dotenv' not found
#0 phar:///usr/local/bin/dep/src/Deployer.php(325): require()
#1 [internal function]: Deployer\Deployer::Deployer\{closure}()
#2 phar:///usr/local/bin/dep/src/Deployer.php(326): call_user_func(Object(Closure))
#3 phar:///usr/local/bin/dep/bin/dep(119): Deployer\Deployer::run('6.3.0', '/home/grek/Phps...')
#4 /usr/local/bin/dep(4): require('phar:///usr/loc...')
#5 {main}
更新 3
我创建测试文件:./test.php
<?php
use Symfony\Component\Dotenv\Dotenv;
require 'vendor/autoload.php';
(new Dotenv())->load(__DIR__.'/.env');
php test.php 工作正常。
从同一位置运行 dep deploy:staging
给我
[Error] Class 'Symfony\Component\Dotenv\Dotenv' not found
#0 phar:///usr/local/bin/dep/src/Deployer.php(325): require()
我的 deploy.php 文件
<?php
namespace Deployer;
use Symfony\Component\Dotenv\Dotenv;
require 'vendor/autoload.php';
require 'recipe/symfony.php';
(new Dotenv())->load(__DIR__.'/.env');
Deployer 全局安装
whereis dep
dep: /usr/local/bin/dep