Report this

What is the reason for this report?

App platform composer install not able to connect to database

Posted on August 31, 2023
Quenoz Alvareoe

By Quenoz Alvareoe

Software Engineer

I have set up digitalocean database and added the app as trusted source but the database connection fails over the composer installation process. Below are the errors.

2023-08-31T12:28:49.440674571Z │          - Installing spatie/laravel-permission (5.11.0): Extracting archive
2023-08-31T12:28:49.440996235Z │          - Installing backpack/permissionmanager (7.0.1): Extracting archive
2023-08-31T12:28:49.441707872Z │          - Installing backpack/pro (2.0.11): Extracting archive
2023-08-31T12:28:49.441857947Z │          - Installing backpack/theme-tabler (1.0.12): Extracting archive
2023-08-31T12:28:49.441866784Z │          - Installing laravel/sanctum (v3.2.6): Extracting archive
2023-08-31T12:28:49.442922204Z │          - Installing nikic/php-parser (v4.17.1): Extracting archive
2023-08-31T12:28:49.443072538Z │          - Installing psy/psysh (v0.11.20): Extracting archive
2023-08-31T12:28:49.443083506Z │          - Installing laravel/tinker (v2.8.2): Extracting archive
2023-08-31T12:28:49.443739356Z │          - Installing league/oauth1-client (v1.10.1): Extracting archive
2023-08-31T12:28:49.443887417Z │          - Installing laravel/socialite (v5.6.1): Extracting archive
2023-08-31T12:28:49.444189417Z │          - Installing webfuelagency/socialite (v1.0.0): Extracting archive
2023-08-31T12:28:50.211339029Z │        Generating optimized autoload files
2023-08-31T12:28:51.092950964Z │        > Illuminate\Foundation\ComposerScripts::postAutoloadDump
2023-08-31T12:28:51.112618305Z │        > @php artisan package:discover --ansi
2023-08-31T12:30:51.671975471Z │
2023-08-31T12:30:51.685054869Z │        In Connection.php line 801:
2023-08-31T12:30:51.685072692Z │
2023-08-31T12:30:51.685075407Z │          SQLSTATE[HY000] [2002] Connection timed out (Connection: mysql, SQL: select
2023-08-31T12:30:51.685077778Z │           column_name as `column_name` from information_schema.columns where table_s
2023-08-31T12:30:51.686646615Z │          chema = racer and table_name = users)
2023-08-31T12:30:51.686650405Z │
2023-08-31T12:30:51.686653013Z │
2023-08-31T12:30:51.688565005Z │        In Connector.php line 65:
2023-08-31T12:30:51.688570318Z │
2023-08-31T12:30:51.688572730Z │          SQLSTATE[HY000] [2002] Connection timed out
2023-08-31T12:30:51.688575121Z │
2023-08-31T12:30:51.688577991Z │
2023-08-31T12:30:51.694274106Z │        Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
2023-08-31T12:30:51.740116109Z │  !     WARNING: An error occurred during a database connection or query
2023-08-31T12:30:51.740606806Z │ 
2023-08-31T12:30:51.743565792Z │  !     ERROR: Dependency installation failed!
2023-08-31T12:30:51.743584506Z │  !
2023-08-31T12:30:51.743589033Z │  !     The 'composer install' process failed with an error. The cause
2023-08-31T12:30:51.743592710Z │  !     may be the download or installation of packages, or a pre- or
2023-08-31T12:30:51.743596676Z │  !     post-install hook (e.g. a 'post-install-cmd' item in 'scripts')
2023-08-31T12:30:51.743600321Z │  !     in your 'composer.json'.
2023-08-31T12:30:51.743603582Z │  !
2023-08-31T12:30:51.743606904Z │  !     Typical error cases are out-of-date or missing parts of code,
2023-08-31T12:30:51.743610463Z │  !     timeouts when making external connections, or memory limits.
2023-08-31T12:30:51.743626470Z │  !
2023-08-31T12:30:51.743629959Z │  !     Check the above error output closely to determine the cause of
2023-08-31T12:30:51.743633303Z │  !     the problem, ensure the code you're pushing is functioning
2023-08-31T12:30:51.743636503Z │  !     properly, and that all local changes are committed correctly.
2023-08-31T12:30:51.743639566Z │  !
2023-08-31T12:30:51.743642861Z │  !     For more information on builds for PHP on Heroku, refer to
2023-08-31T12:30:51.743645886Z │  !     https://devcenter.heroku.com/articles/php-support
2023-08-31T12:30:51.746419873Z │  !
2023-08-31T12:30:51.749945421Z │  !     REMINDER: the following warnings were emitted during the build;
2023-08-31T12:30:51.753633670Z │  !     check the details above, as they may be related to this error:
2023-08-31T12:30:51.756724906Z │  !     - Your app's PHP version is close to end of maintenance
2023-08-31T12:30:51.756739316Z │  !     - An error occurred during a database connection or query
2023-08-31T12:30:51.757494004Z │ 
2023-08-31T12:30:51.758311052Z │ ERROR: failed to build: exit status 1

this is my composer json

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The skeleton application for the Laravel framework.",
    "keywords": ["laravel", "framework"],
    "license": "MIT",
    "require": {
        "php": "8.1.18",
        "ext-bcmath": "*",
        "ext-ctype": "*",
        "ext-curl": "*",
        "ext-exif": "*",
        "ext-fileinfo": "*",
        "ext-gd": "*",
        "ext-json": "*",
        "ext-mbstring": "*",
        "ext-openssl": "*",
        "ext-pdo": "*",
        "ext-tokenizer": "*",
        "ext-xml": "*",
        "backpack/crud": "^6.1",
        "backpack/devtools": "^2.0",
        "backpack/langfilemanager": "^5.0",
        "backpack/medialibrary-uploaders": "^1.0",
        "backpack/menucrud": "^4.0",
        "backpack/pagemanager": "^3.2",
        "backpack/permissionmanager": "^7.0",
        "backpack/pro": "^2.0",
        "backpack/theme-tabler": "^1.0",
        "guzzlehttp/guzzle": "^7.2",
        "laravel/framework": "^10.10",
        "laravel/sanctum": "^3.2",
        "laravel/tinker": "^2.8",
        "spatie/laravel-medialibrary": "^10.11",
        "webfuelagency/socialite": "^1.0"
    },

and my app spec

alerts:
- rule: DEPLOYMENT_FAILED
- rule: DOMAIN_FAILED
databases:
- cluster_name: staging-db1
  db_name: racer
  db_user: doadmin
  engine: MYSQL
  name: staging-db1
  production: true
  size: professional-xs
  version: "8"
ingress:
  rules:
  - component:
      name: testapp
    match:
      path:
        prefix: /
name: racer
region: sgp
services:
- build_command: npm run build
  environment_slug: php
  envs:
  - key: DATABASE_URL
    scope: RUN_TIME
    value: ${staging-db1.DATABASE_URL}
  github:
    branch: staging
    deploy_on_push: true
    repo: wfftt/testapp
  http_port: 8080
  instance_count: 2
  instance_size_slug: professional-xs
  name: racer
  run_command: heroku-php-apache2 public/ && composer install --ignore-platform-reqs
    && php artisan migrate:fresh
  source_dir: /

I tested the database and the app running on my local were able to connect by adding my ip to the trusted source. Any idea?

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.