依赖项安装失败! laravel应用程序部署到heroku时出错

时间:2019-11-23 07:11:43

标签: postgresql laravel-5 heroku heroku-postgres

在尝试将laravel应用程序部署到Heroku时,我开始使此依赖项安装失败!将我的DB_CONNECTION更改为Postgresql后出现错误。当我这样做

  

git push heroku master

..........
remote:          - Installing jakub-onderka/php-console-color (v0.2): Loading from cache
remote:          - Installing nikic/php-parser (v4.3.0): Downloading (100%)
remote:          - Installing jakub-onderka/php-console-highlighter (v0.4): Loading from cache
remote:          - Installing dnoegel/php-xdg-base-dir (0.1): Loading from cache
remote:          - Installing psy/psysh (v0.9.9): Loading from cache
remote:          - Installing laravel/tinker (v1.0.10): Loading from cache
remote:          - Installing guzzlehttp/guzzle (6.4.1): Downloading (100%)
remote:          - Installing unicodeveloper/laravel-paystack (1.0.2): Loading from cache
remote:        Package silex/silex is abandoned, you should avoid using it. Use symfony/flex instead.
remote:        Generating optimized autoload files
remote:        > Illuminate\Foundation\ComposerScripts::postAutoloadDump
remote:        > @php artisan package:discover --ansi
remote:
remote:        In ConfigurationUrlParser.php line 132:
remote:
remote:          parse_url() expects parameter 1 to be string, array given
remote:
remote:
remote:        Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
remote:  !     WARNING: A post-autoload-dump script terminated with an error
remote:
remote:  !     ERROR: Dependency installation failed!
remote:  !
remote:  !     The 'composer install' process failed with an error. The cause
remote:  !     may be the download or installation of packages, or a pre- or
remote:  !     post-install hook (e.g. a 'post-install-cmd' item in 'scripts')
remote:  !     in your 'composer.json'.
remote:  !
remote:  !     Typical error cases are out-of-date or missing parts of code,
remote:  !     timeouts when making external connections, or memory limits.
remote:  !
remote:  !     Check the above error output closely to determine the cause of
remote:  !     the problem, ensure the code you're pushing is functioning
remote:  !     properly, and that all local changes are committed correctly.
remote:  !
remote:  !     For more information on builds for PHP on Heroku, refer to
remote:  !     https://devcenter.heroku.com/articles/php-support
remote:  !
remote:  !     REMINDER: the following warnings were emitted during the build;
remote:  !     check the details above, as they may be related to this error:
remote:  !     - A post-autoload-dump script terminated with an error
remote:
remote:  !     Push rejected, failed to compile PHP app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to blemademo.
remote:
To https://git.heroku.com/blemademo.git
 ! [remote rejected]   master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/blemademo.git'

我已在Heroku仪表板上将Heroku Postgres Hobby Dev设置为数据库,并在我的配置中设置了DATABASE_URL。 在我的laravel database.php文件中,我将此文件放在文件顶部;

$host = env('DB_HOST', '127.0.0.1');
$database = env('DB_DATABASE', '');
$username = env('DB_USERNAME', 'forge');
$password = env('DB_PASSWORD', 'forge');

if($databaseUrl = getenv('DATABASE_URL')) {
    $url = parse_url($databaseUrl);

    $host = $url['host'];
    $username = $url['user'];
    $password = $url['pass'];
    $database = ltrim($url['path'], '/');
}

我的默认数据库连接设置为:

'default' => 'pgsql'

然后在我的连接数组中:

'pgsql' => [
    'driver' => 'pgsql',
    'url' => $url,
    'host' => $host,
    'database' => $database,
    'username' => $username,
    'password' => $password,
    'charset' => 'utf8',
    'prefix' => '',
    'prefix_indexes' => true,
    'schema' => 'public',
    'sslmode' => 'prefer',
    'port' => env('DB_PORT', '5432'),
],

我尝试使用谷歌搜索解决方案,但没有运气。我需要做什么来解决这个问题?

1 个答案:

答案 0 :(得分:1)

$url是一个数组; parse_url返回一个关联数组。配置中的url键应为代表URL的字符串,而不是数组。您正在分配'url' => $url,,所以'url'是一个数组,而不是字符串。

如果您想使用url,则只需设置该密钥,它将解析该URL中为您提供的其余信息。

  

“某些托管数据库提供程序(例如Heroku)提供单个数据库“ URL”,该URL以单个字符串包含数据库的所有连接信息。”

     

“为方便起见,Laravel支持使用这些URL作为使用多个配置选项配置数据库的替代方法。如果存在url(或相应的DATABASE_URL环境变量)配置选项,将使用它提取数据库连接和凭据信息。”

Laravel 5.8 Docs - Database - Configuration - Configuration Using URLs