依赖安装失败!将 laravel 应用程序部署到 heroku 时出错
Dependency installation failed! error while deploying laravel app to heroku
在尝试将 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 Postgres Hobby Dev 配置为 heroku 仪表板上的数据库,并在我的配置中设置了 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'),
],
我尝试使用谷歌搜索解决方案,但没有成功。请问我需要做什么来解决这个问题?
$url
是一个数组; parse_url
正在返回关联数组。配置中的 url
键应该是表示 URL 的字符串,而不是数组。您正在分配 'url' => $url,
,因此 'url'
是一个数组,而不是字符串。
如果你想使用 url
你只需要设置那个键,它会解析 URL 给你的其余信息。
"Some managed database providers such as Heroku provide a single database "URL" that contains all of the connection information for the database in a single string."
"For convenience, Laravel supports these URLs as an alternative to configuring your database with multiple configuration options. If the url
(or corresponding DATABASE_URL
environment variable) configuration option is present, it will be used to extract the database connection and credential information."
Laravel 5.8 Docs - Database - Configuration - Configuration Using URLs
在尝试将 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 Postgres Hobby Dev 配置为 heroku 仪表板上的数据库,并在我的配置中设置了 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'),
],
我尝试使用谷歌搜索解决方案,但没有成功。请问我需要做什么来解决这个问题?
$url
是一个数组; parse_url
正在返回关联数组。配置中的 url
键应该是表示 URL 的字符串,而不是数组。您正在分配 'url' => $url,
,因此 'url'
是一个数组,而不是字符串。
如果你想使用 url
你只需要设置那个键,它会解析 URL 给你的其余信息。
"Some managed database providers such as Heroku provide a single database "URL" that contains all of the connection information for the database in a single string."
"For convenience, Laravel supports these URLs as an alternative to configuring your database with multiple configuration options. If the
url
(or correspondingDATABASE_URL
environment variable) configuration option is present, it will be used to extract the database connection and credential information."
Laravel 5.8 Docs - Database - Configuration - Configuration Using URLs