Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installer options are not properly loaded as env vars #1499

Closed
HeapUnderfl0w opened this issue Aug 8, 2022 · 5 comments · Fixed by #1500
Closed

Installer options are not properly loaded as env vars #1499

HeapUnderfl0w opened this issue Aug 8, 2022 · 5 comments · Fixed by #1500
Labels
Milestone

Comments

@HeapUnderfl0w
Copy link

HeapUnderfl0w commented Aug 8, 2022

How Shlink is set-up

  • Shlink Version: 3.2.0
  • PHP Version: 8.1.8
  • How do you serve Shlink: Self-hosted nginx
  • Database engine used: PostgreSQL

Summary

When installing and/or upgrading shlink it defaults to a sqlite database in $SHLINK_ROOT/data/database.sqlite
instead of the configured postgres database.

Even reinstalling from scratch exhibits the same behavior.

The config generated by the installer:

<?php
return array(
    'DB_DRIVER' => 'postgres',
    'DB_NAME' => 'shlink',
    'DB_HOST' => '/var/run/postgresql/.s.PGSQL.5432',
    'DB_PORT' => '5432',
    'DB_USER' => 'shlink',
    'DB_PASSWORD' => 'WrJxnuWlGsUrnB7R3mc[...shortened]',
    'DEFAULT_DOMAIN' => 's.heap.wtf',
    'IS_HTTPS_ENABLED' => true,
    'DEFAULT_SHORT_CODES_LENGTH' => 5,
    'AUTO_RESOLVE_TITLES' => true,
    'REDIRECT_APPEND_EXTRA_PATH' => false,
    'MULTI_SEGMENT_SLUGS_ENABLED' => false,
    'GEOLITE_LICENSE_KEY' => '[redacted]',
    'REDIRECT_STATUS_CODE' => 302,
    'DISABLE_TRACKING' => false,
    'TRACK_ORPHAN_VISITS' => true,
    'DISABLE_TRACK_PARAM' => 'dnt',
    'DISABLE_TRACKING_FROM' => null,
    'DISABLE_IP_TRACKING' => false,
    'ANONYMIZE_REMOTE_ADDR' => true,
    'DISABLE_UA_TRACKING' => false,
    'DISABLE_REFERRER_TRACKING' => false,
    'DEFAULT_BASE_URL_REDIRECT' => 'https://heap.wtf',
    'DEFAULT_INVALID_SHORT_URL_REDIRECT' => 'https://heap.wtf',
    'DEFAULT_REGULAR_404_REDIRECT' => null,
    'DEFAULT_QR_CODE_SIZE' => 300,
    'DEFAULT_QR_CODE_MARGIN' => 1,
    'DEFAULT_QR_CODE_FORMAT' => 'png',
    'DEFAULT_QR_CODE_ERROR_CORRECTION' => 'm',
    'DEFAULT_QR_CODE_ROUND_BLOCK_SIZE' => true,
    'DELETE_SHORT_URL_THRESHOLD' => 50,
    'BASE_PATH' => '',
    'TIMEZONE' => 'CEST',
    'REDIS_SERVERS' => null,
);

Current behavior

Creating and initializing a database at $SHLINK_ROOT/data/database.sqlite.

Expected behavior

Initializing the database in the running postgres instance (/var/run/postgresql/.s.PGSQL.5432)

How to reproduce

  • Download the latest shlink package from the releases page (here, download shlink3.2.0_php8.1_dist.zip )
  • Run the installer via vendor/bin/shlink-installer install and fill in the values listed above
@HeapUnderfl0w
Copy link
Author

I have resolved this by clearing the database to 0 (ofc clearing all stored short links) and then rerunning the installer on a clean folder with a new shell.

From my observations this issue came from a polluted environment.

@HeapUnderfl0w
Copy link
Author

Ok i was mistaken. It is still not accessing the postgres database (and still creating the sqlite one)

@HeapUnderfl0w HeapUnderfl0w reopened this Aug 8, 2022
@acelaya
Copy link
Member

acelaya commented Aug 8, 2022

Yep, I have reproduced it. It's not just a problem with the database driver, but a regression introduced in Shlink 3.2 which is making it not load the configuration at all, so it uses default values for everything.

The fix is easy. I will publish v3.2.1 in a couple of hours, as this is a bug affecting everyone not using the docker image.

@acelaya acelaya changed the title Unable to install or upgrade using postgres as a backend store Installer options are not properly loaded as env vars Aug 8, 2022
@acelaya acelaya added this to Shlink Aug 8, 2022
@acelaya acelaya moved this to Todo 🗒️ in Shlink Aug 8, 2022
@acelaya acelaya added this to the 3.2.1 milestone Aug 8, 2022
@acelaya acelaya moved this from Todo 🗒️ to In Progress 📝 in Shlink Aug 8, 2022
@acelaya acelaya moved this from In Progress 📝 to In review 👀 in Shlink Aug 8, 2022
Repository owner moved this from In review 👀 to Done ✅ in Shlink Aug 8, 2022
@acelaya
Copy link
Member

acelaya commented Aug 8, 2022

I have just released v3.2.1, which includes the fix for this. You can skip v3.2.0 and update directly to v3.2.1

@HeapUnderfl0w
Copy link
Author

HeapUnderfl0w commented Aug 8, 2022

This worked like a charm.
It was even able to recover from my old 2.x instance (i had backed up the DB beforehand via pg_dump).

For anyone finding this and wondering how (assuming both your user and db are called shlink):

  • Backup your old shlink folder
    • In that folder already rename config/params/generated_config.php to something else
  • Backup your database using pg_dump -bcC shlink > shlink.sql
  • Recreate the postgres db in psql via DROP DATABASE shlink; and CREATE DATABASE shlink; ALTER DATABASE shlink OWNER TO shlink
  • Unpack the new shlink to your desired directory
  • Run the installer and answer all the questions
  • Copy the newly generated config/params/generated_config.php to your backup's config/params/
  • Restore the database with cat shlink.sql | psql -d shlink
  • Run vendor/bin/shlink-installer update
  • Answer yes and put your backed up shlink as the path

Now the upgrade should go through as normal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants